2019年12月8日 星期日

Node-RED insert and select using binding

Database examples - insert and select using binding


A selection of database examples. How you can manipulate the message topic and payload in various ways to get or insert data into a database. Includes bind columns, getting data directly from an input, converting automatically, templates etc. Examples are in SQLite but can be in MySQL or Postgres. Database table = "CREATE TABLE test (id INTEGER, text VARCHAR);".




CREATE TABLE RFIDtable( id INT PRIMARY KEY NOT NULL, currenttime TEXT , uidname TEXT)


INSERT Function 
-----------------------------------------------------------
msg.topic = "INSERT INTO RFIDtable (id,currenttime, uidname) VALUES (?,?,?)";
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();

if(h<10)
{
    
  h = '0'+h;

}

if(m<10)
{
    
  m = '0' + m;

}

if(s<10)
{
    
  s = '0' + s;

}

var hms= h + ':' + m + ':' + s ;
var id= Date.now() ;
msg.payload = [id ,hms, msg.payload];
return msg;

-----------------------------------------------------------


View Data

SELECT * FROM RFIDtable ORDER BY  id  DESC LIMIT 100;

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...