Completing firmware for the temperature/humidity, IR, and magnetic sensors for both...
authorrtrimana <rtrimana@uci.edu>
Fri, 11 May 2018 16:25:06 +0000 (09:25 -0700)
committerrtrimana <rtrimana@uci.edu>
Fri, 11 May 2018 16:25:06 +0000 (09:25 -0700)
13 files changed:
version2/src/C/Makefile
version2/src/C/README.txt [new file with mode: 0644]
version2/src/C/Sensor-Arduino_Photon-Cloud.ino [deleted file]
version2/src/others/IR-Sensor/IR-Sensor_Particle-Cloud.ino
version2/src/others/Magnetic-Sensor/Magnetic-Sensor_Particle-Cloud.ino
version2/src/others/RPi/LightsController.ino
version2/src/others/RPi/Makefile
version2/src/others/ino/IR-Sensor/IR-Sensor_Fidelius-Cloud.ino
version2/src/others/ino/IR-Sensor/IR-Sensor_Particle-Cloud.ino
version2/src/others/ino/Magnetic-Sensor/Magnetic-Sensor_Fidelius-Cloud.ino [new file with mode: 0644]
version2/src/others/ino/Magnetic-Sensor/Magnetic-Sensor_Particle-Cloud.ino [new file with mode: 0644]
version2/src/others/ino/Temp-Sensor/Temp-Sensor_Fidelius-Cloud.ino
version2/src/others/ino/Temp-Sensor/Temp-Sensor_Particle-Cloud.ino

index ab535de291b82b21250bd2808eda451d791c2b00..ba09b7a11bb58eb866585ddd16349bed0ef71231 100644 (file)
@@ -37,6 +37,23 @@ flash6:
 flash7:
        particle flash IoT-7 photon_firmware*.bin
 
+flash8:
+       particle flash IoT-8 photon_firmware*.bin
+
+flash9:
+       particle flash IoT-9 photon_firmware*.bin
+
+flash10:
+       particle flash IoT-10 photon_firmware*.bin
+
+flash11:
+       particle flash IoT-11 photon_firmware*.bin
+
+flash12:
+       particle flash IoT-12 photon_firmware*.bin
+
+flash13:
+       particle flash IoT-13 photon_firmware*.bin
 
 PHONY += clean
 clean:
