1 // ------------------------------------------------
2 // Controlling Arduino EK1656 through cloud
3 // @author Rahmadi Trimananda - UC Irvine
4 // ------------------------------------------------
5 // Gikfun MC-38 - Arduino EK1656 (magnetic sensor)
6 // Basically, this simple code detects sensor opening and send the occurrences to the cloud
7 // We use the WKP port (port A7) to wake up the device when there is motion
15 // Setting up pins for input
18 // Get the MAC address
22 int64_t mac4 = (int64_t) mac[4];
23 int64_t mac5 = (int64_t) mac[5];
24 machineId = (mac4 * 256) + mac5;
29 // Basically delay to give time to send updates to Particle cloud.
30 // If we do less than this then it would fail publishing.
33 sprintf(keyBuffer, "%04x", machineId);
35 sprintf(dataBuffer, "%s -> closing-door-detected", Time.timeStr().c_str());
36 Particle.publish(keyBuffer, dataBuffer);
41 //String strTime(micros());
42 //Particle.publish("Time motion sensor", strTime.c_str());
45 System.sleep(SLEEP_MODE_DEEP, 0);