From 24593ac424c95b1afe6e573b6db2756cb98d4bac Mon Sep 17 00:00:00 2001 From: rtrimana Date: Tue, 24 Apr 2018 15:34:23 -0700 Subject: [PATCH] Adding code to connect just WiFi and not Particle cloud, i.e. Particle.connect(). --- version2/src/C/Makefile | 28 +++++++++++++++++++++++++--- version2/src/C/Sensor-Arduino.ino | 31 ++++++++++++++++++++++++------- version2/src/C/Table.cpp | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/version2/src/C/Makefile b/version2/src/C/Makefile index ee49f31..ab535de 100644 --- a/version2/src/C/Makefile +++ b/version2/src/C/Makefile @@ -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: diff --git a/version2/src/C/Sensor-Arduino.ino b/version2/src/C/Sensor-Arduino.ino index 241d652..86e6101 100644 --- a/version2/src/C/Sensor-Arduino.ino +++ b/version2/src/C/Sensor-Arduino.ino @@ -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(); 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) { } diff --git a/version2/src/C/Table.cpp b/version2/src/C/Table.cpp index ecca22b..a1df03a 100755 --- a/version2/src/C/Table.cpp +++ b/version2/src/C/Table.cpp @@ -1504,7 +1504,7 @@ void Table::validateAndUpdate(Array *newSlots, bool acceptUpdatesToLocal } } delete indexer; - + // If there is a gap, check to see if the server sent us // everything-> if (firstSeqNum != (sequenceNumber + 1)) { -- 2.34.1