Adding code to connect just WiFi and not Particle cloud, i.e. Particle.connect().
authorrtrimana <rtrimana@uci.edu>
Tue, 24 Apr 2018 22:34:23 +0000 (15:34 -0700)
committerrtrimana <rtrimana@uci.edu>
Tue, 24 Apr 2018 22:34:23 +0000 (15:34 -0700)
version2/src/C/Makefile
version2/src/C/Sensor-Arduino.ino
version2/src/C/Table.cpp

index ee49f31f15112f6433ffe8a9a7dfe95dc8234cf0..ab535de291b82b21250bd2808eda451d791c2b00 100644 (file)
@@ -1,6 +1,6 @@
 include common.mk
 
-all: compile flash
+all: compile
 
 # To run Particle, we need to install Particle CLI
 # Please see: 
@@ -13,8 +13,30 @@ compile:
        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:
index 241d6524a5e4589afdde4f8e34fea8f71f02dd7b..86e610154efdc9bbfcb870b795d9a2232f0f140c 100644 (file)
@@ -14,9 +14,10 @@ SYSTEM_THREAD(ENABLED)
 #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);
@@ -59,19 +60,35 @@ void setup() {
        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 ? ":" : "");
        //}
@@ -87,7 +104,6 @@ void setup() {
        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());     
        
@@ -159,6 +175,7 @@ void loop() {
        // Turn off sensor
        digitalWrite(PWRPIN, LOW);
 
+       // TODO: Profiling!
        //Serial.print("Time end loop: ");
        //Serial.println(micros());
        //while(true) { }
index ecca22b5061e47299c12ec59ff557e15aebb6717..a1df03ac5969c2b70842242642031d7039d10cc6 100755 (executable)
@@ -1504,7 +1504,7 @@ void Table::validateAndUpdate(Array<Slot *> *newSlots, bool acceptUpdatesToLocal
                }
        }
        delete indexer;
-       
+
        // If there is a gap, check to see if the server sent us
        // everything->
        if (firstSeqNum != (sequenceNumber + 1)) {