-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensing.ino
705 lines (598 loc) · 21.5 KB
/
sensing.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
#include <JSONVar.h>
#include <Arduino_JSON.h>
#include <JSON.h>
#include <Wire.h>
#include "Adafruit_SGP30.h"
#include "MutichannelGasSensor.h"
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include "SdsDustSensor.h"
#include "ThingSpeak.h"
#include <Arduino.h>
#include "sensirion_common.h"
#include <Adafruit_Sensor.h>
#include "DHT.h"
// Use this file to store all of the private credentials
// and connection details
#define SECRET_CH_ID1 864649 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY1 "D6WO0I37GORJEIV9" // replace XYZ with your channel write API Key
#define SECRET_CH_ID2 864650 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY2 "DDEGP9X1V4WEGEFH" // replace XYZ with your channel write API Key
#define SECRET_CH_ID3 864651 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY3 "MC5M1BZI4U9422XF" // replace XYZ with your channel write API Key
#define SECRET_CH_ID4 864652 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY4 "1T9T3FK7NR422DJP" // replace XYZ with your channel write API Key
//#define SECRET_CH_ID1 906528 // replace 0000000 with your channel number
//#define SECRET_WRITE_APIKEY1 "LL4J2EL6WCIW3SKD" // replace XYZ with your channel write API Key
//
//#define SECRET_CH_ID2 907653 // replace 0000000 with your channel number
//#define SECRET_WRITE_APIKEY2 "JIT20STHHFLPYTBD" // replace XYZ with your channel write API Key
//
//#define SECRET_CH_ID3 907654 // replace 0000000 with your channel number
//#define SECRET_WRITE_APIKEY3 "XSP8H1C1CD9VDQ2K" // replace XYZ with your channel write API Key
//
//#define SECRET_CH_ID4 907655 // replace 0000000 with your channel number
//#define SECRET_WRITE_APIKEY4 "Z5HI2QGCMDXMTGQ0" // replace XYZ with your channel write API Key
int rxPin = 14;
int txPin = 15;
SdsDustSensor sds(rxPin, txPin);
uint32_t delayMS;
int x;
// ##################### Update the Wifi SSID, Password and IP adress of the server ##########
// WIFI params
char* WIFI_SSID = "JioFi_20FDE31";
char* WIFI_PSWD = "n5v406hr5d";
//char* WIFI_SSID = "WPS unavailable";
//char* WIFI_PSWD = "no game no life";
String CSE_IP = "onem2m.iiit.ac.in";
// #######################################################
int WIFI_DELAY = 100; //ms
// oneM2M : CSE params
int CSE_HTTP_PORT = 80;
String CSE_NAME = "in-name";
String CSE_M2M_ORIGIN = "admin:admin";
// oneM2M : resources' params
String DESC_CNT_NAME = "DESCRIPTOR";
String DATA_CNT_NAME = "DATA";
String CMND_CNT_NAME = "COMMAND";
int TY_AE = 2;
int TY_CNT = 3;
int TY_CI = 4;
int TY_SUB = 23;
// HTTP constants
int LOCAL_PORT = 9999;
char* HTTP_CREATED = "HTTP/1.1 201 Created";
char* HTTP_OK = "HTTP/1.1 200 OK\r\n";
int REQUEST_TIME_OUT = 5000; //ms
//MISC
//int LED_PIN = D1;/
int SERIAL_SPEED = 9600;
#define DEBUG
///////////////////////////////////////////
//sensor variables
#define DHTPIN 0 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
float dht_val[2];
Adafruit_SGP30 sgp;
///////////////////////////////////////////
// Global variables
WiFiServer server(LOCAL_PORT); // HTTP Server (over WiFi). Binded to listen on LOCAL_PORT contant
WiFiClient client;
String context = "";
String command = ""; // The received command
unsigned long myChannelNumber1 = SECRET_CH_ID1;
const char * myWriteAPIKey1 = SECRET_WRITE_APIKEY1;
unsigned long myChannelNumber2 = SECRET_CH_ID2;
const char * myWriteAPIKey2 = SECRET_WRITE_APIKEY2;
unsigned long myChannelNumber3 = SECRET_CH_ID3;
const char * myWriteAPIKey3 = SECRET_WRITE_APIKEY3;
unsigned long myChannelNumber4 = SECRET_CH_ID4;
const char * myWriteAPIKey4 = SECRET_WRITE_APIKEY4;
String myStatus = "";
// Method for creating an HTTP POST with preconfigured oneM2M headers
// param : url --> the url path of the targted oneM2M resource on the remote CSE
// param : ty --> content-type being sent over this POST request (2 for ae, 3 for cnt, etc.)
// param : rep --> the representaton of the resource in JSON format
String doPOST(String url, int ty, String rep) {
String postRequest = String() + "POST " + url + " HTTP/1.1\r\n" +
"Host: " + CSE_IP + ":" + CSE_HTTP_PORT + "\r\n" +
"X-M2M-Origin: " + CSE_M2M_ORIGIN + "\r\n" +
"Content-Type: application/json;ty=" + ty + "\r\n" +
"Content-Length: " + rep.length() + "\r\n"
"Connection: close\r\n\n" +
rep;
// Connect to the CSE address
Serial.println("connecting to " + CSE_IP + ":" + CSE_HTTP_PORT + " ...");
// Get a client
WiFiClient client;
if (!client.connect(CSE_IP, CSE_HTTP_PORT)) {
Serial.println("Connection failed !");
return "error";
}
// if connection succeeds, we show the request to be send
#ifdef DEBUG
Serial.println(postRequest);
#endif
// Send the HTTP POST request
client.print(postRequest);
// Manage a timeout
unsigned long startTime = millis();
while (client.available() == 0) {
if (millis() - startTime > REQUEST_TIME_OUT) {
Serial.println("Client Timeout");
client.stop();
return "error";
}
}
// If success, Read the HTTP response
String result = "";
if (client.available()) {
result = client.readStringUntil('\r');
// Serial.println(result);
}
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection...");
return result;
}
// Method for creating an ApplicationEntity(AE) resource on the remote CSE (this is done by sending a POST request)
// param : ae --> the AE name (should be unique under the remote CSE)
String createAE(String ae) {
String aeRepresentation =
"{\"m2m:ae\": {"
"\"rn\":\"" + ae + "\","
"\"api\":\"org.demo." + ae + "\","
"\"rr\":\"true\","
"\"poa\":[\"http://" + WiFi.localIP().toString() + ":" + LOCAL_PORT + "/" + ae + "\"]"
"}}";
#ifdef DEBUG
Serial.println(aeRepresentation);
#endif
return doPOST("/" + CSE_NAME, TY_AE, aeRepresentation);
}
// Method for creating an Container(CNT) resource on the remote CSE under a specific AE (this is done by sending a POST request)
// param : ae --> the targeted AE name (should be unique under the remote CSE)
// param : cnt --> the CNT name to be created under this AE (should be unique under this AE)
String createCNT(String ae, String cnt) {
String cntRepresentation =
"{\"m2m:cnt\": {"
"\"rn\":\"" + cnt + "\","
"\"min\":\"" + -1 + "\""
"}}";
return doPOST("/" + CSE_NAME + "/" + ae, TY_CNT, cntRepresentation);
}
// Method for creating an ContentInstance(CI) resource on the remote CSE under a specific CNT (this is done by sending a POST request)
// param : ae --> the targted AE name (should be unique under the remote CSE)
// param : cnt --> the targeted CNT name (should be unique under this AE)
// param : ciContent --> the CI content (not the name, we don't give a name for ContentInstances)
String createCI(String ae, String cnt, String ciContent) {
String ciRepresentation =
"{\"m2m:cin\": {"
"\"con\":\"" + ciContent + "\""
"}}";
return doPOST("/" + CSE_NAME + "/" + ae + "/" + cnt, TY_CI, ciRepresentation);
}
// Method for creating an Subscription (SUB) resource on the remote CSE (this is done by sending a POST request)
// param : ae --> The AE name under which the SUB will be created .(should be unique under the remote CSE)
// The SUB resource will be created under the COMMAND container more precisely.
String createSUB(String ae) {
String subRepresentation =
"{\"m2m:sub\": {"
"\"rn\":\"SUB_" + ae + "\","
"\"nu\":[\"" + CSE_NAME + "/" + ae + "\"], "
"\"nct\":1"
"}}";
return doPOST("/" + CSE_NAME + "/" + ae + "/" + CMND_CNT_NAME, TY_SUB, subRepresentation);
}
// Method to register a module (i.e. sensor or actuator) on a remote oneM2M CSE
void registerModule(String module, bool isActuator, String intialDescription, String initialData) {
if (WiFi.status() == WL_CONNECTED) {
String result;
// 1. Create the ApplicationEntity (AE) for this sensor
result = createAE(module);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("AE " + module + " created !");
#endif
// 2. Create a first container (CNT) to store the description(s) of the sensor
result = createCNT(module, DESC_CNT_NAME);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("CNT " + module + "/" + DESC_CNT_NAME + " created !");
#endif
// Create a first description under this container in the form of a ContentInstance (CI)
result = createCI(module, DESC_CNT_NAME, intialDescription);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("CI " + module + "/" + DESC_CNT_NAME + "/{initial_description} created !");
#endif
}
}
// 3. Create a second container (CNT) to store the data of the sensor
result = createCNT(module, DATA_CNT_NAME);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("CNT " + module + "/" + DATA_CNT_NAME + " created !");
#endif
// Create a first data value under this container in the form of a ContentInstance (CI)
result = createCI(module, DATA_CNT_NAME, initialData);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("CI " + module + "/" + DATA_CNT_NAME + "/{initial_aata} created !");
#endif
}
}
// 3. if the module is an actuator, create a third container (CNT) to store the received commands
if (isActuator) {
result = createCNT(module, CMND_CNT_NAME);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("CNT " + module + "/" + CMND_CNT_NAME + " created !");
#endif
// subscribe to any ne command put in this container
result = createSUB(module);
if (result == HTTP_CREATED) {
#ifdef DEBUG
Serial.println("SUB " + module + "/" + CMND_CNT_NAME + "/SUB_" + module + " created !");
#endif
}
}
}
}
}
}
void init_WiFi() {
Serial.println("Connecting to " + String(WIFI_SSID) + " ...");
WiFi.persistent(false);
WiFi.begin(WIFI_SSID, WIFI_PSWD);
// wait until the device is connected to the wifi network
while (WiFi.status() != WL_CONNECTED) {
delay(WIFI_DELAY);
Serial.print(".");
}
// Connected, show the obtained ip address
Serial.println("WiFi Connected ==> IP Address = " + WiFi.localIP().toString());
}
void init_HTTPServer() {
server.begin();
Serial.println("Local HTTP Server started !");
}
void task_HTTPServer() {
// Check if a client is connected
client = server.available();
if (!client)
return;
// Wait until the client sends some data
Serial.println("New client connected. Receiving request... ");
while (!client.available()) {
#ifdef DEBUG_MODE
Serial.print(".");
#endif
delay(5);
}
// Read the request
String request = client.readString();
Serial.println(request);
client.flush();
int start, end;
// identify the right module (sensor or actuator) that received the notification
// the URL used is ip:port/ae
start = request.indexOf("/");
end = request.indexOf("HTTP") - 1;
context = request.substring(start + 1, end);
#ifdef DEBUG
Serial.println(String() + start + " , " + end + " -> " + context + ".");
#endif
// ingore verification messages
if (request.indexOf("vrq") > 0) {
client.flush();
return;
}
//Parse the request and identify the requested command from the device
//Request should be like "[operation_name]"
start = request.indexOf("[");
end = request.indexOf("]"); // first occurence of
command = request.substring(start + 1, end);
#ifdef DEBUG
Serial.println(String() + start + " , " + end + " -> " + command + ".");
#endif
client.flush();
}
// ######### START OF EXAMPLE ######### //
void init_luminosity() {
String initialDescription = "Name = LuminositySensor\t"
"Unit = Lux\t"
"Location = Home\t";
String initialData = "0";
registerModule("LuminositySensor", false, initialDescription, initialData);
}
void task_luminosity() {
int sensorValue;
int sensorPin = A0;
sensorValue = analogRead(sensorPin);
//sensorValue = random(10, 20);
#ifdef DEBUG
Serial.println("luminosity value = " + sensorValue);
#endif
String ciContent = String(sensorValue);
createCI("LuminositySensor", DATA_CNT_NAME, ciContent);
}
void init_led() {
String initialDescription = "Name = LedActuator\t"
"Location = Home\t";
String initialData = "off";
registerModule("LedActuator", true, initialDescription, initialData);
}
//void task_led() {
//
//}
//
//void command_led(String cmd) {
// //Serial.print(cmd);
// if (cmd == "switchOn") {
//#ifdef DEBUG
// Serial.println("Switching on the LED ...");
//#endif
// digitalWrite(LED_PIN, LOW);
// }
// else if (cmd == "switchOff") {
//#ifdef DEBUG
// Serial.println("Switching off the LED ...");
//#endif
// digitalWrite(LED_PIN, HIGH);
// }
//}
// ######### END OF EXAMPLE ######### //
/////////////////////////////////////////////////////////////////////////////////
// ######################################################## //
// ######### USE THIS SPACE TO DECLARE VARIABLES ######### //
// ######################################################## //
float temp, hum;
// ######################################################## //
void dht_usr()
{ Serial.println("Reading DHT values");
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
;//Serial.println(F("Failed to read from DHT sensor!"));
;
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
dht_val[0] = h;
dht_val[1] = t;
ThingSpeak.setField(1, String(h));
ThingSpeak.setField(2, String(t));
// write to the ThingSpeak channel
x = ThingSpeak.writeFields(myChannelNumber1, myWriteAPIKey1);
if (x == 200) {
Serial.println("Channel update successful.");
}
else {
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
float sgp_val[10];
void sgp_usr()
{
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
sgp_val[0] = sgp.TVOC;
sgp_val[1] = sgp.eCO2;
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
ThingSpeak.setField(1, String(sgp_val[0]));
ThingSpeak.setField(2, String(sgp_val[1]));
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber2, myWriteAPIKey2);
if (x == 200) {
Serial.println("Channel update successful.");
}
else {
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
if (! sgp.IAQmeasureRaw()) {
Serial.println("Raw Measurement failed");
return;
}
// sgp_val[2]= sgp.rawH2;
// Serial.print("Raw H2 "); Serial.print(sgp.rawH2); Serial.print(" \t");
// Serial.print("Raw Ethanol "); Serial.print(sgp.rawEthanol); Serial.println("");
delay(1000);
uint16_t TVOC_base, eCO2_base;
if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
Serial.println("Failed to get baseline readings");
return;
}
Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
}
float mgs_val[3];
void mgs_usr()
{
float c;
c = gas.measure_NH3();
mgs_val[0] = c;
Serial.print("The concentration of NH3 is ");
if (c >= 0) {
Serial.print(c);
}
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_CO();
mgs_val[1] = c;
Serial.print("The concentration of CO is ");
if (c >= 0) {
Serial.print(c);
}
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_NO2();
mgs_val[2] = c;
Serial.print("The concentration of NO2 is ");
if (c >= 0) {
Serial.print(c);
}
else Serial.print("invalid");
Serial.println(" ppm");
ThingSpeak.setField(1, String(mgs_val[0]));
ThingSpeak.setField(2, String(mgs_val[1]));
ThingSpeak.setField(3, String(mgs_val[2]));
// write to the ThingSpeak channel
x = ThingSpeak.writeFields(myChannelNumber4, myWriteAPIKey4);
if (x == 200) {
Serial.println("Channel update successful.");
}
else {
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
// c = gas.measure_C3H8();
// Serial.print("The concentration of C3H8 is ");
// if(c>=0) {
// Serial.print(c);
// }
// else Serial.print("invalid");
// Serial.println(" ppm");
//
// c = gas.measure_C4H10();
// Serial.print("The concentration of C4H10 is ");
// if(c>=0) {
// Serial.print(c);
// }
// else Serial.print("invalid");
// Serial.println(" ppm");
//
// c = gas.measure_CH4();
// Serial.print("The concentration of CH4 is ");
// if(c>=0) {
// Serial.print(c);
// }
// else Serial.print("invalid");
// Serial.println(" ppm");
//
// c = gas.measure_H2();
// Serial.print("The concentration of H2 is ");
// if(c>=0) {
// Serial.print(c);
// }
// else Serial.print("invalid");
// Serial.println(" ppm");
//
// c = gas.measure_C2H5OH();
// Serial.print("The concentration of C2H5OH is ");
// if(c>=0) {
// Serial.print(c);
// }
// else Serial.print("invalid");
// Serial.println(" ppm");
delay(1000);
;//Serial.println("...");
}
float sds_val[10];
void sds_usr()
{
Serial.println("sds");
PmResult pm = sds.readPm();
if (pm.isOk()) {
Serial.print("PM2.5 = ");
Serial.print(pm.pm25);
Serial.print(", PM10 = ");
Serial.println(pm.pm10);
sds_val[0] = pm.pm25;
sds_val[1] = pm.pm10;
ThingSpeak.setField(1, String(pm.pm25));
ThingSpeak.setField(2, String(pm.pm10));
// write to the ThingSpeak channel
x = ThingSpeak.writeFields(myChannelNumber3, myWriteAPIKey3);
if (x == 200) {
Serial.println("Channel update successful.");
}
else {
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
}
}
void setup() {
// intialize the serial liaison
Serial.begin(SERIAL_SPEED);
// Connect to WiFi network
init_WiFi();
ThingSpeak.begin(client);
// Start HTTP server
init_HTTPServer();
s16 err;
u16 scaled_ethanol_signal, scaled_h2_signal;
// ######### USE THIS SPACE FOR YOUR SETUP CODE ######### //
Serial.println("sensors initialising!!!");
sds.begin();
Serial.println("SDS initialised!!!");
// /rial.println(sds.setContinuousWorkingPeriod().toString()); // ensures sensor has continuous working period - default but not recommended
dht.begin();
Serial.println("dht initialised!!!");
sgp.begin();
Serial.println("sgp initialised!!!");
gas.begin(0x04);//the default I2C address of the slave is 0x04
Serial.println("gas initialised!!!");
gas.powerOn();
Serial.println("gas initialised!!!");
// ###################################################### //
}
// Main loop of the µController
void loop() {
// ############################################################### //
// ######### USE THIS SPACE FOR YOUR SENSOR POLING CODE ######### //
// ############################################################### //
Serial.print("yo");
for(int i=0;i<30;i++)
{ dht_usr();
sgp_usr();
mgs_usr();
sds_usr();
delay(20000);
}
// ######################################################### //
// ################################################################### //
// ######### USE THIS SPACE FOR YOUR SENDING DATA TO SERVER ######### //
// ################################################################### //
/*
CreateCI(AE_NAME,CONTAINER_NAME,SENSOR_VALUE)
CreateCI is what posts your sensor data into the container.
In the below example:
AE_NAME: Team8_Automated_Driving (As stated in the resource tree)
CONTAINER_NAME : node_1 ( or as stated in the resource tree)
SENSOR_VALUE : string of comma separated all sensor values (Eg: 27,25 is temp,hum)
*/
// Storing as a string in a single containers
String sensor_value_string;
sensor_value_string = String("dht : ") + String(dht_val[0]) + String(" , ") + String(dht_val[1]) + String(" \n ") + String("sgp : ") + String(sgp_val[0]) + String(" , ") + String(sgp_val[1]) + String(" \n ") + String("multi : ") + String(mgs_val[0]) + String(" , ") + String(mgs_val[1]) + String(" , ") + String(mgs_val[2]) + String(" \n ") + String("sds : ") + String(sds_val[0]) + String(" , ") + String(sds_val[1]) + String(" \n ") ;
createCI("Team14_Indoor_air_pollution_Mess", "node_1", sensor_value_string);
// Check if the data instance was created.
// delay(600000); // DO NOT CHANGE THIS VALUE
// ################################################################### //
}