This is the code for the monitoring center

Dependencies:   beep mbed

Fork of Accel_Mag_Gyro_SensorStream_K64F_AGM01_M2X by AT&T Developer Summit Hackathon 2016

Files at this revision

API Documentation at this revision

Comitter:
natschwa
Date:
Mon Mar 19 17:24:39 2018 +0000
Parent:
1:5e587e213940
Commit message:
Finished

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
FXAS21002.lib Show diff for this revision Revisions of this file
FXOS8700.lib Show diff for this revision Revisions of this file
M2XStreamClient.lib Show diff for this revision Revisions of this file
beep.lib Show annotated file Show diff for this revision Revisions of this file
jsonlite.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
diff -r 5e587e213940 -r d0f21ffe5e3d EthernetInterface.lib
--- a/EthernetInterface.lib	Tue Apr 25 23:41:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r 5e587e213940 -r d0f21ffe5e3d FXAS21002.lib
--- a/FXAS21002.lib	Tue Apr 25 23:41:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/AswinSivakumar/code/FXAS21002/#c9ebfc81e8b6
diff -r 5e587e213940 -r d0f21ffe5e3d FXOS8700.lib
--- a/FXOS8700.lib	Tue Apr 25 23:41:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/AswinSivakumar/code/FXOS8700/#df2167370234
diff -r 5e587e213940 -r d0f21ffe5e3d M2XStreamClient.lib
--- a/M2XStreamClient.lib	Tue Apr 25 23:41:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/teams/ATT-M2X-team/code/M2XStreamClient/#2610823f7f2e
diff -r 5e587e213940 -r d0f21ffe5e3d beep.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Mon Mar 19 17:24:39 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dreschpe/code/beep/#d8e14429a95f
diff -r 5e587e213940 -r d0f21ffe5e3d jsonlite.lib
--- a/jsonlite.lib	Tue Apr 25 23:41:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/citrusbyte/code/jsonlite/#807034181e02
diff -r 5e587e213940 -r d0f21ffe5e3d main.cpp
--- a/main.cpp	Tue Apr 25 23:41:37 2017 +0000
+++ b/main.cpp	Mon Mar 19 17:24:39 2018 +0000
@@ -1,103 +1,129 @@
-/*
- * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2017 NXP
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * o Redistributions of source code must retain the above copyright notice, this list
- *   of conditions and the following disclaimer.
- *
- * o Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- * o Neither the name of the copyright holder nor the names of its
- *   contributors may be used to endorse or promote products derived from this
- *   software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "FXAS21002.h"
-#include "FXOS8700.h"  
+//Monitoring Center
+
 #include "mbed.h"
-#include "M2XStreamClient.h"
-#include "EthernetInterface.h"
+
+#define RX_  PTC14
+#define TX_  PTC15
 
-// Initialize Serial port
-Serial pc(USBTX, USBRX);
-
-// Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
-FXOS8700 accel(D14,D15);
-FXOS8700 mag(D14,D15);
-FXAS21002 gyro(D14,D15);
+//Delay declared in seconds
+/*GPIO declaration*/
+DigitalOut Red(LED1);
+DigitalOut Green(LED2);
+DigitalOut Blue(LED3);
 
-// Set Sensor Stream details
-char deviceId[] = "8b34bc421abf15b7ec6471fa19513a98"; // Device you want to push to
-char streamAcc[] = "acc_rms"; // Stream you want to push to
-char streamMag[] = "mag_rms"; // Stream you want to push to
-char streamGyr[] = "gyr_rms"; // Stream you want to push to
-char m2xKey[] = "737018ea33de7760ab346c85ae2d9d27"; // Your M2X API Key or Master API Key
+DigitalIn sw2(SW2);
+
+//DigitalOut buzzer(D2);
+PwmOut buzzer(D3);
 
-int main()
-{
-    // Intialize Ethernet connection
-EthernetInterface eth;
-eth.init();
-eth.connect();
-printf("Success. Connected!. Device IP Address is %s\r\n", eth.getIPAddress());
+int on = 1, off = 0; 
 
- // Initialize the M2X client
-Client client;
-M2XStreamClient m2xClient(&client, m2xKey);
-int ret;
+Serial BlueTooth(TX_, RX_);  // bluetooth serial port
+//Serial BlueTooth(USBTX, USBRX); // USB serial port
 
 
-    // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
-    accel.accel_config();
-    mag.mag_config();
-    gyro.gyro_config();
+int main(void)
+{
 
-    float accel_data[3]; float accel_rms=0.0;
-    float mag_data[3];   float mag_rms=0.0;
-    float gyro_data[3];  float gyro_rms=0.0;
-       
-    printf("Begin Data Acquisition from FXOS8700 and FXAS21002....\r\n\r\n");
-    wait(0.5);
+    int pause = 3000;
+    int buzz_on = 0;
+    int reset_flg = 1;
     
-    while(1)
-    {
-      accel.acquire_accel_data_g(accel_data);
-      accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
-      printf("%4.2f,\t%4.2f,\t%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]);
-      wait(0.01);
+    /*LedsOFF (active low)*/
+    Red = 1;
+    Green = 1;
+    Blue = 1;
       
-      mag.acquire_mag_data_uT(mag_data);
-      printf("%4.2f,\t%4.2f,\t%4.2f,\t",mag_data[0],mag_data[1],mag_data[2]);
-      mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
-      wait(0.01);
-      
-      gyro.acquire_gyro_data_dps(gyro_data);
-      printf("%4.2f,\t%4.2f,\t%4.2f\r\n",gyro_data[0],gyro_data[1],gyro_data[2]);
-      gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
-      wait(0.01);
-      
-      ret = m2xClient.updateStreamValue(deviceId, streamAcc, accel_rms);
-      printf("send() returned %d\r\n", ret);
-      ret = m2xClient.updateStreamValue(deviceId, streamMag, mag_rms);
-      printf("send() returned %d\r\n", ret);
-      ret = m2xClient.updateStreamValue(deviceId, streamGyr, gyro_rms);
-      printf("send() returned %d\r\n", ret);
-      wait(1);
+    BlueTooth.baud(9600);
+    printf("Trying to Connect to Master\n\r");
+    buzzer.write(0.0);
+    
+    while (!BlueTooth.readable()){   // read data from the bluetooth serial port   
+        printf("Trying to c\n\r");
+        //wait(0.1);
+    }
+    while (BlueTooth.getc() != 'Z'){   // searching for starting byte from master
+        printf("Searching for Z\n\r");    
+    }
+    
+    //data[0] = BlueTooth.getc();
+    printf("Connected\n\rStarting byte= %c\n\r", BlueTooth.getc() );
+   
+    printf("Sending Ack\n\r");
+    
+    while(pause--){ // sending master acknowledgment 
+        BlueTooth.putc('X');
     }
-      
-}
\ No newline at end of file
+    
+    printf("Ack Recived: System Ready\n\r"); // turn LGB LED blue upon Ack recived
+    Red = 1;
+    Green = 1;
+    Blue = 0;
+    
+    while (true)  
+    {
+     
+        buzzer.write(0.0);
+        if(BlueTooth.readable()) // read data from the bluetooth serial port    
+        {   
+            while(BlueTooth.getc() == 'A'){   // turn LGB LED yellow when Alert recived
+                printf("Alert Recieved\n\r");
+                reset_flg = 1;
+                Blue = 1;
+                Red = 0;
+                Green = 0;
+                wait(.5);
+                Red = 1;
+                Green=1;
+                wait(0.5);
+            }
+            buzzer.write(0.0);
+            while(BlueTooth.getc() == 'C') // turn LGB LED green upon correct password
+            {
+                printf("Correct password\n\r");
+                Blue = 1;
+                Red = 1;
+                Green = 0;    
+            }
+            
+            while(BlueTooth.getc() == 'G')
+            {
+                printf("Alam TimeOut\n\r"); 
+            }
+            
+            buzz_on=1;
+            while((BlueTooth.getc() == 'F') && reset_flg) // turn LGB LED Red, sound buzzer
+            {
+                printf("Incorrect Password\n\r");
+                
+                Blue = 1;
+                Red = 0;
+                Green = 1;
+                
+                if(buzz_on)
+                {
+                    printf("Buzzer On\n\r");
+                    buzzer.period(1.0/8.0);
+                    buzzer.write(.5);
+                    buzz_on = 0;    
+                }
+                if(sw2==0) // turn off buzzer when sw2 pressed
+                {
+                    printf("Alarm Disabled\n\r");
+                    buzzer.write(0.0); 
+                    reset_flg = 0;
+                    wait(2);
+                }   
+            }//end while
+            
+            
+            //reset_flg = 1;
+            printf("Alarm Off\n\r");    
+            buzzer.write(0.0);
+            Blue = 1;        
+            Red = 1;
+            Green = 1;     
+        }  
+          
+    }//end while(true)      
+}
diff -r 5e587e213940 -r d0f21ffe5e3d mbed-rtos.lib
--- a/mbed-rtos.lib	Tue Apr 25 23:41:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#c825593ece39