缓慢完善中,一步一步记录学习 代码地址:https://github.com/klren0312/stm32_wifi 2017.3.19
目前用来解决,获取STM32发来的数据,将其保存到MYSQL中,方便后面实时显示和统计。
npm install mysql --save
DROP TABLE IF EXISTS `env`;
CREATE TABLE `env` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tem` int(11) DEFAULT NULL,
`hum` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
var mysql = require('mysql');
var conn = mysql.createConnection({
host:'localhost',
user:'root',
password:'root',
database:'nodemysql',
port:3306
});
conn.connect();
//查询
conn.query('SELECT * from env',function(err,rows,fields){
if (err) throw err;
});
//增加
var post = {tem:25,hum:50}
conn.query('INSERT INTO env SET ?', post ,function(error,result,fields){
if(error) throw error;
});
//更改
conn.query('UPDATE env SET tem=? , hum=? WHERE id = ?',[12,66,1], function(error,result,fields){
if(error) throw error;
});
//删除
conn.query('DELETE FROM env WHERE tem=?',[12],function(error,result,fields){
if (error) throw error;
console.log('delete '+ result.affectedRows + ' rows');
})
conn.end();
QQ截图20170320180002.png
@治电小白菜 20170319