2021年11月11日 星期四

Node-Red & Sqlite

Node-Red &  Sqlite 



源自於 https://funprojects.blog/2019/12/26/sqlite-and-node-red/

[{"id":"ada4db46f6f6a7bc","type":"inject","z":"02f6189fd1732594","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":40,"wires":[["af5d47440e496fa7"]]},{"id":"af5d47440e496fa7","type":"sqlite","z":"02f6189fd1732594","mydb":"d14459453c376dc8","sqlquery":"fixed","sql":"create table temps (thetime Timestamp , thetemp integet);","name":"Create DataBase Table","x":430,"y":40,"wires":[["68317db6cf5df82a"]]},{"id":"68317db6cf5df82a","type":"debug","z":"02f6189fd1732594","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":40,"wires":[]},{"id":"bdb9ef4bbc482528","type":"sqlite","z":"02f6189fd1732594","mydb":"d14459453c376dc8","sqlquery":"fixed","sql":"select * from temps;","name":"select * from temps;","x":380,"y":100,"wires":[["d027fe4d780208d3"]]},{"id":"d027fe4d780208d3","type":"debug","z":"02f6189fd1732594","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":100,"wires":[]},{"id":"e4f045af896b4ef7","type":"inject","z":"02f6189fd1732594","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["bdb9ef4bbc482528"]]},{"id":"602f17fc686fd904","type":"sqlite","z":"02f6189fd1732594","mydb":"d14459453c376dc8","sqlquery":"prepared","sql":"insert into temps (thetime , thetemp) values ($thetime ,$thevalue)","name":"insert into sqlite","x":600,"y":180,"wires":[["4484db5a40a5906b"]]},{"id":"4484db5a40a5906b","type":"debug","z":"02f6189fd1732594","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":180,"wires":[]},{"id":"5f07d298848394d2","type":"function","z":"02f6189fd1732594","name":"","func":"// Create a Params variable\n// with a time and value component\n//\nmsg.params = { $thetime:Date.now(), $thevalue:msg.payload }\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":180,"wires":[["602f17fc686fd904"]]},{"id":"17c4a7e034dbfe1c","type":"random","z":"02f6189fd1732594","name":"","low":1,"high":10,"inte":"true","property":"payload","x":280,"y":180,"wires":[["5f07d298848394d2"]]},{"id":"aa90861727ca970c","type":"inject","z":"02f6189fd1732594","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":180,"wires":[["17c4a7e034dbfe1c"]]},{"id":"a5478371ea733c9e","type":"inject","z":"02f6189fd1732594","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":240,"wires":[["21d0b7078ffb41a2"]]},{"id":"21d0b7078ffb41a2","type":"sqlite","z":"02f6189fd1732594","mydb":"d14459453c376dc8","sqlquery":"fixed","sql":"select * from temps LIMIT 8 OFFSET (SELECT COUNT(*) FROM temps)-8;","name":"select * from temps;","x":310,"y":240,"wires":[["13ef92bdfd8b347c"]]},{"id":"13ef92bdfd8b347c","type":"function","z":"02f6189fd1732594","name":"Format Chart Data","func":"//  \n // Create a data variable   \n //  \n var series = [\"temp DegC\"];  \n var labels = [\"Data Values\"];  \n var data = \"[[\";  \n   \n for (var i=0; i < msg.payload.length; i++) {  \n   data += '{ \"x\":' + msg.payload[i].thetime + ', \"y\":' + msg.payload[i].thetemp + '}';  \n   if (i < (msg.payload.length - 1)) {  \n     data += \",\"  \n   } else {  \n     data += \"]]\"  \n   }  \n }  \n var jsondata = JSON.parse(data);  \n msg.payload = [{\"series\": series, \"data\": jsondata, \"labels\": labels}];  \n   \n \nreturn msg;  \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":240,"wires":[["b63c977dd6ef16f7","fb4bfc24ac7fcb59"]]},{"id":"b63c977dd6ef16f7","type":"debug","z":"02f6189fd1732594","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":280,"wires":[]},{"id":"fb4bfc24ac7fcb59","type":"ui_chart","z":"02f6189fd1732594","name":"","group":"fc89dc38.347898","order":2,"width":0,"height":0,"label":"Sqlite chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":760,"y":240,"wires":[[]]},{"id":"d14459453c376dc8","type":"sqlitedb","db":"sqlte1","mode":"RWC"},{"id":"fc89dc38.347898","type":"ui_group","name":"Widget","tab":"2711d5a2.d68132","order":1,"disp":true,"width":"8","collapse":false},{"id":"2711d5a2.d68132","type":"ui_tab","name":"Sensor","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...