3 #include "TimingSingleton.h"
4 #include "TransactionStatus.h"
9 #define DHTPIN 2 // what pin we're connected to
10 #define DHTTYPE DHT22 // DHT 22 (AM2302)
12 #define SLEEP_TIME 1800 // Sleep time in seconds
14 // Initialize DHT sensor for normal 16mhz Arduino
15 DHT dht(DHTPIN, DHTTYPE);
19 TimingSingleton *timer;
21 MyVector<TransactionStatus *> * transStatusList;
30 // TODO: If you want to use the Serial library,
31 // please install "screen" on your machine and run
32 // it on the serial port right after flashing the
33 // firmware onto the Particle board.
34 // e.g. sudo screen /dev/ttyACM0
36 // Prepare device key from MAC (just last 2 of 6 digits)
40 // TODO: Uncomment the following block to print MAC
42 //for (int i=0; i<6; i++) {
43 // Serial.printf("%02x%s", mac[i], i != 5 ? ":" : "");
47 int64_t machineId = (int64_t) mac[4] + mac[5];
49 timer = TimingSingleton_getInstance();
51 transStatusList = new MyVector<TransactionStatus *>();
52 IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
53 IoTString *password = new IoTString("reallysecret");
54 t1 = new Table(baseurl, password, machineId, -1);
57 baseurl->releaseRef();
58 password->releaseRef();
66 // Wait until sensor is ready
68 // Read temperature as Fahrenheit
69 float tempF = dht.readTemperature(true);
70 // Check if any reads failed and exit early (to try again).
75 sprintf(keyBuffer, "sensor0");
76 iKeyA = new IoTString(keyBuffer);
78 // Do updates for the temperature
79 sprintf(dataBuffer, "%f", tempF);
80 iValueA = new IoTString(dataBuffer);
82 t1->startTransaction();
83 t1->put(iKeyA, iValueA);
84 transStatusList->add(t1->commitTransaction());
88 iValueA->releaseRef();
89 System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME);