實驗 RFID + Node-Red +SQLite 建立資料庫 新增 刪除一筆 刪除全部資料 刪除資料庫
[{"id":"fc2bc05aaeb53a69","type":"ui_button","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","order":21,"width":"3","height":"1","passthru":false,"label":"建立資料庫","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"建立資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":90,"y":60,"wires":[["829a7127d56826ac","14eacaf6ab54d79d"]]},{"id":"4438df7c6a76e928","type":"ui_button","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","order":45,"width":"3","height":"1","passthru":false,"label":"檢視資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"檢視資料","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":260,"wires":[["494b685c1733dc8f","9e276d6d151de3a9"]]},{"id":"36c87a2c69aedce2","type":"ui_button","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","order":47,"width":"3","height":"1","passthru":false,"label":"刪除所有資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除所有資料","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":400,"wires":[["f6ae9a1ac227ccf2","9e276d6d151de3a9"]]},{"id":"8252e64dda450261","type":"sqlite","z":"7aebcf1d53039222","mydb":"dd7f8134e015a1cb","sqlquery":"msg.topic","sql":"","name":"My_RFID_database","x":540,"y":60,"wires":[["168b6d52dfb43542"]]},{"id":"829a7127d56826ac","type":"function","z":"7aebcf1d53039222","name":"CREATE DATABASE","func":"\n\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\nmsg.topic = \"CREATE TABLE RFIDtable(id INTEGER PRIMARY KEY AUTOINCREMENT, uidname TEXT, currentdate DATE, currenttime TIME)\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":60,"wires":[["8252e64dda450261"]]},{"id":"168b6d52dfb43542","type":"debug","z":"7aebcf1d53039222","name":"debug 97","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":60,"wires":[]},{"id":"c0527e21b1adaf97","type":"function","z":"7aebcf1d53039222","name":"INSERT","func":"var 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\nvar var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\n\nvar myRFID = msg.payload;\n\n\nmsg.topic = \"INSERT INTO RFIDtable ( uidname , currentdate, currenttime ) VALUES ($myRFID, $var_date , $var_time ) \" ;\nmsg.payload = [myRFID, var_date , var_time ]\nreturn msg;\n\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":100,"wires":[["4717378946fa2f42","8252e64dda450261"]]},{"id":"f6ae9a1ac227ccf2","type":"function","z":"7aebcf1d53039222","name":"刪除所有資料","func":"//DELETE from RFIDtable\nmsg.topic = \"DELETE from RFIDtable\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":400,"wires":[["b8a824f5153c6fd8"]]},{"id":"b8a824f5153c6fd8","type":"sqlite","z":"7aebcf1d53039222","mydb":"dd7f8134e015a1cb","sqlquery":"msg.topic","sql":"","name":"My_RFID_database","x":560,"y":380,"wires":[["9339112b5f11b666"]]},{"id":"22d6aa6b9b59b1ef","type":"ui_button","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","order":47,"width":"3","height":"1","passthru":false,"label":"刪除資料庫","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":90,"y":440,"wires":[["a19483da5e58cbf4","9e276d6d151de3a9"]]},{"id":"a19483da5e58cbf4","type":"function","z":"7aebcf1d53039222","name":"刪除資料庫","func":"//DROP TABLE RFIDtable\nmsg.topic = \"DROP TABLE RFIDtable\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":440,"wires":[["b8a824f5153c6fd8"]]},{"id":"47110d4be5ce7045","type":"ui_template","z":"7aebcf1d53039222","group":"fe68da70e8d7a3c8","name":"","order":0,"width":"12","height":"10","format":"<table style=\"width:100%\">\n <tr>\n <th>idex</th> \n <th>database_id</th>\n <th>UID </th>\n <th>Date</th>\n <th>Times</th>\n </tr>\n \n <tr ng-repeat=\"x in msg.payload | limitTo:50\">\n <td>{{$index}}</td>\n <td>{{msg.payload[$index].id}}</td>\n <td>{{msg.payload[$index].uidname}}</td>\n <td>{{msg.payload[$index].currentdate}}</td>\n <td>{{msg.payload[$index].currenttime}}</td>\n </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":760,"y":220,"wires":[[]]},{"id":"9339112b5f11b666","type":"debug","z":"7aebcf1d53039222","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":380,"wires":[]},{"id":"494b685c1733dc8f","type":"function","z":"7aebcf1d53039222","name":"檢視資料","func":"\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\n\n//SELECT * FROM RFIDtable ORDER BY id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM RFIDtable ORDER BY id DESC LIMIT 50\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":220,"wires":[["313ed708cbe77e86"]]},{"id":"313ed708cbe77e86","type":"sqlite","z":"7aebcf1d53039222","mydb":"dd7f8134e015a1cb","sqlquery":"msg.topic","sql":"","name":"My_RFID_database","x":540,"y":220,"wires":[["47110d4be5ce7045","1a261bc18a1f5965"]]},{"id":"95fbcdf86ed8fbcb","type":"function","z":"7aebcf1d53039222","name":"SELECT ALL","func":"var del_idtemp=msg.payload;\nflow.set(\"idtemp\", del_idtemp);\n\nmsg.topic = \"SELECT * FROM RFIDtable \";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":360,"wires":[["b8a824f5153c6fd8","f9cbb712b6ee61a0"]]},{"id":"a1677f0f8fd20351","type":"function","z":"7aebcf1d53039222","name":"確認 刪除","func":"var del_id = flow.get(\"idtemp\");\n\n\nmsg.topic = \"DELETE FROM RFIDtable WHERE id= ($del_id) \" ;\nmsg.payload = [del_id]\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":300,"wires":[["a696ffa0a72fbd77"]]},{"id":"6395bc41a36b7b4f","type":"ui_numeric","z":"7aebcf1d53039222","name":"","label":"刪除的database_id","tooltip":"","group":"fe68da70e8d7a3c8","order":30,"width":"4","height":"1","wrap":false,"passthru":true,"topic":"topic","topicType":"msg","format":"{{value}}","min":"1","max":"100","step":1,"className":"","x":110,"y":360,"wires":[["95fbcdf86ed8fbcb","9e276d6d151de3a9"]]},{"id":"a696ffa0a72fbd77","type":"sqlite","z":"7aebcf1d53039222","mydb":"dd7f8134e015a1cb","sqlquery":"msg.topic","sql":"DELETE FROM dhtreadings WHERE id = VALUES ($theid)","name":"My_RFID_database","x":480,"y":300,"wires":[["1a261bc18a1f5965"]]},{"id":"1a261bc18a1f5965","type":"debug","z":"7aebcf1d53039222","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":300,"wires":[]},{"id":"dd7e69860ea9730d","type":"ui_button","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","order":44,"width":"3","height":"1","passthru":false,"label":"刪除一筆資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除一筆資料","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":300,"wires":[["a1677f0f8fd20351","9e276d6d151de3a9"]]},{"id":"f9cbb712b6ee61a0","type":"debug","z":"7aebcf1d53039222","name":"debug 98","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":340,"wires":[]},{"id":"caa123a28d1ba978","type":"mqtt in","z":"7aebcf1d53039222","name":"新增 RFID","topic":"alex9ufo/esp32/RFID","qos":"2","datatype":"auto-detect","broker":"841df58d.ee5e98","nl":false,"rap":true,"rh":0,"inputs":0,"x":80,"y":140,"wires":[["c0527e21b1adaf97","2dddad4e20242887","b59d1f7d9c7476ae"]]},{"id":"4717378946fa2f42","type":"debug","z":"7aebcf1d53039222","name":"debug 100","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":100,"wires":[]},{"id":"2dddad4e20242887","type":"ui_text_input","z":"7aebcf1d53039222","name":"","label":"新增一筆資料","tooltip":"","group":"fe68da70e8d7a3c8","order":7,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"topic","sendOnBlur":true,"className":"","topicType":"msg","x":320,"y":140,"wires":[[]]},{"id":"db8cbbfbf7372391","type":"ui_audio","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":440,"y":180,"wires":[]},{"id":"b59d1f7d9c7476ae","type":"function","z":"7aebcf1d53039222","name":"function ","func":"var temp= msg.payload;\nmsg.payload= \"新增一筆資料\" + temp;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":180,"wires":[["db8cbbfbf7372391"]]},{"id":"9e276d6d151de3a9","type":"ui_audio","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":300,"y":260,"wires":[]},{"id":"14eacaf6ab54d79d","type":"ui_audio","z":"7aebcf1d53039222","name":"","group":"fe68da70e8d7a3c8","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":260,"y":20,"wires":[]},{"id":"fe68da70e8d7a3c8","type":"ui_group","name":"2023 RFID","tab":"eeb8e179.a47a4","order":3,"disp":true,"width":"10","collapse":false,"className":""},{"id":"dd7f8134e015a1cb","type":"sqlitedb","db":"C:\\Users\\User\\.node-red\\my_2023rfid.db","mode":"RWC"},{"id":"841df58d.ee5e98","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"eeb8e179.a47a4","type":"ui_tab","name":"RFID Database","icon":"dashboard","disabled":false,"hidden":false}]
沒有留言:
張貼留言