--- /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);
+
+ System.sleep(SLEEP_MODE_DEEP, 0);
+}
--- /dev/null
+include common.mk
+
+all: compile
+
+# To run Particle, we need to install Particle CLI
+# Please see:
+# https://docs.particle.io/guide/getting-started/connect/photon/#install-the-particle-cli
+monitor:
+ sudo chmod 666 /dev/ttyACM0
+ particle serial monitor
+
+compile:
+ rm -f *.bin
+ particle compile photon
+
+flash0:
+ particle flash IoT-0 photon*.bin
+
+flash1:
+ particle flash IoT-1 photon*.bin
+
+flash2:
+ particle flash IoT-2 photon*.bin
+
+PHONY += clean
+clean:
+ rm -f *.bin
+
+PHONY += mrclean
+mrclean: clean
+ rm -rf ../docs
+
+tabbing:
+ uncrustify -c C.cfg --no-backup *.cpp
+ uncrustify -c C.cfg --no-backup *.h
+
+wc:
+ wc *.cpp *.h
+
+.PHONY: $(PHONY)
--- /dev/null
+# A few common Makefile items
+
+CC := gcc
+CXX := g++
+
+UNAME := $(shell uname)
+
+LIB_NAME := iotcloud
+LIB_SO := lib_$(LIB_NAME).so
+
+CPPFLAGS += -Wall -g -O0
+
+# Mac OSX options
+ifeq ($(UNAME), Darwin)
+CPPFLAGS += -D_XOPEN_SOURCE -DMAC
+endif