2020年10月26日 星期一

Node-Red & SQLite 範例

 Node-Red & SQLite 範例

資料庫

RFID2020_10_25.db

(附檔名會自動附加上去)

資料表

RFID

 

欄位1

id

INTEGER  , PK (PRIMARY) , AI (AUTOINCREMENT)

欄位2

current_time

TEXT

欄位3

uid_name

TEXT




[{"id":"820ca44b.eaabd8","type":"debug","z":"8dfa153f.f89b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":200,"wires":[]},{"id":"b70f9595.254cf8","type":"sqlite","z":"8dfa153f.f89b18","mydb":"e77b6c54.4f02","sqlquery":"msg.topic","sql":"","name":"SQLITE_Example","x":470,"y":200,"wires":[["820ca44b.eaabd8"]]},{"id":"324b8b74.4bf404","type":"sqlite","z":"8dfa153f.f89b18","mydb":"e77b6c54.4f02","sqlquery":"msg.topic","sql":"","name":"SQLITE_Example","x":410,"y":340,"wires":[["d185ba67.098318"]]},{"id":"53d64c02.aa83f4","type":"ui_button","z":"8dfa153f.f89b18","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":110,"y":160,"wires":[["479ed186.266ca"]]},{"id":"bee60e96.b3f28","type":"ui_button","z":"8dfa153f.f89b18","name":"","group":"b165cbf1.03d608","order":51,"width":"2","height":"2","passthru":false,"label":"新增 卡號2","tooltip":"","color":"","bgcolor":"","icon":"","payload":"RFIDAlex_test2","payloadType":"str","topic":"","x":110,"y":200,"wires":[["479ed186.266ca"]]},{"id":"87990a3c.2d9078","type":"ui_button","z":"8dfa153f.f89b18","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":120,"y":280,"wires":[["b70f9595.254cf8"]]},{"id":"479ed186.266ca","type":"function","z":"8dfa153f.f89b18","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":280,"y":180,"wires":[["b70f9595.254cf8","810b9e8b.b9f11"]]},{"id":"810b9e8b.b9f11","type":"ui_text","z":"8dfa153f.f89b18","group":"b165cbf1.03d608","order":10,"width":0,"height":0,"name":"","label":"資料表","format":"{{msg.payload}}","layout":"row-left","x":430,"y":140,"wires":[]},{"id":"7e9dab15.ae60b4","type":"ui_button","z":"8dfa153f.f89b18","name":"","group":"b165cbf1.03d608","order":10,"width":"2","height":"2","passthru":false,"label":"檢視最新10筆資料","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"SELECT * FROM RFID ORDER BY  id  DESC LIMIT 10;","x":130,"y":340,"wires":[["324b8b74.4bf404"]]},{"id":"d185ba67.098318","type":"ui_template","z":"8dfa153f.f89b18","group":"b165cbf1.03d608","name":"","order":0,"width":"12","height":"4","format":"<table style=\"width:100%\">\n  <tr>\n    <th>Index</th> \n    <th>Date</th> \n    <th>RFID</th>\n  </tr>\n  <tr ng-repeat=\"x in msg.payload | limitTo:10\">\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":600,"y":340,"wires":[["759d0aa7.6b8d14"]]},{"id":"759d0aa7.6b8d14","type":"debug","z":"8dfa153f.f89b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":340,"wires":[]},{"id":"e77b6c54.4f02","type":"sqlitedb","z":"","db":"RFID2020_10_25.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}]

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

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