diff --git a/version2/src/C/README.txt b/version2/src/C/README.txt
new file mode 100644 (file)
index 0000000..505a6ae
--- /dev/null
@@ -0,0 +1,6 @@
+
+- This is the codebase for Fidelius cloud application that we build on Particle (PHOTON) devices.
+
+- We can replace the .ino file with any of .ino files for Fidelius cloud from the iotcloud/version2/src/others/ino directory.
+
+- INO files that only need Particle API's can be compiled separately and it does not have to be together with this Fidelius API source code, unless it needs some other library, e.g. DHT library.
diff --git a/version2/src/C/Sensor-Arduino_Photon-Cloud.ino b/version2/src/C/Sensor-Arduino_Photon-Cloud.ino
deleted file mode 100644 (file)
index 742ccc8..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-#include "Table.h"
-#include "IoTString.h"
-#include "TimingSingleton.h"
-#include "TransactionStatus.h"
-#include "DHT.h"
-
-SYSTEM_MODE(SEMI_AUTOMATIC)
-SYSTEM_THREAD(ENABLED)
-
-// System defines
-// Arduino
-#define DHTPIN                         2               // Data pin
-#define PWRPIN                         D5              // Power pin
-#define ERRPIN                         D7              // Error pin
-#define DHTTYPE                        DHT22   // DHT 22  (AM2302)
-// IoTCloud
-#define SLEEP_TIME                     15              // Sleep time in seconds
-#define RETRY_SLEEP_TIME       5               // 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);
-
-// Globals
-// IoTCloud
-bool foundError;
-MyVector<TransactionStatus *> * transStatusList;
-char keyBuffer[80];
-char dataBuffer[80];
-Table *t1;
-int64_t machineId;
-
-void setup() {
-       // TODO: 
-       // 1) This code reads from the sensor and publishes
-       //    the results on the cloud.
-       // 2) If you want to use the Serial library, 
-       //    please install "screen" on your machine and run
-       //    it on the serial port right after flashing the
-       //    firmware onto the Particle board.
-       //    e.g. sudo screen /dev/ttyACM0
-
-       // We use one I/O pin to power the sensor so
-       // that we can make it go to sleep when we go into
-       // deep sleep.
-       
-       // TODO: Profiling!
-       //Serial.begin();
-       //Serial.print("Time begin setup: ");
-       //Serial.println(micros());
-       // Turn on sensor
-       pinMode(PWRPIN, OUTPUT);
-       digitalWrite(PWRPIN, HIGH);
-       // Arduino DHT
-       dht.begin();
-       // 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
-       // 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);
-
-       // 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
-       //for (int i=0; i<6; i++) {
-       //      Serial.printf("%02x%s", mac[i], i != 5 ? ":" : "");
-       //}
-       //Serial.println();
-       // Prepare machine ID
-       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
-       
-    // TODO: Profiling 
-       //Serial.print("Time end setup: ");
-       //Serial.println(micros());
-}
-
-void loop() {
-       // Wait until sensor is ready
-       delay(1500);
-    // TODO: Profiling
-       //Serial.print("Time begin loop: ");
-       //Serial.println(micros());
-       // Read humidity
-       float humid = dht.readHumidity();
-       // Read temperature as Fahrenheit
-       float tempF = dht.readTemperature(true);
-       // Check if any reads failed and exit early (to try again).
-       if (isnan(humid) || isnan(tempF))
-               return;
-
-       // Machine ID
-       sprintf(keyBuffer, "%04x", machineId);
-       // Humidity + Temperature
-       sprintf(dataBuffer, "%0.2f-%0.2f", humid, tempF);
-
-       // Publish on PHOTON's cloud
-       Particle.publish(keyBuffer, dataBuffer);
-       delay(1000);
-
-       // Turn off sensor
-       digitalWrite(PWRPIN, LOW);
-
-       // TODO: Profiling
-       //Serial.print("Time end loop: ");
-       //Serial.println(micros());
-       //while(true) { }
-       System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME);
-}
-
index 1e74a7a303ac1911845026a01d33f73fe05994b7..c51c30f23a557ecf5c6dd7e62ccab0d4f9781dd5 100644 (file)
@@ -36,6 +36,11 @@ void loop() {
        sprintf(dataBuffer, "%s -> motion-detected", Time.timeStr().c_str());
        Particle.publish(keyBuffer, dataBuffer);
        delay(1000);
+       
+       // TODO: Profiling
+       //String strTime(micros());
+       //Particle.publish("Time motion sensor", strTime.c_str());
+       //while(true);
 
        System.sleep(SLEEP_MODE_DEEP, 0);
 }
index 3f4c9c8d7d96a027e56f2b4b0ffda1561c5dd208..855c567457b3aa742b4def3e42ad9024896ba736 100644 (file)
@@ -37,5 +37,10 @@ void loop() {
        
        delay(1000);
        
+       // TODO: Profiling
+       //String strTime(micros());
+       //Particle.publish("Time motion sensor", strTime.c_str());
+       //while(true);
+       
        System.sleep(SLEEP_MODE_DEEP, 0);
 }
index b47d15d2cf69daa30085192edbd214fda8333cd6..a5fccefe65a8cc3004e409078ee9e7760e6ca6ac 100644 (file)
@@ -43,8 +43,15 @@ void setup()
        llb2->init();
 
        pinMode(led1, OUTPUT);
-    Particle.function("lifx1",lifx1Toggle);
-    Particle.function("lifx2",lifx2Toggle);
+       // Argument needed ("on" or "off") for these functions
+    //Particle.function("lifx1",lifxb1Toggle);
+    //Particle.function("lifx2",lifxb2Toggle);
+
+    // Argument not needed for these functions
+    Particle.function("turnOn_1",turnOnLiFX_1);
+    Particle.function("turnOff_1",turnOffLiFX_1);
+    Particle.function("turnOn_2",turnOnLiFX_2);
+    Particle.function("turnOff_2",turnOffLiFX_2);
 }
 
 
@@ -84,3 +91,32 @@ int lifx2Toggle(String command) {
         return -1;
     }
 }
