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;

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...