Adding .ino files for IoTCloud library tests (periodic write and sleep); adding DHT...
[iotcloud.git] / version2 / src / others / ino / Periodic.ino
1 /**
2  * Periodic write and sleep to cloud.
3  * @author Rahmadi Trimananda <rtrimana@uci.edu>
4  * @version 1.0
5  */
6
7 #include "Table.h"
8 #include "IoTString.h"
9 #include "TimingSingleton.h"
10 #include "TransactionStatus.h"
11
12 #define SLEEP_TIME 300  // in seconds
13
14 TimingSingleton *timer;
15 bool foundError;
16 MyVector<TransactionStatus *> * transStatusList;
17 char keyBuffer[80];
18 char dataBuffer[80];
19
20 Table *t1;
21 IoTString *iKeyA;
22 IoTString *iValueA;
23
24 void setup() {
25         // TODO: This test uses the Serial library
26         // Please install "screen" on your machine and run
27         // it on the serial port right after flashing the
28         // firmware onto the Particle board.
29         // e.g. sudo screen /dev/ttyACM0
30         Serial.begin();
31         timer = TimingSingleton_getInstance();
32         foundError = false;
33         transStatusList = new MyVector<TransactionStatus *>();
34         IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
35         IoTString *password = new IoTString("reallysecret");
36         t1 = new Table(baseurl, password, 321, -1);
37         t1->rebuild();
38
39         baseurl->releaseRef();
40         password->releaseRef();
41 }
42
43
44 void loop() {
45         // Key
46         sprintf(keyBuffer, "sensor0");
47         iKeyA = new IoTString(keyBuffer);
48
49         // Do Updates for the keys
50         sprintf(dataBuffer, "data92617");
51         iValueA = new IoTString(dataBuffer);
52
53         t1->startTransaction();
54         t1->put(iKeyA, iValueA);
55         transStatusList->add(t1->commitTransaction());
56         t1->update();
57
58         iKeyA->releaseRef();
59         iValueA->releaseRef();
60         System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME);
61 }