Aryan Varma / Mbed 2 deprecated PIRMotionsensor_IBMIoTclient

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Files at this revision

API Documentation at this revision

Comitter:
AryanVarma
Date:
Tue Mar 29 03:46:17 2016 +0000
Parent:
18:94da9de96d54
Commit message:
IoT based security system that detects suspicious movements through a Grove PIR motion sensor and alerts the user on their email if the motion detected is between 7 to 9 times.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 94da9de96d54 -r ee5e5c9573e5 main.cpp
--- a/main.cpp	Wed Aug 12 20:50:56 2015 +0000
+++ b/main.cpp	Tue Mar 29 03:46:17 2016 +0000
@@ -1,28 +1,3 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- *    http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- *   http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *    Sam Danbury - initial implementation
- *    Ian Craggs - refactoring to remove STL and other changes
- *    Sam Grove  - added check for Ethernet cable.
- *    Chris Styles - Added additional menu screen for software revision
- *    James Sutton - Mac fix and extra debug
- *    Ian Craggs - add not authorized messages
- *
- * To do :
- *    Add magnetometer sensor output to IoT data stream
- *
- *******************************************************************************/
-
 #include "LM75B.h"
 #include "MMA7660.h"
 #include "MQTTClient.h"
@@ -35,28 +10,26 @@
 #define __APP_SW_REVISION__ "18"
 
 // Configuration values needed to connect to IBM IoT Cloud
-#define ORG "quickstart"             // For a registered connection, replace with your org
+#define ORG ""             // For a registered connection, replace with your org
 #define ID ""                        // For a registered connection, replace with your id
 #define AUTH_TOKEN ""                // For a registered connection, replace with your auth-token
-#define TYPE DEFAULT_TYPE_NAME       // For a registered connection, replace with your type
+#define TYPE ""       // For a registered connection, replace with your type
 
 #define MQTT_PORT 1883
 #define MQTT_TLS_PORT 8883
 #define IBM_IOT_PORT MQTT_PORT
 
 #define MQTT_MAX_PACKET_SIZE 250
+#include "K64F.h"
+InterruptIn motion(D2);
 
-#if defined(TARGET_UBLOX_C027)
-#warning "Compiling for mbed C027"
-#include "C027.h"
-#elif defined(TARGET_LPC1768)
-#warning "Compiling for mbed LPC1768"
-#include "LPC1768.h"
-#elif defined(TARGET_K64F)
-#warning "Compiling for mbed K64F"
-#include "K64F.h"
-#endif
+int motion_detected = 0;
 
+void irq_handler(void)
+{
+    motion_detected = 1;
+}
+    int cnt = 0;
 
 bool quickstartMode = true;
 char org[11] = ORG;  
@@ -403,11 +376,18 @@
 {
     MQTT::Message message;
     char* pubTopic = "iot-2/evt/status/fmt/json";
-            
+            motion.rise(&irq_handler);
+            if(motion_detected){
+            cnt++;       
+            motion_detected = 0;
+            } 
     char buf[250];
-    sprintf(buf,
-     "{\"d\":{\"myName\":\"IoT mbed\",\"accelX\":%0.4f,\"accelY\":%0.4f,\"accelZ\":%0.4f,\"temp\":%0.4f,\"joystick\":\"%s\",\"potentiometer1\":%0.4f,\"potentiometer2\":%0.4f}}",
-            MMA.x(), MMA.y(), MMA.z(), sensor.temp(), joystickPos, ain1.read(), ain2.read());
+    
+    if(cnt > 7 && cnt<10)
+    {
+        sprintf(buf,"{\"Motion\":\"%s\"}","md");
+    }
+           
     message.qos = MQTT::QOS0;
     message.retained = false;
     message.dup = false;