Ok so now i formatted the data into JSON but in my node red is not showing up anything.
Arduino code:
#include <ArduinoJson.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
dht.begin();
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1);
}
}
void loop() {
float Temperature = dht.readTemperature();
float Humidity = dht.readHumidity();
if (isnan(Temperature) || isnan(Humidity)){
Serial.println("Failed to read from DHT sensor!");
return;
}
float bmppressure = bmp.readPressure()/100.00;
float bmpaltitude = bmp.readAltitude();
unsigned int ldrValue;
ldrValue = analogRead(A0);
StaticJsonDocument<200> jsonDoc;
jsonDoc["dht"]["humidity"] = Humidity;
jsonDoc["dht"]["temperature"] = Temperature;
jsonDoc["bmp"]["altitude"] = bmpaltitude;
jsonDoc["bmp"]["pressure"] = bmppressure;
jsonDoc["ldr"]["lightLevel"] = ldrValue;
serializeJson(jsonDoc, Serial);
/*String dhtData = String(Humidity) + "," + String(Temperature);
String bmpData = String(bmpaltitude) + "," + String(bmppressure);
String ldrData = String(ldrValue);
Serial.println(dhtData);
Serial.println(bmpData);
Serial.println(ldrData);*/
delay(3000);
}
This is my node red flow:
[
{
"id": "187b0bb9eda06271",
"type": "tab",
"label": "Smart Weather Monitoring System",
"disabled": false,
"info": "",
"env": []
},
{
"id": "d884e680153f7ef9",
"type": "serial in",
"z": "187b0bb9eda06271",
"name": "Arduino Maker Uno",
"serial": "f8031aa692189f38",
"x": 110,
"y": 220,
"wires": [
[
"298062ff1bce572c"
]
]
},
{
"id": "43b64526193c24c0",
"type": "function",
"z": "187b0bb9eda06271",
"name": "Data",
"func": "let data = (typeof msg.payload === 'string' ? msg.payload : msg.payload.toString()).split(',');\n\nlet Humidity = { payload: parseFloat(data[0]) };\nlet Temperature = { payload: parseFloat(data[1]) };\n\nlet Altitude = { payload: parseFloat(data[2]) };\nlet Pressure = { payload: parseFloat(data[3]) };\n\nlet LightLevel = { payload: parseInt(data[4]) }\n\nreturn [Humidity,Temperature,Altitude,Pressure,LightLevel];\n",
"outputs": 3,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 490,
"y": 220,
"wires": [
[
"cb2b8668573a675c",
"3c5c16bcb2531195"
],
[
"9521c4917a80a9a0",
"a83551e53e6e8cf9"
],
[
"fe061fa0a7a3a932",
"efb25ca3a309af9a"
]
]
},
{
"id": "cb2b8668573a675c",
"type": "change",
"z": "187b0bb9eda06271",
"name": "Humidity & Temperature",
"rules": [
{
"t": "set",
"p": "fields.humidity",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "tags.region",
"pt": "msg",
"to": "KL",
"tot": "str"
},
{
"t": "set",
"p": "fields.temperature",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$append(fields,tags)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 770,
"y": 60,
"wires": [
[
"f6c309b7549c21c0"
]
]
},
{
"id": "3c5c16bcb2531195",
"type": "debug",
"z": "187b0bb9eda06271",
"name": "Humidity & Temperature",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 100,
"wires": []
},
{
"id": "f6c309b7549c21c0",
"type": "mqtt out",
"z": "187b0bb9eda06271",
"name": "Humidity & Temperature",
"topic": "sensor/dht11/HumidANDTemp",
"qos": "0",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "262512044f4f61ac",
"x": 1190,
"y": 60,
"wires": []
},
{
"id": "1c98f6a210d9a5cb",
"type": "mqtt in",
"z": "187b0bb9eda06271",
"name": "Humidity & Temperature",
"topic": "sensor/dht11/HumidANDTemp",
"qos": "0",
"datatype": "auto-detect",
"broker": "262512044f4f61ac",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 120,
"y": 420,
"wires": [
[]
]
},
{
"id": "0327f64d58edc99b",
"type": "influxdb out",
"z": "187b0bb9eda06271",
"influxdb": "921764b5c0c308e9",
"name": "Humidity & Temperature",
"measurement": "HumidTemp",
"precision": "",
"retentionPolicy": "",
"database": "database",
"precisionV18FluxV20": "ms",
"retentionPolicyV18Flux": "",
"org": "organisation",
"bucket": "bucket",
"x": 470,
"y": 420,
"wires": []
},
{
"id": "b1d8a857d8b58b2b",
"type": "inject",
"z": "187b0bb9eda06271",
"name": "Humidity & Temperature",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "10",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 770,
"y": 420,
"wires": [
[
"f317d195f17e386f"
]
]
},
{
"id": "f317d195f17e386f",
"type": "influxdb in",
"z": "187b0bb9eda06271",
"influxdb": "921764b5c0c308e9",
"name": "Humidity & Temperature",
"query": "select * from HumidTemp",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 1130,
"y": 420,
"wires": [
[
"9b67bc942370f8f1",
"95e5f54cb3cb3f0c"
]
]
},
{
"id": "9b67bc942370f8f1",
"type": "ui_gauge",
"z": "187b0bb9eda06271",
"name": "Humidity",
"group": "73e85ccf4436dcc5",
"order": 1,
"width": 6,
"height": 4,
"gtype": "gage",
"title": "Humidity",
"label": "%rh",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1460,
"y": 400,
"wires": []
},
{
"id": "95e5f54cb3cb3f0c",
"type": "ui_gauge",
"z": "187b0bb9eda06271",
"name": "Temperature",
"group": "73e85ccf4436dcc5",
"order": 2,
"width": 6,
"height": 4,
"gtype": "gage",
"title": "Temperature",
"label": "Celcius",
"format": "{{value}}°C",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1470,
"y": 440,
"wires": []
},
{
"id": "9521c4917a80a9a0",
"type": "change",
"z": "187b0bb9eda06271",
"name": "Altitude & Atmospheric Pressure",
"rules": [
{
"t": "set",
"p": "fields.altitude",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "tags.location",
"pt": "msg",
"to": "indoors",
"tot": "str"
},
{
"t": "set",
"p": "fields.pressure",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$append(fields,tags)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 790,
"y": 180,
"wires": [
[
"ea005c1d37e31c5e"
]
]
},
{
"id": "ea005c1d37e31c5e",
"type": "mqtt out",
"z": "187b0bb9eda06271",
"name": "Altitude & Atmospheric Pressure",
"topic": "sensor/bmp180/AltitudeANDPressure",
"qos": "0",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "262512044f4f61ac",
"x": 1210,
"y": 180,
"wires": []
},
{
"id": "a83551e53e6e8cf9",
"type": "debug",
"z": "187b0bb9eda06271",
"name": "Altitude & Atmospheric Pressure",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 790,
"y": 220,
"wires": []
},
{
"id": "fe061fa0a7a3a932",
"type": "change",
"z": "187b0bb9eda06271",
"name": "Luminousity",
"rules": [
{
"t": "set",
"p": "tags.status",
"pt": "msg",
"to": "Good",
"tot": "str"
},
{
"t": "set",
"p": "fields.lightLevel",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$append(fields,tags)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 730,
"y": 300,
"wires": [
[
"8e1747b1f9b24bef"
]
]
},
{
"id": "8e1747b1f9b24bef",
"type": "mqtt out",
"z": "187b0bb9eda06271",
"name": "Luminousity",
"topic": "sensor/ldr/luminousity",
"qos": "0",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "262512044f4f61ac",
"x": 1150,
"y": 300,
"wires": []
},
{
"id": "efb25ca3a309af9a",
"type": "debug",
"z": "187b0bb9eda06271",
"name": "Luminousity",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 730,
"y": 340,
"wires": []
},
{
"id": "de3c5ea50f1fea9e",
"type": "mqtt in",
"z": "187b0bb9eda06271",
"name": "Altitude & Atmospheric Pressure",
"topic": "sensor/bmp180/AltitudeANDPressure",
"qos": "0",
"datatype": "auto-detect",
"broker": "262512044f4f61ac",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 150,
"y": 480,
"wires": [
[]
]
},
{
"id": "7e7eb7b086be8aea",
"type": "mqtt in",
"z": "187b0bb9eda06271",
"name": "Luminousity",
"topic": "sensor/ldr/luminousity",
"qos": "0",
"datatype": "auto-detect",
"broker": "262512044f4f61ac",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 90,
"y": 540,
"wires": [
[]
]
},
{
"id": "077cdcf90a88e107",
"type": "influxdb out",
"z": "187b0bb9eda06271",
"influxdb": "921764b5c0c308e9",
"name": "Altitude & Atmospheric Pressure",
"measurement": "AltiPres",
"precision": "",
"retentionPolicy": "",
"database": "database",
"precisionV18FluxV20": "ms",
"retentionPolicyV18Flux": "",
"org": "organisation",
"bucket": "bucket",
"x": 490,
"y": 480,
"wires": []
},
{
"id": "107ef1e8df34e717",
"type": "influxdb out",
"z": "187b0bb9eda06271",
"influxdb": "921764b5c0c308e9",
"name": "Luminousity",
"measurement": "luminousity",
"precision": "",
"retentionPolicy": "",
"database": "database",
"precisionV18FluxV20": "ms",
"retentionPolicyV18Flux": "",
"org": "organisation",
"bucket": "bucket",
"x": 430,
"y": 540,
"wires": []
},
{
"id": "19c0a1e84ad3b9f3",
"type": "inject",
"z": "187b0bb9eda06271",
"name": "Altitude & Atmospheric Pressure",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "10",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 800,
"y": 500,
"wires": [
[
"a66fd1da4f53e1b6"
]
]
},
{
"id": "a66fd1da4f53e1b6",
"type": "influxdb in",
"z": "187b0bb9eda06271",
"influxdb": "921764b5c0c308e9",
"name": "Altitude & Atmospheric Pressure",
"query": "select * from AltiPres",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 1150,
"y": 500,
"wires": [
[
"8a575bbfbfd7d159",
"655c9885536327a3"
]
]
},
{
"id": "8a575bbfbfd7d159",
"type": "ui_gauge",
"z": "187b0bb9eda06271",
"name": "Altitude",
"group": "73e85ccf4436dcc5",
"order": 3,
"width": 6,
"height": 4,
"gtype": "wave",
"title": "Altitude",
"label": "meters",
"format": "{{value}}",
"min": "500",
"max": "1200",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1460,
"y": 480,
"wires": []
},
{
"id": "655c9885536327a3",
"type": "ui_gauge",
"z": "187b0bb9eda06271",
"name": "Atmospheric Pressure",
"group": "73e85ccf4436dcc5",
"order": 4,
"width": 6,
"height": 4,
"gtype": "wave",
"title": "Atmospheric Pressure",
"label": "Pa",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1500,
"y": 520,
"wires": []
},
{
"id": "a64c47964ffb2163",
"type": "inject",
"z": "187b0bb9eda06271",
"name": "Luminousity",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "10",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 730,
"y": 580,
"wires": [
[
"d7cda6c27c50de2c"
]
]
},
{
"id": "d7cda6c27c50de2c",
"type": "influxdb in",
"z": "187b0bb9eda06271",
"influxdb": "921764b5c0c308e9",
"name": "Luminousity",
"query": "select * from luminousity",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 1090,
"y": 580,
"wires": [
[
"4ea5d6334f76f042"
]
]
},
{
"id": "4ea5d6334f76f042",
"type": "ui_gauge",
"z": "187b0bb9eda06271",
"name": "Luminousity",
"group": "73e85ccf4436dcc5",
"order": 6,
"width": 6,
"height": 4,
"gtype": "donut",
"title": "Luminousity",
"label": "lx",
"format": "{{value}}",
"min": 0,
"max": "1000",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1470,
"y": 580,
"wires": []
},
{
"id": "298062ff1bce572c",
"type": "json",
"z": "187b0bb9eda06271",
"name": "JSON to String/Object",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 320,
"y": 220,
"wires": [
[
"43b64526193c24c0"
]
]
},
{
"id": "326407df7896fa4f",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "dcee4deb41a081e3",
"order": 5,
"width": 3,
"height": 1
},
{
"id": "ab4e8ece052ee7df",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "dcee4deb41a081e3",
"order": 7,
"width": 3,
"height": 1
},
{
"id": "7118a611b5e78c39",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "dcee4deb41a081e3",
"order": 8,
"width": 3,
"height": 1
},
{
"id": "5bd96b67d74d8666",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "dcee4deb41a081e3",
"order": 9,
"width": 3,
"height": 1
},
{
"id": "25d2d5596d5348c2",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "dcee4deb41a081e3",
"order": 10,
"width": 3,
"height": 1
},
{
"id": "a8ed22c0c0383de1",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "dcee4deb41a081e3",
"order": 11,
"width": 3,
"height": 1
},
{
"id": "76569fc26d088856",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 5,
"width": 3,
"height": 1
},
{
"id": "958aabaf0ed9df4d",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 7,
"width": 3,
"height": 1
},
{
"id": "df3831187c0a8804",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 8,
"width": 3,
"height": 1
},
{
"id": "10eae83ae4ef8890",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 9,
"width": 3,
"height": 1
},
{
"id": "86724259dec5773c",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 10,
"width": 3,
"height": 1
},
{
"id": "56da73672c15615f",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 11,
"width": 3,
"height": 1
},
{
"id": "552fe493d28b50b5",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 12,
"width": 3,
"height": 1
},
{
"id": "3572c60d2d1c408d",
"type": "ui_spacer",
"z": "187b0bb9eda06271",
"name": "spacer",
"group": "73e85ccf4436dcc5",
"order": 13,
"width": 3,
"height": 1
},
{
"id": "f8031aa692189f38",
"type": "serial-port",
"serialport": "COM7",
"serialbaud": "9600",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"dtr": "none",
"rts": "none",
"cts": "none",
"dsr": "none",
"newline": "\\n",
"bin": "false",
"out": "char",
"addchar": "",
"responsetimeout": "10000"
},
{
"id": "262512044f4f61ac",
"type": "mqtt-broker",
"name": "",
"broker": "broker.emqx.io",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "921764b5c0c308e9",
"type": "influxdb",
"hostname": "127.0.0.1",
"port": "8086",
"protocol": "http",
"database": "SWMS",
"name": "SWMS",
"usetls": false,
"tls": "",
"influxdbVersion": "1.x",
"url": "http://localhost:8086",
"rejectUnauthorized": true
},
{
"id": "73e85ccf4436dcc5",
"type": "ui_group",
"name": "Assignment",
"tab": "c9feb0502bf4a2fb",
"order": 1,
"disp": true,
"width": 12,
"collapse": false
},
{
"id": "dcee4deb41a081e3",
"type": "ui_group",
"name": "Assignment",
"tab": "13ff37f4e3992732",
"order": 1,
"disp": true,
"width": 12,
"collapse": false
},
{
"id": "c9feb0502bf4a2fb",
"type": "ui_tab",
"name": "SWMS",
"icon": "dashboard",
"disabled": false,
"hidden": false
},
{
"id": "13ff37f4e3992732",
"type": "ui_tab",
"name": "Smart Weather Monitoring System",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]