Thanks! finally I used you suggestion with var timeStamp = new Date(); and works fine now.
I try to show back in graph the data collected by the Mysql based on example i found in
https://flows.nodered.org/flow/13c55d1aa11e864609e24fa534a1fa26
but unfortunately doesnt work. I tried to adjust it with my limited knowlege on this but still...
any clue how to show back the data?
Here below my complete flow
[
{
"id": "5ed7faf3.7da194",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": ""
},
{
"id": "cef973e0.4f14",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "",
"topic": "qiot/things/admin/unowifi/18ds20",
"qos": "0",
"datatype": "auto",
"broker": "79f88f2d.0eb26",
"x": 144.01736450195312,
"y": 53.26042938232422,
"wires": [
[
"8686ae1f.5c71a",
"c741bdcb.c539f"
]
]
},
{
"id": "8686ae1f.5c71a",
"type": "delay",
"z": "5ed7faf3.7da194",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "10",
"nbRateUnits": "1",
"rateUnits": "hour",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 342.45838165283203,
"y": 155.67013597488403,
"wires": [
[
"596ee9c.cc98018"
]
]
},
{
"id": "596ee9c.cc98018",
"type": "function",
"z": "5ed7faf3.7da194",
"name": "prepare data to sql",
"func": "var sensorVal= parseFloat(msg.payload);\n//var timeStamp = msg.timestamp;\nvar timeStamp = new Date();\nvar sensorName = \"UnoWifiDS18B20\"; // defined string. Or should this be aquired from the topic?\n\n// replace myTable with your db table name \nmsg.topic = \"INSERT INTO Sensor_data (Sensor_Val, Time, Sensor_Name) VALUES (?,?,?)\";\nmsg.payload = [sensorVal, timeStamp, sensorName];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 596.6978149414062,
"y": 159.31246185302734,
"wires": [
[
"9a8874a1.0f8f78",
"c2a3837c.19267"
]
]
},
{
"id": "cf4bf498.e89f28",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1111.708251953125,
"y": 184.61454963684082,
"wires": []
},
{
"id": "9a8874a1.0f8f78",
"type": "mysql",
"z": "5ed7faf3.7da194",
"mydb": "bc8ab442.0892a8",
"name": "",
"x": 845.2047119140625,
"y": 157.6528549194336,
"wires": [
[
"cf4bf498.e89f28"
]
]
},
{
"id": "c741bdcb.c539f",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 420.2499465942383,
"y": 41.75003433227539,
"wires": []
},
{
"id": "c2a3837c.19267",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "complete msg",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 857.5,
"y": 125.0000228881836,
"wires": []
},
{
"id": "f6193383.b7c27",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "esp8266/18ds20",
"topic": "qiot/things/admin/ESPeasy/ds18b20/Temp",
"qos": "0",
"datatype": "auto",
"broker": "dfce0de9.dd384",
"x": 97.99996948242188,
"y": 361.01040840148926,
"wires": [
[
"846e36fc.fdc7d8"
]
]
},
{
"id": "b846580b.b51268",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "esp8266 Rssi",
"topic": "qiot/things/admin/ESPeasy/sys_info/rssi",
"qos": "0",
"datatype": "auto",
"broker": "dfce0de9.dd384",
"x": 100.99995422363281,
"y": 969.0104389190674,
"wires": [
[]
]
},
{
"id": "972109d8.7ad7f8",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "UNO wifi RSSI",
"topic": "arduino",
"qos": "0",
"datatype": "auto",
"broker": "dfce0de9.dd384",
"x": 101.99995422363281,
"y": 824.0107555389404,
"wires": [
[]
]
},
{
"id": "5dfeca1f.5ff2a4",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "esp8266Soil/18ds20",
"topic": "qiot/things/admin/esp8266Soil/18ds20/Temp",
"qos": "0",
"datatype": "auto",
"broker": "dfce0de9.dd384",
"x": 102.99999237060547,
"y": 263.0106430053711,
"wires": [
[
"a36e7864.d03e58"
]
]
},
{
"id": "9ae687ad.e8bd58",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "esp8266Soil RSSI",
"topic": "qiot/things/admin/esp8266Soil/sysinfo/rssi",
"qos": "0",
"datatype": "auto",
"broker": "dfce0de9.dd384",
"x": 110.99993896484375,
"y": 901.0107955932617,
"wires": [
[
"92bda667.dbde48",
"a6dab5f8.a5da88"
]
]
},
{
"id": "7935196d.886808",
"type": "comment",
"z": "5ed7faf3.7da194",
"name": "SENSOR RSSI",
"info": "",
"x": 105.18054962158203,
"y": 762.4931545257568,
"wires": []
},
{
"id": "92bda667.dbde48",
"type": "function",
"z": "5ed7faf3.7da194",
"name": "prepare data to sql",
"func": "var SensorRSSI_val= parseFloat(msg.payload);\n//var timeStamp = msg.timestamp;\nvar timeStamp = new Date();\nvar SensorRSSI_Name = \"esp8266Soil_RSSI\"; // defined string. Or should this be aquired from the topic?\n\n// replace myTable with your db table name \nmsg.topic = \"INSERT INTO SensorRSSI (SensorRSSI_val, SensorRSSI_time, SensorRSSI_Name) VALUES (?,?,?)\";\nmsg.payload = [SensorRSSI_val, timeStamp, SensorRSSI_Name];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 493.25678634643555,
"y": 900.3196086883545,
"wires": [
[
"6832b15.bf2095",
"682a8ce2.833864"
]
]
},
{
"id": "1e5c1ae8.0c68f5",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 976.2672119140625,
"y": 905.6217641830444,
"wires": []
},
{
"id": "6832b15.bf2095",
"type": "mysql",
"z": "5ed7faf3.7da194",
"mydb": "bc8ab442.0892a8",
"name": "",
"x": 731.7636833190918,
"y": 898.6600017547607,
"wires": [
[
"1e5c1ae8.0c68f5"
]
]
},
{
"id": "682a8ce2.833864",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "complete msg",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 754.0589714050293,
"y": 866.0071697235107,
"wires": []
},
{
"id": "a6dab5f8.a5da88",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 472.18044662475586,
"y": 856.9273343086243,
"wires": []
},
{
"id": "a36e7864.d03e58",
"type": "function",
"z": "5ed7faf3.7da194",
"name": "prepare data to sql",
"func": "var sensorVal= parseFloat(msg.payload);\n//var timeStamp = msg.timestamp;\nvar timeStamp = new Date();\nvar sensorName = \"ESP8266SoilDS18B20\"; // defined string. Or should this be aquired from the topic?\n\n// replace myTable with your db table name \nmsg.topic = \"INSERT INTO Sensor_data (Sensor_Val, Time, Sensor_Name) VALUES (?,?,?)\";\nmsg.payload = [sensorVal, timeStamp, sensorName];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 621.2567977905273,
"y": 261.65273237228394,
"wires": [
[
"7c1b707.71dbb9",
"a595e30b.e8793"
]
]
},
{
"id": "279343aa.0028fc",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1136.267234802246,
"y": 286.9548201560974,
"wires": []
},
{
"id": "7c1b707.71dbb9",
"type": "mysql",
"z": "5ed7faf3.7da194",
"mydb": "bc8ab442.0892a8",
"name": "",
"x": 869.7636947631836,
"y": 259.9931254386902,
"wires": [
[
"279343aa.0028fc"
]
]
},
{
"id": "a595e30b.e8793",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "complete msg",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 882.0589828491211,
"y": 227.34029340744019,
"wires": []
},
{
"id": "846e36fc.fdc7d8",
"type": "function",
"z": "5ed7faf3.7da194",
"name": "prepare data to sql",
"func": "var sensorVal= parseFloat(msg.payload);\n//var timeStamp = msg.timestamp;\nvar timeStamp = new Date();\nvar sensorName = \"ESP8266_18DS20\"; // defined string. Or should this be aquired from the topic?\n\n// replace myTable with your db table name \nmsg.topic = \"INSERT INTO Sensor_data (Sensor_Val, Time, Sensor_Name) VALUES (?,?,?)\";\nmsg.payload = [sensorVal, timeStamp, sensorName];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 631.2567977905273,
"y": 364.65273237228394,
"wires": [
[
"790fd8ab.8981d8",
"e75b426d.812a5"
]
]
},
{
"id": "a8e0b0e6.bfcfa",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1146.267234802246,
"y": 389.9548201560974,
"wires": []
},
{
"id": "790fd8ab.8981d8",
"type": "mysql",
"z": "5ed7faf3.7da194",
"mydb": "bc8ab442.0892a8",
"name": "",
"x": 879.7636947631836,
"y": 362.9931254386902,
"wires": [
[
"a8e0b0e6.bfcfa"
]
]
},
{
"id": "e75b426d.812a5",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "complete msg",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 892.0589828491211,
"y": 330.3402934074402,
"wires": []
},
{
"id": "df8d3209.6dff4",
"type": "mqtt in",
"z": "5ed7faf3.7da194",
"name": "esp8266Soil/SoilMoisture",
"topic": "qiot/things/admin/esp8266Soil/SoilMoisture1/Soil",
"qos": "0",
"datatype": "auto",
"broker": "dfce0de9.dd384",
"x": 115,
"y": 534.0104370117188,
"wires": [
[
"2f2c34ea.34757c"
]
]
},
{
"id": "52295e66.9a571",
"type": "comment",
"z": "5ed7faf3.7da194",
"name": "SENSOR Soil Moisture",
"info": "",
"x": 105,
"y": 471.0104064941406,
"wires": []
},
{
"id": "2f2c34ea.34757c",
"type": "function",
"z": "5ed7faf3.7da194",
"name": "prepare data to sql",
"func": "var sensorVal= parseFloat(msg.payload);\n//var timeStamp = msg.timestamp;\nvar timeStamp = new Date();\nvar sensorName = \"ESP8266_Soil\"; // defined string. Or should this be aquired from the topic?\n\n// replace myTable with your db table name \nmsg.topic = \"INSERT INTO Soil_data (Soil_Val, Soil_Time, Soil_Sensor_Name) VALUES (?,?,?)\";\nmsg.payload = [sensorVal, timeStamp, sensorName];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 444.0173645019531,
"y": 531.0104370117188,
"wires": [
[
"b30aa5af.4e73b8",
"90d818d1.58e228"
]
]
},
{
"id": "4ba61c22.c67074",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 959.0278015136719,
"y": 556.3125247955322,
"wires": []
},
{
"id": "b30aa5af.4e73b8",
"type": "mysql",
"z": "5ed7faf3.7da194",
"mydb": "bc8ab442.0892a8",
"name": "",
"x": 697.524284362793,
"y": 592.3508701324463,
"wires": [
[
"4ba61c22.c67074"
]
]
},
{
"id": "90d818d1.58e228",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "complete msg",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 704.8195495605469,
"y": 496.697998046875,
"wires": []
},
{
"id": "5ad2a546.30330c",
"type": "template",
"z": "5ed7faf3.7da194",
"name": "Format query 1",
"field": "topic",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "SELECT Sensor_Val,Sensor_Name,Time FROM Sensor_data WHERE time > {{payload}}",
"output": "str",
"x": 419.98268127441406,
"y": 1306.6771240234375,
"wires": [
[
"437443b9.463e5c"
]
]
},
{
"id": "c5e27001.6ffb6",
"type": "ui_chart",
"z": "5ed7faf3.7da194",
"name": "24 hours unowifi",
"group": "92af9b5c.356eb8",
"order": 2,
"width": "0",
"height": "0",
"label": "Chart",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": "24",
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"colors": [
"#00e68c",
"#2d2da8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"outputs": 1,
"x": 1149.9826736450195,
"y": 1240.6771259307861,
"wires": [
[]
]
},
{
"id": "437443b9.463e5c",
"type": "mysql",
"z": "5ed7faf3.7da194",
"mydb": "bc8ab442.0892a8",
"name": "MYSQL",
"x": 581.9826431274414,
"y": 1303.6771221160889,
"wires": [
[
"637ffcf6.860844",
"a96f7bc5.c35978"
]
]
},
{
"id": "5aff77b9.770f38",
"type": "function",
"z": "5ed7faf3.7da194",
"name": "Criteria",
"func": "var timeE = msg.payload;\n//Restrict the query to pull the last 24hrs\n//of data instead of the whole db\nmsg.payload = (timeE - (1000*60*60*24));\n node.status({text:msg.payload});\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 231.98265075683594,
"y": 1272.677128791809,
"wires": [
[
"5ad2a546.30330c"
]
]
},
{
"id": "637ffcf6.860844",
"type": "debug",
"z": "5ed7faf3.7da194",
"name": "",
"active": true,
"console": "false",
"complete": "false",
"x": 1008.9825973510742,
"y": 1333.6771221160889,
"wires": []
},
{
"id": "37f2ce1d.acc042",
"type": "inject",
"z": "5ed7faf3.7da194",
"name": "Timestamp",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"x": 113.98265838623047,
"y": 1218.6771297454834,
"wires": [
[
"5aff77b9.770f38"
]
]
},
{
"id": "7c2bf451.d1adec",
"type": "comment",
"z": "5ed7faf3.7da194",
"name": "Flow to query database and format for chart",
"info": "",
"x": 223.98265838623047,
"y": 1175.6771430969238,
"wires": []
},
{
"id": "a96f7bc5.c35978",
"type": "change",
"z": "5ed7faf3.7da194",
"name": "Format data",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "(\t $series := [\t { \"field\": \"Sensor_Val\", \"label\": \"Sensor_Name\" }\t ];\t $xaxis := \"timestamp\";\t [\t {\t \"series\": $series.label,\t \"data\": $series.[\t (\t $yaxis := $.field;\t $$.payload.{\t \"x\": $lookup($, $xaxis),\t \"y\": $lookup($, $yaxis)\t }\t )\t ]\t }\t ]\t)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 888.9826240539551,
"y": 1213.6771268844604,
"wires": [
[
"c5e27001.6ffb6"
]
]
},
{
"id": "222645ef.a31b9a",
"type": "comment",
"z": "5ed7faf3.7da194",
"name": "MYSQL example to chart data",
"info": "https://flows.nodered.org/flow/13c55d1aa11e864609e24fa534a1fa26",
"x": 125,
"y": 1091.677131652832,
"wires": []
},
{
"id": "79f88f2d.0eb26",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "375002bfab8d.sn.mynetname.net",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "bc8ab442.0892a8",
"type": "MySQLdatabase",
"z": "",
"host": "127.0.0.1",
"port": "3306",
"db": "node_red",
"tz": ""
},
{
"id": "dfce0de9.dd384",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "375002bfab8d.sn.mynetname.net",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "92af9b5c.356eb8",
"type": "ui_group",
"z": "",
"name": "Flow3 test",
"tab": "8b674cb8.c3c87",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "8b674cb8.c3c87",
"type": "ui_tab",
"z": "",
"name": "Test Mysql",
"icon": "dashboard",
"order": 6,
"disabled": false,
"hidden": false
}
]
Thanks once more in advance for all your valuable help on that!