-
Notifications
You must be signed in to change notification settings - Fork 1
/
dynamicserial.ino
54 lines (51 loc) · 1.35 KB
/
dynamicserial.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <SoftwareSerial.h>
SoftwareSerial s(12,14);
#include <ArduinoJson.h>
void setup() {
// Initialize Serial port
Serial.begin(115200);
s.begin(115200);
while (!Serial) continue;
}
void loop() {
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(s);
if (root == JsonObject::invalid())
{
return;
}
//Print the data in the serial monitor
Serial.println("JSON received and parsed");
root.prettyPrintTo(Serial);
Serial.println("");
Serial.print("Temperature ");
float data1=root["temp"];
Serial.println(data1);
Serial.print("Humidity ");
float data2=root["hum"];
Serial.println(data2);
Serial.print("Heat-index ");
float data3=root["hi"];
Serial.println(data3);
Serial.print("CO2: ");
float co2=root["CO2"];
Serial.println(co2);
Serial.print("propane: ");
float propane=root["Propane"];
Serial.println(propane);
Serial.print("alcohol");
float alcohol=root["Alcohol"];
Serial.println(alcohol);
Serial.print("ch4: ");
float ch4=root["CH4"];
Serial.println(ch4);
Serial.print("lpg: ");
float lpg=root["LPG"];
Serial.println(lpg);
Serial.print("h2: ");
float h2=root["H2"];
Serial.println(h2);
Serial.println("");
Serial.println("---------------------xxxxx--------------------");
Serial.println("");
}