+
+
+int turnOnLiFX_1(String command) {
+
+       llb1->turnOn();
+       return 1;
+}
+
+
+int turnOffLiFX_1(String command) {
+
+       llb1->turnOff();
+       return 1;
+}
+
+
+int turnOnLiFX_2(String command) {
+
+       llb2->turnOn();
+       return 1;
+}
+
+
+int turnOffLiFX_2(String command) {
+
+       llb2->turnOff();
+       return 1;
+}
+
index 948d8e1a64c44da78201352df4b3f223a3b1c953..b5d2c537c1228a4bdf75d5c57bd764674b65d438 100644 (file)
@@ -16,8 +16,6 @@ compile-c:
 compile:
        rm -f *.bin
        particle compile raspberry-pi
-       #particle compile photon
-       
        
 flash:
        particle flash Pi-1 raspberry-pi*.bin
index 84831d0f6e875a23b199557f74687b33576d8881..cf27477a216c42c3e85159431a8224fe3fc3182e 100644 (file)
@@ -29,6 +29,7 @@ char keyBuffer[80];
 char dataBuffer[80];
 Table *t1;
 int64_t machineId;
+String wakeupTime;
 
 // Setting up pins for input
 void setup() {
@@ -46,10 +47,11 @@ void setup() {
        //    firmware onto the Particle board.
        //    e.g. sudo screen /dev/ttyACM0
 
+       // Record the time when waking up!
+       wakeupTime = Time.timeStr();
+
        // TODO: Profiling!
        //Serial.begin();
-       //Serial.print("Time begin setup: ");
-       //Serial.println(micros());
 
        // Connect only to WiFi
        WiFi.on();
@@ -88,8 +90,8 @@ void loop() {
        // Machine ID
        sprintf(keyBuffer, "ir%04x", machineId);
        IoTString * iKey = new IoTString(keyBuffer);
-       // Do updates for the humidity
-       sprintf(dataBuffer, "motion-detected");
+       // Do updates for the motion detection
+       sprintf(dataBuffer, "%s -> motion-detected", wakeupTime.c_str());
        IoTString * iValue = new IoTString(dataBuffer);
 
        // Check and create a new key if it isn't created yet
@@ -99,8 +101,9 @@ void loop() {
        transStatusList->add(t1->commitTransaction());
 
        // TODO: Profiling
-       //Serial.print("Time end loop: ");
+       //Serial.print("Elapsed time: ");
        //Serial.println(micros());
-       //while(true) { }
+       //while(true);
+       
        System.sleep(SLEEP_MODE_DEEP, 0);
 }
index c3be4ab5606c0dbf7b8e695a02b49a0ea472651b..c51c30f23a557ecf5c6dd7e62ccab0d4f9781dd5 100644 (file)
@@ -8,10 +8,6 @@
 //
 // Based on tutorial: http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/
 
-SYSTEM_MODE(SEMI_AUTOMATIC)
-SYSTEM_THREAD(ENABLED)
-
-int pirValue; // Place to store read PIR Value
 int64_t machineId;
 // Key and data
 char keyBuffer[80];
@@ -37,9 +33,14 @@ void loop() {
        // Machine ID
        sprintf(keyBuffer, "%04x", machineId);
        // Motion detection
-       sprintf(dataBuffer, "motion-detected");
+       sprintf(dataBuffer, "%s -> motion-detected", Time.timeStr().c_str());
        Particle.publish(keyBuffer, dataBuffer);
        delay(1000);
+       
+       // TODO: Profiling
+       //String strTime(micros());
+       //Particle.publish("Time motion sensor", strTime.c_str());
+       //while(true);
 
        System.sleep(SLEEP_MODE_DEEP, 0);
 }
diff --git a/version2/src/others/ino/Magnetic-Sensor/Magnetic-Sensor_Fidelius-Cloud.ino b/version2/src/others/ino/Magnetic-Sensor/Magnetic-Sensor_Fidelius-Cloud.ino
new file mode 100644 (file)
index 0000000..e9afd62
--- /dev/null
@@ -0,0 +1,106 @@
+// ------------------------------------------------
+// Controlling HC-SR501 through Particle Cloud
+// @author Rahmadi Trimananda - UC Irvine
+// ------------------------------------------------
+// HC-SR501 Motion Detector
+// Basically, this simple code detects motion and send the occurrences to the cloud
+// We use the WKP port (port A7) to wake up the device when there is motion
+//
+// Based on tutorial: http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/
+#include "Table.h"
+#include "IoTString.h"
+#include "TimingSingleton.h"
+#include "TransactionStatus.h"
+
+// IoTCloud
+#define SLEEP_TIME                     15              // Sleep time in seconds
+#define RETRY_SLEEP_TIME       5               // 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
+
+SYSTEM_MODE(SEMI_AUTOMATIC)
+SYSTEM_THREAD(ENABLED)
+
+// Globals
+// IoTCloud
+bool foundError;
+MyVector<TransactionStatus *> * transStatusList;
+char keyBuffer[80];
+char dataBuffer[80];
+Table *t1;
+int64_t machineId;
+String wakeupTime;
+
+// Setting up pins for input
+void setup() {
+       // TODO: 
+       // 1) Before running PHOTON's with this firmware,
+       //    please go to the master branch and run Init.C
+       //    in iotcloud/version2/src/C to initialize 
+       //    a table on the cloud side.
+       //    If you want to read the committed keys and values 
+       //    on the cloud, then you can use Read.java in
+       //    iotcloud/version2/src/java/simple_test.
+       // 2) If you want to use the Serial library, 
+       //    please install "screen" on your machine and run
+       //    it on the serial port right after flashing the
+       //    firmware onto the Particle board.
+       //    e.g. sudo screen /dev/ttyACM0
+       
+       // Record the time when waking up!
+       wakeupTime = Time.timeStr();
+
+       // TODO: Profiling!
+       //Serial.begin();
+
+       // Connect only to WiFi
+       WiFi.on();
+       WiFi.connect();
+       if (!waitFor(WiFi.ready, RETRY_TIME))
+               System.sleep(SLEEP_MODE_DEEP, RETRY_SLEEP_TIME);
+       while(!WiFi.localIP()); // Wait for valid IP
+    // Add delay if needed (for the humidity sensor we need ~2s delay)
+    // Delays are in millis but micros() returns microsecond time
+       if (micros() < CONNECTION_DELAY)
+               delay((CONNECTION_DELAY - micros())/1000);
+
+       // Get the MAC address
+       byte mac[6];
+       WiFi.macAddress(mac);
+       // Prepare machine ID
+       int64_t mac4 = (int64_t) mac[4];
+       int64_t mac5 = (int64_t) mac[5];
+       machineId = (mac4 * 256) +  mac5;
+       
+       IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
+       IoTString *password = new IoTString("reallysecret");
+       
+       t1 = new Table(baseurl, password, machineId, -1);
+       t1->rebuild();
+
+       baseurl->releaseRef();
+       password->releaseRef();
+}
+
+void loop() {
+
+       // Machine ID
+       sprintf(keyBuffer, "mag%04x", machineId);
+       IoTString * iKey = new IoTString(keyBuffer);
+       // Do updates for the magnetic action
+       sprintf(dataBuffer, "%s -> closing-door-detected", wakeupTime.c_str());
+       IoTString * iValue = new IoTString(dataBuffer);
+
+       // Check and create a new key if it isn't created yet
+       t1->createNewKey(iKey, machineId);
+       t1->startTransaction();
+       t1->put(iKey, iValue);
+       transStatusList->add(t1->commitTransaction());
+
+       // TODO: Profiling
+       //Serial.print("Elapsed time: ");
+       //Serial.println(micros());
+       //while(true);
+
+       System.sleep(SLEEP_MODE_DEEP, 0);
+}
diff --git a/version2/src/others/ino/Magnetic-Sensor/Magnetic-Sensor_Particle-Cloud.ino b/version2/src/others/ino/Magnetic-Sensor/Magnetic-Sensor_Particle-Cloud.ino
new file mode 100644 (file)
index 0000000..855c567
--- /dev/null
@@ -0,0 +1,46 @@
+// ------------------------------------------------
+// Controlling Arduino EK1656 through cloud
+// @author Rahmadi Trimananda - UC Irvine
+// ------------------------------------------------
+// Gikfun MC-38 - Arduino EK1656 (magnetic sensor)
+// Basically, this simple code detects sensor opening and send the occurrences to the cloud
+// We use the WKP port (port A7) to wake up the device when there is motion
+//
+
+int64_t machineId;
+// Key and data
+char keyBuffer[80];
+char dataBuffer[80];
+
+// Setting up pins for input
+void setup() {
+
+       // Get the MAC address
+       byte mac[6];
+       WiFi.macAddress(mac);
+       // Prepare machine ID
+       int64_t mac4 = (int64_t) mac[4];
+       int64_t mac5 = (int64_t) mac[5];
+       machineId = (mac4 * 256) +  mac5;
+}
+
+void loop() {
+
+       // Basically delay to give time to send updates to Particle cloud.
+       // If we do less than this then it would fail publishing.
+       delay(2000);    
+       // Machine ID
+       sprintf(keyBuffer, "%04x", machineId);
+       // Motion detection
+       sprintf(dataBuffer, "%s -> closing-door-detected", Time.timeStr().c_str());
+       Particle.publish(keyBuffer, dataBuffer);
+       
+       delay(1000);
+       
+       // TODO: Profiling
+       //String strTime(micros());
+       //Particle.publish("Time motion sensor", strTime.c_str());
+       //while(true);
+       
+       System.sleep(SLEEP_MODE_DEEP, 0);
+}
index c35a2bb8c692e1f96bd6038fe6ed88363a51e69a..3e4441e37d56c4fb63316559585e258952ca61c7 100644 (file)
@@ -63,9 +63,9 @@ void setup() {
        // Wait for a maximum amount of time - sleep if WiFi is not connected
        // Wake up and try again afterwards
        // 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);
+       //Particle.connect();
+       //if (!waitFor(Particle.connected, RETRY_TIME))
+       //      System.sleep(SLEEP_MODE_DEEP, RETRY_SLEEP_TIME);
 
        // Connect only to WiFi
        WiFi.on();
@@ -129,6 +129,9 @@ void loop() {
        // Check if any reads failed and exit early (to try again).
        if (isnan(humid) || isnan(tempF))
                return;
+       
+       // TODO: Update values separately to different keys
+       /*
        // Humidity
        // Key
        sprintf(keyBuffer, "h%04x", machineId);
@@ -162,12 +165,13 @@ void loop() {
        iValueHumid->releaseRef();
        iKeyTempF->releaseRef();
        iValueTempF->releaseRef();
+       */
        
        // TODO: Collapse temperature and humidity into one key
-/*     sprintf(keyBuffer, "%04x", machineId);
+       sprintf(keyBuffer, "humtemp%04x", machineId);
        IoTString * iKey = new IoTString(keyBuffer);
        // Do updates for the temperature
-       sprintf(dataBuffer, "%0.2f%0.2f", humid, tempF);
+       sprintf(dataBuffer, "%0.2f-%0.2f", humid, tempF);
        IoTString * iValue = new IoTString(dataBuffer);
        
        t1->createNewKey(iKey, machineId);
@@ -176,7 +180,7 @@ void loop() {
        transStatusList->add(t1->commitTransaction());
        
        iKey->releaseRef();
-       iValue->releaseRef();*/
+       iValue->releaseRef();
        
        /*for (uint i = 0; i < transStatusList->size(); i++) {
                TransactionStatus * status = transStatusList->get(i);
@@ -191,9 +195,10 @@ void loop() {
        digitalWrite(PWRPIN, LOW);
 
        // TODO: Profiling
-       //Serial.print("Time end loop: ");
+       //Serial.print("Elapsed time: ");
        //Serial.println(micros());
-       //while(true) { }
+       //while(true);
+       
        System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME);
 }
 
index 9674a47b44f248023fda1b755a05fff4c93fe1dd..ce216c44f4b91a2cf96082e3962656317bddde7d 100644 (file)
@@ -91,7 +91,7 @@ void loop() {
                return;
 
        // Machine ID
-       sprintf(keyBuffer, "%04x", machineId);
+       sprintf(keyBuffer, "humtemp%04x", machineId);
        // Humidity + Temperature
        sprintf(dataBuffer, "%0.2f-%0.2f", humid, tempF);