#define ERRPIN D7 // Error pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// IoTCloud
-#define SLEEP_TIME 300 // Sleep time in seconds
+#define SLEEP_TIME 120 // Sleep time in seconds
#define RETRY_SLEEP_TIME 15 // Sleep time in seconds
#define RETRY_TIME 10000 // stop trying after 10 seconds
#define CONNECTION_DELAY 2100000 // Need to delay after connecting WiFi to wait for sensor
if (!waitFor(WiFi.ready, RETRY_TIME))
System.sleep(SLEEP_MODE_DEEP, RETRY_SLEEP_TIME);
// Check if we already got an IP from the router
- while(WiFi.localIP().toString().equals("0.0.0.0")) { }
- // Add delay if needed (for the humidity sensor we need ~2s delay)
+ while(!WiFi.localIP());
+ // Add delay if needed (for the humidity sensor we need ~2s delay)
if (micros() < CONNECTION_DELAY)
// Delays are in millis but micros() returns microsecond time
delay((CONNECTION_DELAY - micros())/1000);
int64_t mac4 = (int64_t) mac[4];
int64_t mac5 = (int64_t) mac[5];
machineId = (mac4 * 256) + mac5;
+ //machineId = (int64_t) mac[5]; // Shorter version of machine ID
// IoTCloud library
timer = TimingSingleton_getInstance();
transStatusList = new MyVector<TransactionStatus *>();
IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
IoTString *password = new IoTString("reallysecret");
+ // TODO: Profiling
//Serial.print("Time begin rebuilding table: ");
//Serial.println(micros());
baseurl->releaseRef();
password->releaseRef();
-
+ // TODO: Profiling
//Serial.print("Time end setup: ");
//Serial.println(micros());
}
void loop() {
// Wait until sensor is ready
//delay(2000);
+ // TODO: Profiling
//Serial.print("Time begin loop: ");
//Serial.println(micros());
// Read humidity
return;
// Humidity
// Key
- sprintf(keyBuffer, "humid%d", machineId);
+ sprintf(keyBuffer, "h%04x", machineId);
IoTString * iKeyHumid = new IoTString(keyBuffer);
// Do updates for the temperature
- sprintf(dataBuffer, "%f", humid);
+ sprintf(dataBuffer, "%0.2f", humid);
IoTString * iValueHumid = new IoTString(dataBuffer);
// Check and create a new key if it isn't created yet
// Temperature
// Key
- sprintf(keyBuffer, "tempF%d", machineId);
+ sprintf(keyBuffer, "t%04x", machineId);
IoTString * iKeyTempF = new IoTString(keyBuffer);
// Do updates for the temperature
- sprintf(dataBuffer, "%f", tempF);
+ sprintf(dataBuffer, "%0.2f", tempF);
IoTString * iValueTempF = new IoTString(dataBuffer);
// Check and create a new key if it isn't created yet
// Turn off sensor
digitalWrite(PWRPIN, LOW);
- // TODO: Profiling!
+ // TODO: Profiling
//Serial.print("Time end loop: ");
//Serial.println(micros());
//while(true) { }