include common.mk
-all: compile flash
+all: compile
# To run Particle, we need to install Particle CLI
# Please see:
rm -f *.bin
particle compile photon
-flash:
- particle flash Photon photon_firmware*.bin
+flash0:
+ particle flash IoT-0 photon_firmware*.bin
+
+flash1:
+ particle flash IoT-1 photon_firmware*.bin
+
+flash2:
+ particle flash IoT-2 photon_firmware*.bin
+
+flash3:
+ particle flash IoT-3 photon_firmware*.bin
+
+flash4:
+ particle flash IoT-4 photon_firmware*.bin
+
+flash5:
+ particle flash IoT-5 photon_firmware*.bin
+
+flash6:
+ particle flash IoT-6 photon_firmware*.bin
+
+flash7:
+ particle flash IoT-7 photon_firmware*.bin
+
PHONY += clean
clean:
#define ERRPIN D7 // Error pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// IoTCloud
-#define SLEEP_TIME 30 // Sleep time in seconds
+#define SLEEP_TIME 300 // 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
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
digitalWrite(PWRPIN, HIGH);
// Arduino DHT
dht.begin();
- // Connect to WiFi
- Particle.connect();
+ // Connect to WiFi and Particle cloud
// Wait for a maximum amount of time - sleep if WiFi is not connected
// Wake up and try again afterwards
- if (!waitFor(Particle.connected, RETRY_TIME))
+ // TODO: either use this or just WiFi connection (below)
+ //Particle.connect();
+ //if (!waitFor(Particle.connected, RETRY_TIME))
+ // System.sleep(SLEEP_MODE_DEEP, RETRY_SLEEP_TIME);
+
+ // Connect only to WiFi
+ WiFi.on();
+ WiFi.connect();
+ 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)
+ if (micros() < CONNECTION_DELAY)
+ // Delays are in millis but micros() returns microsecond time
+ delay((CONNECTION_DELAY - micros())/1000);
+
+ // TODO: Profiling WiFi
+ //Serial.println(micros());
+ //while(true) { }
+
// Prepare device key from MAC (just last 2 of 6 digits)
byte mac[6];
WiFi.macAddress(mac);
// TODO: Uncomment the following block to print MAC
- //Serial.begin();
//for (int i=0; i<6; i++) {
// Serial.printf("%02x%s", mac[i], i != 5 ? ":" : "");
//}
transStatusList = new MyVector<TransactionStatus *>();
IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
IoTString *password = new IoTString("reallysecret");
-
//Serial.print("Time begin rebuilding table: ");
//Serial.println(micros());
// Turn off sensor
digitalWrite(PWRPIN, LOW);
+ // TODO: Profiling!
//Serial.print("Time end loop: ");
//Serial.println(micros());
//while(true) { }