In my flow I have two http-request nodes that I use (every ten minutes) to get data from an API. I filter the request data through five functions and I end up with five values:
- temperature
- humidity
- pressure
- PM10
- PM2.5
Now I have to store these variables into a new sqlite db, calculate the mean for each one (every two hours) and save it in a different table of my sqlite db. Lastly, I have to plot the mean.
I spent the last two days trying to store the values in a db but I'm so stuck. Can you please help me?
My flow is:
[
{
"id": "9bd4d4a2aefc85ef",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "b8b922afb22bcc64",
"type": "http request",
"z": "9bd4d4a2aefc85ef",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "data.sensor.community/airrohr/v1/sensor/56402/",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 490,
"y": 180,
"wires": [
[
"a7c40c9260131891",
"648ae758795c8323",
"52f3e8cec5632c1d"
]
]
},
{
"id": "972baebc079e5737",
"type": "inject",
"z": "9bd4d4a2aefc85ef",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "600",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 180,
"wires": [
[
"cab8ba5f69ac662f"
]
]
},
{
"id": "cab8ba5f69ac662f",
"type": "function",
"z": "9bd4d4a2aefc85ef",
"name": "msg headers",
"func": "\nmsg.headers = {};\nmsg.headers['content-type'] = 'application/json';\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 310,
"y": 180,
"wires": [
[
"b8b922afb22bcc64",
"4ce3f8e1f62d363c"
]
]
},
{
"id": "a7c40c9260131891",
"type": "function",
"z": "9bd4d4a2aefc85ef",
"name": "Temperature",
"func": "var temp = {};\n\ntemp.payload = Number(msg.payload[0].sensordatavalues[0].value);\n\ntemp.topic = \"Temperature: \";\n\nreturn temp;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 120,
"wires": [
[
"a93e0c9e08a7b2ce"
]
]
},
{
"id": "648ae758795c8323",
"type": "function",
"z": "9bd4d4a2aefc85ef",
"name": "Pressure",
"func": "var press = {};\n\npress.payload = Number(msg.payload[0].sensordatavalues[1].value);\npress.topic = \"Pressure: \";\n\nreturn press;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 700,
"y": 180,
"wires": [
[
"80fda223a34e984b"
]
]
},
{
"id": "52f3e8cec5632c1d",
"type": "function",
"z": "9bd4d4a2aefc85ef",
"name": "Humidity",
"func": "var hum = {};\n\nhum.payload = Number(msg.payload[0].sensordatavalues[2].value);\n\nhum.topic = \"Humidity: \";\n\nreturn hum;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 700,
"y": 240,
"wires": [
[
"905a3adce3845d77"
]
]
},
{
"id": "a93e0c9e08a7b2ce",
"type": "ui_chart",
"z": "9bd4d4a2aefc85ef",
"name": "",
"group": "5ad727043a9a374f",
"order": 1,
"width": 0,
"height": 0,
"label": "Temperature",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "-10",
"ymax": "40",
"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": 890,
"y": 120,
"wires": [
[]
]
},
{
"id": "80fda223a34e984b",
"type": "ui_chart",
"z": "9bd4d4a2aefc85ef",
"name": "",
"group": "eee15df9519e1362",
"order": 1,
"width": 0,
"height": 0,
"label": "Pressure",
"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": 880,
"y": 180,
"wires": [
[]
]
},
{
"id": "905a3adce3845d77",
"type": "ui_chart",
"z": "9bd4d4a2aefc85ef",
"name": "",
"group": "a13ed6592e65c37d",
"order": 1,
"width": 0,
"height": 0,
"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": 880,
"y": 240,
"wires": [
[]
]
},
{
"id": "4ce3f8e1f62d363c",
"type": "http request",
"z": "9bd4d4a2aefc85ef",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "data.sensor.community/airrohr/v1/sensor/56401/",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 490,
"y": 380,
"wires": [
[
"332f6ceab8a668af",
"c9ba0952a84ce5d1"
]
]
},
{
"id": "332f6ceab8a668af",
"type": "function",
"z": "9bd4d4a2aefc85ef",
"name": "PM10",
"func": "var pm10 = {};\n\npm10.payload = Number(msg.payload[0].sensordatavalues[0].value);\n\npm10.topic = \"PM10: \";\n\nreturn pm10;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 340,
"wires": [
[
"8355037b867a0a36"
]
]
},
{
"id": "c9ba0952a84ce5d1",
"type": "function",
"z": "9bd4d4a2aefc85ef",
"name": "PM2.5",
"func": "var pm25 = {};\n\npm25.payload = Number(msg.payload[0].sensordatavalues[1].value);\n\npm25.topic = \"PM25: \";\n\nreturn pm25;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 440,
"wires": [
[
"f6aec9e2bde9e73e"
]
]
},
{
"id": "8355037b867a0a36",
"type": "ui_chart",
"z": "9bd4d4a2aefc85ef",
"name": "",
"group": "bbd1bb4c3c1006dc",
"order": 1,
"width": 0,
"height": 0,
"label": "PM10",
"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": 870,
"y": 340,
"wires": [
[]
]
},
{
"id": "f6aec9e2bde9e73e",
"type": "ui_chart",
"z": "9bd4d4a2aefc85ef",
"name": "",
"group": "12ead6f68e7681c4",
"order": 1,
"width": 0,
"height": 0,
"label": "PM2.5",
"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": 870,
"y": 440,
"wires": [
[]
]
},
{
"id": "5ad727043a9a374f",
"type": "ui_group",
"name": "Temperature",
"tab": "922b63a179737013",
"order": 1,
"disp": true,
"width": "8",
"collapse": false,
"className": ""
},
{
"id": "eee15df9519e1362",
"type": "ui_group",
"name": "Pressure",
"tab": "922b63a179737013",
"order": 2,
"disp": true,
"width": "8",
"collapse": false,
"className": ""
},
{
"id": "a13ed6592e65c37d",
"type": "ui_group",
"name": "Humidity",
"tab": "922b63a179737013",
"order": 3,
"disp": true,
"width": "8",
"collapse": false,
"className": ""
},
{
"id": "bbd1bb4c3c1006dc",
"type": "ui_group",
"name": "PM10",
"tab": "f7ca8a44f3ea797f",
"order": 4,
"disp": true,
"width": "10",
"collapse": false,
"className": ""
},
{
"id": "12ead6f68e7681c4",
"type": "ui_group",
"name": "PM2.5",
"tab": "f7ca8a44f3ea797f",
"order": 5,
"disp": true,
"width": "10",
"collapse": false,
"className": ""
},
{
"id": "922b63a179737013",
"type": "ui_tab",
"name": "Sensor 56402: Temperature, Pressure, Humidity",
"icon": "dashboard",
"order": 2,
"disabled": false,
"hidden": false
},
{
"id": "f7ca8a44f3ea797f",
"type": "ui_tab",
"name": "Sensor 56401: PM2.5, PM10",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]