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:
--- /dev/null
+
+- 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.
+++ /dev/null
-#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);
-}
-
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);
}
delay(1000);
+ // TODO: Profiling
+ //String strTime(micros());
+ //Particle.publish("Time motion sensor", strTime.c_str());
+ //while(true);
+
System.sleep(SLEEP_MODE_DEEP, 0);
}
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);
}
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;
+}
+
compile:
rm -f *.bin
particle compile raspberry-pi
- #particle compile photon
-
flash:
particle flash Pi-1 raspberry-pi*.bin
char dataBuffer[80];
Table *t1;
int64_t machineId;
+String wakeupTime;
// Setting up pins for input
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();
// 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
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);
}
//
// 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];
// 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);
}
--- /dev/null
+// ------------------------------------------------
+// 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);
+}
--- /dev/null
+// ------------------------------------------------
+// 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);
+}
// 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();
// 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);
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);
transStatusList->add(t1->commitTransaction());
iKey->releaseRef();
- iValue->releaseRef();*/
+ iValue->releaseRef();
/*for (uint i = 0; i < transStatusList->size(); i++) {
TransactionStatus * status = transStatusList->get(i);
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);
}
return;
// Machine ID
- sprintf(keyBuffer, "%04x", machineId);
+ sprintf(keyBuffer, "humtemp%04x", machineId);
// Humidity + Temperature
sprintf(dataBuffer, "%0.2f-%0.2f", humid, tempF);