2024年3月26日 星期二

DHT11 (Node-Red) +PostgreSQL 模擬

 DHT11 (Node-Red) +PostgreSQL 模擬







[{"id":"acddd911a6412f0a","type":"inject","z":"08dc41d47d4d9e09","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"15","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":130,"y":140,"wires":[["60f82608b91e1010","a7941c012545db2a"]]},{"id":"60f82608b91e1010","type":"postgrestor","z":"08dc41d47d4d9e09","name":"DHT11","query":"SELECT * FROM DHT11sensor order by time desc limit 1;","postgresDB":"b98af31e5c23d7ac","output":true,"outputs":1,"throwErrors":false,"x":290,"y":140,"wires":[["2536c7ad0157dbf2","cd48a2caa41c4e6d","7c706fad4771614c"]]},{"id":"2536c7ad0157dbf2","type":"ui_gauge","z":"08dc41d47d4d9e09","name":"","group":"49ca43fc9b95bcc1","order":2,"width":"6","height":"4","gtype":"gage","title":"Temperature","label":"C","format":"{{payload.rows[0].temp}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":510,"y":140,"wires":[]},{"id":"cd48a2caa41c4e6d","type":"ui_gauge","z":"08dc41d47d4d9e09","name":"","group":"49ca43fc9b95bcc1","order":3,"width":"6","height":"4","gtype":"gage","title":"Humidity","label":"%","format":"{{payload.rows[0].humidity}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":500,"y":180,"wires":[]},{"id":"cd4adcf359d66588","type":"ui_text","z":"08dc41d47d4d9e09","group":"49ca43fc9b95bcc1","order":1,"width":0,"height":0,"name":"","label":"Update Time:   ","format":"{{msg.payload}}","layout":"row-left","className":"","x":730,"y":100,"wires":[]},{"id":"a7941c012545db2a","type":"postgrestor","z":"08dc41d47d4d9e09","name":"DHT11","query":"select TO_CHAR(time, 'YYYY-MM-DD HH:mm:ss') as time,temp,humidity from (SELECT * FROM DHT11sensor order by time desc limit 30) as data order by time;","postgresDB":"b98af31e5c23d7ac","output":true,"outputs":1,"throwErrors":false,"x":290,"y":220,"wires":[["de934747674f4abc","b6869634764c8604","15f7b694306c2f80"]]},{"id":"bc052292a6aa1f41","type":"ui_chart","z":"08dc41d47d4d9e09","name":"","group":"6879ef9ca30c1e34","order":0,"width":"13","height":"4","label":"Temperature","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":690,"y":220,"wires":[[]]},{"id":"de934747674f4abc","type":"function","z":"08dc41d47d4d9e09","name":"Format chart","func":"var data = [];\nvar label = [];\nvar i;\ndata.push([]);\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  data[0].push(msg.payload.rows[i]['temp']);\n}\n\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  label.push(msg.payload.rows[i]['time']);\n}\n\nvar m={\n    \"series\":[\"Temperature\"],\n    \"data\":data,\n    \"labels\":label\n};\n\nreturn {payload:[m]};\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":220,"wires":[["bc052292a6aa1f41"]]},{"id":"864f41576f8d37a8","type":"ui_chart","z":"08dc41d47d4d9e09","name":"","group":"6879ef9ca30c1e34","order":0,"width":"13","height":"4","label":"Humidity","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":680,"y":260,"wires":[[]]},{"id":"b6869634764c8604","type":"function","z":"08dc41d47d4d9e09","name":"Format chart","func":"var data = [];\nvar label = [];\nvar i;\ndata.push([]);\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  data[0].push(msg.payload.rows[i]['humidity']);\n}\n\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  label.push(msg.payload.rows[i]['time']);\n}\n\nvar m={\n    \"series\":[\"Humidity\"],\n    \"data\":data,\n    \"labels\":label\n};\n\nreturn {payload:[m]};\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":260,"wires":[["864f41576f8d37a8"]]},{"id":"15f7b694306c2f80","type":"function","z":"08dc41d47d4d9e09","name":"create array","func":"\nvar i;\nvar list_data = [];\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  list_data.push({\"No\":i+1,\"Time\":msg.payload.rows[i]['time'],\"Temperature\":msg.payload.rows[i]['temp'],\n  \"Humidity\":msg.payload.rows[i]['humidity']});\n}\n\nmsg.payload = list_data;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":300,"wires":[["997a83e59f6a3cdc"]]},{"id":"997a83e59f6a3cdc","type":"ui_table","z":"08dc41d47d4d9e09","group":"756d53853a29259a","name":"","order":0,"width":"8","height":"14","columns":[],"outputs":1,"cts":true,"x":670,"y":300,"wires":[["7fd94d3ea87889b9"]]},{"id":"7fd94d3ea87889b9","type":"template","z":"08dc41d47d4d9e09","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"Time: {{payload.Time}}<br>\nTemperature: {{payload.Temperature}}<br>\nHumidity: {{payload.Humidity}}<br>","output":"str","x":790,"y":300,"wires":[["5d991cfa9fbd5624"]]},{"id":"5d991cfa9fbd5624","type":"ui_toast","z":"08dc41d47d4d9e09","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":true,"className":"","topic":"Data","name":"","x":950,"y":300,"wires":[]},{"id":"b7a62274d2e3e00a","type":"inject","z":"08dc41d47d4d9e09","name":"CREATE","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":400,"wires":[["7b87c1255de70067"]]},{"id":"47c2279e27890264","type":"inject","z":"08dc41d47d4d9e09","name":"INSERT 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":480,"wires":[["77ce9a8be017a108","b1e6cd67c3efbc9a","6bad2a6dc37cea5d"]]},{"id":"77ce9a8be017a108","type":"random","z":"08dc41d47d4d9e09","name":"temp","low":"10","high":"45","inte":"true","property":"payload","x":310,"y":440,"wires":[["a2b84168d315fcb0"]]},{"id":"6bad2a6dc37cea5d","type":"function","z":"08dc41d47d4d9e09","name":"function name","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();     //秒\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 var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\nvar date_time = yyyy+'/'+MM+'/'+dd+ ' '+h+':'+m+':'+s;\n\nmsg.payload=date_time;\nflow.set('time',date_time);\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":520,"wires":[["90ba57a6962cd376"]]},{"id":"a2b84168d315fcb0","type":"function","z":"08dc41d47d4d9e09","name":"function temp","func":"var temp=msg.payload;\nflow.set('temp',temp);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":440,"wires":[[]]},{"id":"d28a9b235c2408b3","type":"postgres","z":"08dc41d47d4d9e09","postgresdb":"d02a35f8c3a63a7c","name":"DHT11","output":true,"perrow":false,"rowspermsg":"1","return_on_error":false,"limit_queries":"0","limit_by":"payload","limit_value":"1","limit_drop_intermediate":false,"limit_drop_if_in_queue":false,"outputs":true,"x":490,"y":400,"wires":[["eee469a9a3490ab3"]]},{"id":"7b87c1255de70067","type":"function","z":"08dc41d47d4d9e09","name":"function  ","func":"msg.payload = `CREATE TABLE DHT11sensor(\n    user_id serial PRIMARY KEY,\n    time timestamp,\n    temp float4,\n    humidity float4\n)`\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":400,"wires":[["d28a9b235c2408b3"]]},{"id":"90ba57a6962cd376","type":"function","z":"08dc41d47d4d9e09","name":"function","func":"var time1=flow.get('time');\nvar temp1=flow.get('temp');\nvar humidity1=flow.get('humidity');\n\n\nmsg.payload={\n    time: time1,\n    temp: temp1,\n    humidity: humidity1\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":520,"wires":[["4f835c264a3542bb","c6e36a0b21561204"]]},{"id":"eee469a9a3490ab3","type":"debug","z":"08dc41d47d4d9e09","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":400,"wires":[]},{"id":"4f835c264a3542bb","type":"debug","z":"08dc41d47d4d9e09","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":520,"wires":[]},{"id":"c6e36a0b21561204","type":"function","z":"08dc41d47d4d9e09","name":"function   Add db ","func":"msg.payload = `INSERT INTO DHT11sensor( time, temp, humidity)\nVALUES (\n '${msg.payload.time}',\n '${msg.payload.temp}', \n '${msg.payload.humidity}')\n returning *\n`\nreturn msg;\n\n\n//msg.payload = `CREATE TABLE DHT11sensor(\n//    user_id serial PRIMARY KEY,\n//    time timestamp,\n//    temp float4,\n//    humidity float4\n//)`\n\n//return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":620,"wires":[["e621d8a99137d96f"]]},{"id":"e621d8a99137d96f","type":"postgres","z":"08dc41d47d4d9e09","postgresdb":"d02a35f8c3a63a7c","name":"DHT11","output":true,"perrow":false,"rowspermsg":"1","return_on_error":false,"limit_queries":"0","limit_by":"payload","limit_value":"1","limit_drop_intermediate":false,"limit_drop_if_in_queue":false,"outputs":true,"x":730,"y":620,"wires":[["89398818c2863b22"]]},{"id":"89398818c2863b22","type":"debug","z":"08dc41d47d4d9e09","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":620,"wires":[]},{"id":"b1e6cd67c3efbc9a","type":"random","z":"08dc41d47d4d9e09","name":"humidity","low":"25","high":"100","inte":"true","property":"payload","x":320,"y":480,"wires":[["b2012bfbe7bb4b05"]]},{"id":"b2012bfbe7bb4b05","type":"function","z":"08dc41d47d4d9e09","name":"function humidity","func":"var humidity=msg.payload;\nflow.set('humidity',humidity);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":480,"wires":[[]]},{"id":"7c706fad4771614c","type":"function","z":"08dc41d47d4d9e09","name":"Format chart","func":"var time2 =msg.payload.rows[0].time;\n\nmsg.payload=time2;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":100,"wires":[["cd4adcf359d66588"]]},{"id":"b98af31e5c23d7ac","type":"postgresDB","name":"DHT11","throwErrors":true,"throwErrorsFieldType":"bool","host":"127.0.0.1","hostFieldType":"str","port":"5432","portFieldType":"num","database":"DHT11","databaseFieldType":"str","ssl":"false","sslFieldType":"bool","max":"10","maxFieldType":"num","min":"1","minFieldType":"num","idle":"1000","idleFieldType":"num","connectionTimeout":"10000","connectionTimeoutFieldType":"num","user":"postgres","userFieldType":"str","password":"Alex9981","passwordFieldType":"str"},{"id":"49ca43fc9b95bcc1","type":"ui_group","name":"Current Temperature & Humidity","tab":"50b4e86120098aeb","order":1,"disp":true,"width":"13","collapse":false,"className":""},{"id":"6879ef9ca30c1e34","type":"ui_group","name":"Chart","tab":"50b4e86120098aeb","order":2,"disp":true,"width":"13","collapse":false,"className":""},{"id":"756d53853a29259a","type":"ui_group","name":"Raw Data Table","tab":"50b4e86120098aeb","order":3,"disp":true,"width":"8","collapse":false,"className":""},{"id":"d02a35f8c3a63a7c","type":"postgresdb","cfgname":"DHT11","hostname":"localhost","port":"5432","db":"DHT11","ssl":false},{"id":"50b4e86120098aeb","type":"ui_tab","name":"DHT-11","icon":"dashboard","order":7,"disabled":false,"hidden":false}]


更新後


[{"id":"acddd911a6412f0a","type":"inject","z":"08dc41d47d4d9e09","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"15","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":130,"y":140,"wires":[["60f82608b91e1010","a7941c012545db2a"]]},{"id":"60f82608b91e1010","type":"postgrestor","z":"08dc41d47d4d9e09","name":"DHT11","query":"SELECT * FROM DHT11sensor order by time desc limit 1;","postgresDB":"b98af31e5c23d7ac","output":true,"outputs":1,"throwErrors":false,"x":290,"y":140,"wires":[["2536c7ad0157dbf2","cd48a2caa41c4e6d","7c706fad4771614c","16216b92fe56954d"]]},{"id":"2536c7ad0157dbf2","type":"ui_gauge","z":"08dc41d47d4d9e09","name":"","group":"49ca43fc9b95bcc1","order":2,"width":"6","height":"4","gtype":"gage","title":"Temperature","label":"C","format":"{{payload.rows[0].temp}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":510,"y":140,"wires":[]},{"id":"cd48a2caa41c4e6d","type":"ui_gauge","z":"08dc41d47d4d9e09","name":"","group":"49ca43fc9b95bcc1","order":3,"width":"6","height":"4","gtype":"gage","title":"Humidity","label":"%","format":"{{payload.rows[0].humidity}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":500,"y":180,"wires":[]},{"id":"cd4adcf359d66588","type":"ui_text","z":"08dc41d47d4d9e09","group":"49ca43fc9b95bcc1","order":1,"width":0,"height":0,"name":"","label":"Update Time:   ","format":"{{msg.payload}}","layout":"row-left","className":"","x":730,"y":100,"wires":[]},{"id":"a7941c012545db2a","type":"postgrestor","z":"08dc41d47d4d9e09","name":"DHT11","query":"select TO_CHAR(time, 'YYYY-MM-DD HH:mm:ss') as time,temp,humidity from (SELECT * FROM DHT11sensor order by time desc limit 30) as data order by time;","postgresDB":"b98af31e5c23d7ac","output":true,"outputs":1,"throwErrors":false,"x":290,"y":220,"wires":[["de934747674f4abc","b6869634764c8604","15f7b694306c2f80"]]},{"id":"bc052292a6aa1f41","type":"ui_chart","z":"08dc41d47d4d9e09","name":"","group":"6879ef9ca30c1e34","order":0,"width":"13","height":"4","label":"Temperature","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":690,"y":220,"wires":[[]]},{"id":"de934747674f4abc","type":"function","z":"08dc41d47d4d9e09","name":"Format chart","func":"var data = [];\nvar label = [];\nvar i;\ndata.push([]);\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  data[0].push(msg.payload.rows[i]['temp']);\n}\n\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  label.push(msg.payload.rows[i]['time']);\n}\n\nvar m={\n    \"series\":[\"Temperature\"],\n    \"data\":data,\n    \"labels\":label\n};\n\nreturn {payload:[m]};\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":220,"wires":[["bc052292a6aa1f41"]]},{"id":"864f41576f8d37a8","type":"ui_chart","z":"08dc41d47d4d9e09","name":"","group":"6879ef9ca30c1e34","order":0,"width":"13","height":"4","label":"Humidity","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":680,"y":260,"wires":[[]]},{"id":"b6869634764c8604","type":"function","z":"08dc41d47d4d9e09","name":"Format chart","func":"var data = [];\nvar label = [];\nvar i;\ndata.push([]);\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  data[0].push(msg.payload.rows[i]['humidity']);\n}\n\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  label.push(msg.payload.rows[i]['time']);\n}\n\nvar m={\n    \"series\":[\"Humidity\"],\n    \"data\":data,\n    \"labels\":label\n};\n\nreturn {payload:[m]};\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":260,"wires":[["864f41576f8d37a8"]]},{"id":"15f7b694306c2f80","type":"function","z":"08dc41d47d4d9e09","name":"create array","func":"\nvar i;\nvar list_data = [];\nfor (i = 0; i < msg.payload.rows.length; i++) \n{\n  list_data.push({\"No\":i+1,\"Time\":msg.payload.rows[i]['time'],\"Temperature\":msg.payload.rows[i]['temp'],\n  \"Humidity\":msg.payload.rows[i]['humidity']});\n}\n\nmsg.payload = list_data;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":300,"wires":[["997a83e59f6a3cdc"]]},{"id":"997a83e59f6a3cdc","type":"ui_table","z":"08dc41d47d4d9e09","group":"756d53853a29259a","name":"","order":0,"width":"8","height":"14","columns":[],"outputs":1,"cts":true,"x":670,"y":300,"wires":[[]]},{"id":"7fd94d3ea87889b9","type":"template","z":"08dc41d47d4d9e09","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"\nTime: {{payload.time}} <br>\nTemperature: {{payload.temp}} <br>\nHumidity: {{payload.humidity}} <br>\n","output":"str","x":670,"y":40,"wires":[["5d991cfa9fbd5624"]]},{"id":"5d991cfa9fbd5624","type":"ui_toast","z":"08dc41d47d4d9e09","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":true,"className":"","topic":"Data","name":"","x":830,"y":40,"wires":[]},{"id":"b7a62274d2e3e00a","type":"inject","z":"08dc41d47d4d9e09","name":"CREATE","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":400,"wires":[["7b87c1255de70067"]]},{"id":"47c2279e27890264","type":"inject","z":"08dc41d47d4d9e09","name":"INSERT 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":480,"wires":[["77ce9a8be017a108","b1e6cd67c3efbc9a","6bad2a6dc37cea5d"]]},{"id":"77ce9a8be017a108","type":"random","z":"08dc41d47d4d9e09","name":"temp","low":"10","high":"45","inte":"true","property":"payload","x":310,"y":440,"wires":[["a2b84168d315fcb0"]]},{"id":"6bad2a6dc37cea5d","type":"function","z":"08dc41d47d4d9e09","name":"function name","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();     //秒\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 var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\nvar date_time = yyyy+'/'+MM+'/'+dd+ ' '+h+':'+m+':'+s;\n\nmsg.payload=date_time;\nflow.set('time',date_time);\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":520,"wires":[["90ba57a6962cd376"]]},{"id":"a2b84168d315fcb0","type":"function","z":"08dc41d47d4d9e09","name":"function temp","func":"var temp=msg.payload;\nflow.set('temp',temp);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":440,"wires":[[]]},{"id":"d28a9b235c2408b3","type":"postgres","z":"08dc41d47d4d9e09","postgresdb":"d02a35f8c3a63a7c","name":"DHT11","output":true,"perrow":false,"rowspermsg":"1","return_on_error":false,"limit_queries":"0","limit_by":"payload","limit_value":"1","limit_drop_intermediate":false,"limit_drop_if_in_queue":false,"outputs":true,"x":490,"y":400,"wires":[["eee469a9a3490ab3"]]},{"id":"7b87c1255de70067","type":"function","z":"08dc41d47d4d9e09","name":"function  ","func":"msg.payload = `CREATE TABLE DHT11sensor(\n    user_id serial PRIMARY KEY,\n    time timestamp,\n    temp float4,\n    humidity float4\n)`\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":400,"wires":[["d28a9b235c2408b3"]]},{"id":"90ba57a6962cd376","type":"function","z":"08dc41d47d4d9e09","name":"function","func":"var time1=flow.get('time');\nvar temp1=flow.get('temp');\nvar humidity1=flow.get('humidity');\n\n\nmsg.payload={\n    time: time1,\n    temp: temp1,\n    humidity: humidity1\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":520,"wires":[["4f835c264a3542bb","c6e36a0b21561204"]]},{"id":"eee469a9a3490ab3","type":"debug","z":"08dc41d47d4d9e09","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":400,"wires":[]},{"id":"4f835c264a3542bb","type":"debug","z":"08dc41d47d4d9e09","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":520,"wires":[]},{"id":"c6e36a0b21561204","type":"function","z":"08dc41d47d4d9e09","name":"function   Add db ","func":"msg.payload = `INSERT INTO DHT11sensor( time, temp, humidity)\nVALUES (\n '${msg.payload.time}',\n '${msg.payload.temp}', \n '${msg.payload.humidity}')\n returning *\n`\nreturn msg;\n\n\n//msg.payload = `CREATE TABLE DHT11sensor(\n//    user_id serial PRIMARY KEY,\n//    time timestamp,\n//    temp float4,\n//    humidity float4\n//)`\n\n//return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":620,"wires":[["e621d8a99137d96f"]]},{"id":"e621d8a99137d96f","type":"postgres","z":"08dc41d47d4d9e09","postgresdb":"d02a35f8c3a63a7c","name":"DHT11","output":true,"perrow":false,"rowspermsg":"1","return_on_error":false,"limit_queries":"0","limit_by":"payload","limit_value":"1","limit_drop_intermediate":false,"limit_drop_if_in_queue":false,"outputs":true,"x":730,"y":620,"wires":[["89398818c2863b22"]]},{"id":"89398818c2863b22","type":"debug","z":"08dc41d47d4d9e09","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":620,"wires":[]},{"id":"b1e6cd67c3efbc9a","type":"random","z":"08dc41d47d4d9e09","name":"humidity","low":"25","high":"100","inte":"true","property":"payload","x":320,"y":480,"wires":[["b2012bfbe7bb4b05"]]},{"id":"b2012bfbe7bb4b05","type":"function","z":"08dc41d47d4d9e09","name":"function humidity","func":"var humidity=msg.payload;\nflow.set('humidity',humidity);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":480,"wires":[[]]},{"id":"7c706fad4771614c","type":"function","z":"08dc41d47d4d9e09","name":"Format chart","func":"var time2 =msg.payload.rows[0].time;\n\nmsg.payload=time2;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":100,"wires":[["cd4adcf359d66588"]]},{"id":"16216b92fe56954d","type":"function","z":"08dc41d47d4d9e09","name":"function 96","func":"\nvar time2 =msg.payload.rows[0].time;\nvar temp2 =msg.payload.rows[0].temp;\nvar humidity2 =msg.payload.rows[0].humidity;\n\nmsg.payload.time=time2;\nmsg.payload.temp=temp2;\nmsg.payload.humidity=humidity2;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":40,"wires":[["7fd94d3ea87889b9"]]},{"id":"b98af31e5c23d7ac","type":"postgresDB","name":"DHT11","throwErrors":true,"throwErrorsFieldType":"bool","host":"127.0.0.1","hostFieldType":"str","port":"5432","portFieldType":"num","database":"DHT11","databaseFieldType":"str","ssl":"false","sslFieldType":"bool","max":"10","maxFieldType":"num","min":"1","minFieldType":"num","idle":"1000","idleFieldType":"num","connectionTimeout":"10000","connectionTimeoutFieldType":"num","user":"postgres","userFieldType":"str","password":"Alex9981","passwordFieldType":"str"},{"id":"49ca43fc9b95bcc1","type":"ui_group","name":"Current Temperature & Humidity","tab":"50b4e86120098aeb","order":1,"disp":true,"width":"13","collapse":false,"className":""},{"id":"6879ef9ca30c1e34","type":"ui_group","name":"Chart","tab":"50b4e86120098aeb","order":2,"disp":true,"width":"13","collapse":false,"className":""},{"id":"756d53853a29259a","type":"ui_group","name":"Raw Data Table","tab":"50b4e86120098aeb","order":3,"disp":true,"width":"8","collapse":false,"className":""},{"id":"d02a35f8c3a63a7c","type":"postgresdb","cfgname":"DHT11","hostname":"localhost","port":"5432","db":"DHT11","ssl":false},{"id":"50b4e86120098aeb","type":"ui_tab","name":"DHT-11","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

沒有留言:

張貼留言

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

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