2020年11月30日 星期一

Node-Red SQLite 範例

 Node-Red  SQLite 範例

產生資料庫Create

CREATE TABLE RFID ( id INT PRIMARY KEY NOT NULL, current_time TEXT , uid_name TEXT)

插入資料庫的資料

msg.topic = "INSERT INTO RFID (id,current_time, uid_name) VALUES (?,?,?)";

var Today = new Date();

var yyyy = Today.getFullYear(); //年

var MM = Today.getMonth()+1;    //月

var dd = Today.getDate();       //日

var h = Today.getHours();       //時

var m = Today.getMinutes();     //分

var s = Today.getSeconds();     //秒

if(MM<10)

{

   MM = '0'+MM;

}

if(dd<10)

{

   dd = '0'+dd;

}

if(h<10)

{

   h = '0'+h;

}

if(m<10)

{

  m = '0' + m;

}

if(s<10)

{

  s = '0' + s;

}

var hms= yyyy + '/'+ MM + '/'+ dd + ' ' + h + ':' + m + ':' + s ;

var id= Date.now() ;

msg.payload = [id ,hms, msg.payload];

return msg;


檢視資料庫

SELECT * FROM RFID ORDER BY  id  DESC LIMIT 100;


顯示樣板

<table style="width:100%">

  <tr>

    <th>ID    </th> 

    <th>時 間 </th> 

    <th>卡 號 </th>

  </tr>

  <tr ng-repeat="x in msg.payload | limitTo:20">

    <td>{{$index}}</td>

    <td>{{msg.payload[$index].current_time}}</td>

    <td>{{msg.payload[$index].uid_name}}</td> 

  </tr>

</table>


檔案目錄 C:\Users\alex\AppData\Roaming\npm
SQLite檔案名稱 RFID2020_1130.db






// N0de-Red程式

[{"id":"1909ec67.e04a64","type":"debug","z":"18a9e5f7.6c481a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":120,"wires":[]},{"id":"e202150a.adf688","type":"sqlite","z":"18a9e5f7.6c481a","mydb":"e77b6c54.4f02","sqlquery":"msg.topic","sql":"","name":"SQLITE_Example","x":510,"y":120,"wires":[["1909ec67.e04a64"]]},{"id":"d853a446.d7ed78","type":"sqlite","z":"18a9e5f7.6c481a","mydb":"e77b6c54.4f02","sqlquery":"msg.topic","sql":"","name":"SQLITE_Example","x":450,"y":300,"wires":[["e8a8b129.c8ad6"]]},{"id":"697d90a6.eefc5","type":"ui_button","z":"18a9e5f7.6c481a","name":"","group":"b165cbf1.03d608","order":50,"width":"2","height":"2","passthru":false,"label":"新增 卡號1","tooltip":"","color":"","bgcolor":"","icon":"","payload":"Alex_test1","payloadType":"str","topic":"","x":150,"y":80,"wires":[["73137d5.4a9ce84"]]},{"id":"c36997b.25b3868","type":"ui_button","z":"18a9e5f7.6c481a","name":"","group":"b165cbf1.03d608","order":51,"width":"2","height":"2","passthru":false,"label":"新增 卡號2","tooltip":"","color":"","bgcolor":"blue","icon":"","payload":"RFIDAlex_test2","payloadType":"str","topic":"","x":150,"y":120,"wires":[["73137d5.4a9ce84"]]},{"id":"e12f3f08.e6d9a","type":"ui_button","z":"18a9e5f7.6c481a","name":"","group":"b165cbf1.03d608","order":8,"width":0,"height":0,"passthru":false,"label":"刪除所有的資料","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"DELETE from RFID","x":160,"y":180,"wires":[["e202150a.adf688"]]},{"id":"73137d5.4a9ce84","type":"function","z":"18a9e5f7.6c481a","name":"INSERT","func":"msg.topic = \"INSERT INTO RFID (id,current_time, uid_name) VALUES (?,?,?)\";\n\nvar Today = new Date();\nvar yyyy = Today.getFullYear(); //年\nvar MM = Today.getMonth()+1;    //月\nvar dd = Today.getDate();       //日\nvar h = Today.getHours();       //時\nvar m = Today.getMinutes();     //分\nvar s = Today.getSeconds();     //秒\n\nif(MM<10)\n{\n   MM = '0'+MM;\n}\n\nif(dd<10)\n{\n   dd = '0'+dd;\n}\n\nif(h<10)\n{\n   h = '0'+h;\n}\n\nif(m<10)\n{\n  m = '0' + m;\n}\n\nif(s<10)\n{\n  s = '0' + s;\n}\nvar hms= yyyy + '/'+ MM + '/'+ dd + ' ' + h + ':' + m + ':' + s ;\nvar id= Date.now() ;\nmsg.payload = [id ,hms, msg.payload];\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":100,"wires":[["e202150a.adf688","8f7e0ad3.3163f8"]]},{"id":"8f7e0ad3.3163f8","type":"ui_text","z":"18a9e5f7.6c481a","group":"b165cbf1.03d608","order":10,"width":0,"height":0,"name":"","label":"資料表","format":"{{msg.payload}}","layout":"row-left","x":470,"y":60,"wires":[]},{"id":"f30e2ef6.8fa1b","type":"ui_button","z":"18a9e5f7.6c481a","name":"","group":"b165cbf1.03d608","order":10,"width":"2","height":"2","passthru":false,"label":"檢視資料庫","tooltip":"","color":"","bgcolor":"orange","icon":"","payload":"","payloadType":"str","topic":"SELECT * FROM RFID ORDER BY  id  DESC LIMIT 100;","x":150,"y":300,"wires":[["d853a446.d7ed78"]]},{"id":"e8a8b129.c8ad6","type":"ui_template","z":"18a9e5f7.6c481a","group":"b165cbf1.03d608","name":"","order":0,"width":"12","height":"4","format":"<table style=\"width:100%\">\n  <tr>\n    <th>ID    </th> \n    <th>時 間 </th> \n    <th>卡 號 </th>\n  </tr>\n  <tr ng-repeat=\"x in msg.payload | limitTo:20\">\n    <td>{{$index}}</td>\n    <td>{{msg.payload[$index].current_time}}</td>\n    <td>{{msg.payload[$index].uid_name}}</td> \n  </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":640,"y":300,"wires":[[]]},{"id":"ab89d10b.421d4","type":"ui_button","z":"18a9e5f7.6c481a","name":"","group":"b165cbf1.03d608","order":11,"width":"6","height":"2","passthru":false,"label":"建立資料庫(只能執行一次)","tooltip":"","color":"orange","bgcolor":" purple","icon":"","payload":"","payloadType":"str","topic":"CREATE TABLE RFID ( id INT PRIMARY KEY NOT NULL, current_time TEXT , uid_name TEXT)","x":190,"y":240,"wires":[["e202150a.adf688"]]},{"id":"e77b6c54.4f02","type":"sqlitedb","z":"","db":"RFID2020_1130.db","mode":"RWC"},{"id":"b165cbf1.03d608","type":"ui_group","z":"","name":"Data","tab":"7a15eb23.c05f34","order":3,"disp":true,"width":"6","collapse":false},{"id":"7a15eb23.c05f34","type":"ui_tab","z":"","name":"SQlite_2020_0720","icon":"dashboard","disabled":false,"hidden":false}]

沒有留言:

張貼留言

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

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