3 #include "TimingSingleton.h"
4 #include "TransactionStatus.h"
9 #define DHTPIN 2 // Data pin
10 #define PWRPIN D5 // Power pin
11 #define DHTTYPE DHT22 // DHT 22 (AM2302)
13 #define SLEEP_TIME 1800 // Sleep time in seconds
15 // Initialize DHT sensor for normal 16mhz Arduino
16 DHT dht(DHTPIN, DHTTYPE);
20 TimingSingleton *timer;
22 MyVector<TransactionStatus *> * transStatusList;
31 // TODO: If you want to use the Serial library,
32 // please install "screen" on your machine and run
33 // it on the serial port right after flashing the
34 // firmware onto the Particle board.
35 // e.g. sudo screen /dev/ttyACM0
37 // We use one I/O pin to power the sensor so
38 // that we can make it go to sleep when we go into
40 pinMode(PWRPIN, OUTPUT);
42 digitalWrite(PWRPIN, HIGH);
44 // Prepare device key from MAC (just last 2 of 6 digits)
48 // TODO: Uncomment the following block to print MAC
50 //for (int i=0; i<6; i++) {
51 // Serial.printf("%02x%s", mac[i], i != 5 ? ":" : "");
55 int64_t machineId = (int64_t) mac[4] + mac[5];
57 timer = TimingSingleton_getInstance();
59 transStatusList = new MyVector<TransactionStatus *>();
60 IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
61 IoTString *password = new IoTString("reallysecret");
62 t1 = new Table(baseurl, password, machineId, -1);
65 baseurl->releaseRef();
66 password->releaseRef();
74 // Wait until sensor is ready
76 // Read temperature as Fahrenheit
77 float tempF = dht.readTemperature(true);
78 // Check if any reads failed and exit early (to try again).
83 sprintf(keyBuffer, "sensor0");
84 iKeyA = new IoTString(keyBuffer);
86 // Do updates for the temperature
87 sprintf(dataBuffer, "%f", tempF);
88 iValueA = new IoTString(dataBuffer);
90 t1->startTransaction();
91 t1->put(iKeyA, iValueA);
92 transStatusList->add(t1->commitTransaction());
96 iValueA->releaseRef();
99 digitalWrite(PWRPIN, LOW);
100 System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME);