Data transfer from the DSM501 sensor and their processing.
I have an air quality sensor. It sends me 2 values via MQTT. I want from values #1 - values #2. But there is a feature which is this. Data from values No. 1 arrives inconsistently in time (not simultaneously with values No. 2).
What I have learned to do. I take the data of values #1 and send it to an array and then to a google spreadsheet.
And I need to process the data for a period of time or when array 1 is full (because data from values #1 (array 1) comes faster and more often, and data from values #2 (array 2) is slower and not often) and do the calculation again reset the arrays and start filling arrays and calculate when array 1 is full (or take a time interval of 10 seconds and without waiting for the arrays to be filled, calculate the sum of the values of array 1 minus the sum of the values of array 2). At me the new data arrives and mixes up with old.
How can you imagine this for example: you have two taps of water and 2 cups. Beer is flowing rapidly from faucet 1, Water is slowly flowing from faucet 2. Task: to make it so that when at the same time substitute cups and draw beer and water (beer will be filled faster), and then stop taking liquid and from beer minus water we get alcohol. And send the sum further to the calculation (in my case, I will take PM1-2.5 =PM1 - PM2.5 (the value of the sum of array No. 1 - the values of the sum of array No. 2) and calculate the number of aerosol particles per cubic meter (multiply by 0.063612) then I will compare the calculation with the value from the table and get AQI). Help with calculation. I don't learn much about Node-red because I'm new. And My language is not English.
[
{
"id": "ce5f9295acae69c9",
"type": "tab",
"label": "Поток 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c15babbc86b96938",
"type": "mqtt in",
"z": "ce5f9295acae69c9",
"name": "5",
"topic": "5",
"qos": "0",
"datatype": "auto",
"broker": "c921ebcdcb990496",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 70,
"y": 140,
"wires": [
[
"dd0655b255ebba53",
"c4fba6126fc48066"
]
]
},
{
"id": "dd0655b255ebba53",
"type": "json",
"z": "ce5f9295acae69c9",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 230,
"y": 140,
"wires": [
[
"f4a795ba665dd443",
"e837b2c033314bc0",
"b5d22844641e410e"
]
]
},
{
"id": "e837b2c033314bc0",
"type": "ui_chart",
"z": "ce5f9295acae69c9",
"name": "",
"group": "9df7d4a7be7d6ef8",
"order": 2,
"width": "0",
"height": "0",
"label": "chart 1",
"chartType": "line",
"legend": "true",
"xformat": "auto",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "5000",
"ymax": "50000",
"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": 730,
"y": 100,
"wires": [
[]
]
},
{
"id": "c4fba6126fc48066",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "5",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 270,
"y": 40,
"wires": []
},
{
"id": "f4a795ba665dd443",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "5",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 530,
"y": 60,
"wires": []
},
{
"id": "5fdad0a31e59a198",
"type": "mqtt in",
"z": "ce5f9295acae69c9",
"name": "2",
"topic": "2",
"qos": "0",
"datatype": "auto",
"broker": "c921ebcdcb990496",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 70,
"y": 460,
"wires": [
[
"e088b00e0a941448",
"82ef43acd07b8682"
]
]
},
{
"id": "e088b00e0a941448",
"type": "json",
"z": "ce5f9295acae69c9",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 230,
"y": 460,
"wires": [
[
"c11182337f7a4c3b",
"99a3a3479239a017",
"148e6f5916686ae2"
]
]
},
{
"id": "99a3a3479239a017",
"type": "ui_chart",
"z": "ce5f9295acae69c9",
"name": "",
"group": "9df7d4a7be7d6ef8",
"order": 2,
"width": "0",
"height": "0",
"label": "chart 2",
"chartType": "line",
"legend": "true",
"xformat": "auto",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "5000",
"ymax": "70000",
"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": 390,
"y": 440,
"wires": [
[]
]
},
{
"id": "82ef43acd07b8682",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 250,
"y": 400,
"wires": []
},
{
"id": "c11182337f7a4c3b",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 430,
"y": 500,
"wires": []
},
{
"id": "2f906ea82871ebc1",
"type": "inject",
"z": "ce5f9295acae69c9",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "2",
"payloadType": "num",
"x": 90,
"y": 560,
"wires": [
[
"e088b00e0a941448"
]
]
},
{
"id": "3d249954550d23ce",
"type": "GSheet",
"z": "ce5f9295acae69c9",
"creds": "80ad0a94372d6b76",
"method": "append",
"action": "",
"sheet": "",
"cells": "",
"flatten": false,
"name": "5",
"x": 710,
"y": 200,
"wires": [
[
"c098d5b3068a9f5b"
]
]
},
{
"id": "c098d5b3068a9f5b",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "5",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 320,
"wires": []
},
{
"id": "f5ee2445bf0c7f9c",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 730,
"y": 160,
"wires": []
},
{
"id": "b5d22844641e410e",
"type": "buffer-array",
"z": "ce5f9295acae69c9",
"name": "Array 1",
"bufferLen": "3",
"startWhenFilled": true,
"x": 380,
"y": 200,
"wires": [
[
"e303d128b1a65822"
]
]
},
{
"id": "e303d128b1a65822",
"type": "change",
"z": "ce5f9295acae69c9",
"name": "Array Sum 1",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$sum(payload)\t\t",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 200,
"wires": [
[
"f5ee2445bf0c7f9c",
"3d249954550d23ce"
]
]
},
{
"id": "3a144eae801291e2",
"type": "GSheet",
"z": "ce5f9295acae69c9",
"creds": "80ad0a94372d6b76",
"method": "append",
"action": "",
"sheet": "",
"cells": "",
"flatten": false,
"name": "2",
"x": 710,
"y": 620,
"wires": [
[
"d22dd40082f64ff7"
]
]
},
{
"id": "148e6f5916686ae2",
"type": "buffer-array",
"z": "ce5f9295acae69c9",
"name": "Array 2",
"bufferLen": "3",
"startWhenFilled": true,
"x": 420,
"y": 620,
"wires": [
[
"067a5a5ef005ecd6"
]
]
},
{
"id": "067a5a5ef005ecd6",
"type": "change",
"z": "ce5f9295acae69c9",
"name": "Array Sum 2",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$sum(payload)\t\t",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 570,
"y": 620,
"wires": [
[
"3a144eae801291e2"
]
]
},
{
"id": "d22dd40082f64ff7",
"type": "debug",
"z": "ce5f9295acae69c9",
"name": "2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 730,
"y": 700,
"wires": []
},
{
"id": "c8603859a4f18752",
"type": "ui_spacer",
"z": "ce5f9295acae69c9",
"name": "spacer",
"group": "9df7d4a7be7d6ef8",
"order": 1,
"width": 1,
"height": 1
},
{
"id": "0745b821a53b8fcc",
"type": "ui_spacer",
"z": "ce5f9295acae69c9",
"name": "spacer",
"group": "9df7d4a7be7d6ef8",
"order": 1,
"width": 1,
"height": 1
},
{
"id": "c921ebcdcb990496",
"type": "mqtt-broker",
"name": "8266server",
"broker": "",
"port": "1883",
"clientid": "10",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": false,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "9df7d4a7be7d6ef8",
"type": "ui_group",
"name": "Air purity",
"tab": "33495f98ffb09225",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "80ad0a94372d6b76",
"type": "gauth",
"name": "Unknown"
},
{
"id": "33495f98ffb09225",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]