ATT_SMS_System for home security system

Dependencies:   FXOS8700CQ MODSERIAL mbed-rtos mbed

Fork of ATT_Cellular_IOT_Button by Richard Finn

Files at this revision

API Documentation at this revision

Comitter:
natschwa
Date:
Mon Apr 30 17:14:34 2018 +0000
Parent:
72:0afdd141157c
Commit message:
Working ATT_SMS_System

Changed in this revision

cell_modem.cpp Show annotated file Show diff for this revision Revisions of this file
config_me.h Show annotated file 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 annotated file Show diff for this revision Revisions of this file
diff -r 0afdd141157c -r 4a7aa34332b9 cell_modem.cpp
--- a/cell_modem.cpp	Fri Aug 12 21:47:22 2016 +0000
+++ b/cell_modem.cpp	Mon Apr 30 17:14:34 2018 +0000
@@ -311,7 +311,7 @@
     }
     else
     {
-        PRINTF(RED "No response..." DEF "\r\n");
+        PRINTF(RED "No response...!" DEF "\r\n");
     }
     return iStatus;
 }
diff -r 0afdd141157c -r 4a7aa34332b9 config_me.h
--- a/config_me.h	Fri Aug 12 21:47:22 2016 +0000
+++ b/config_me.h	Mon Apr 30 17:14:34 2018 +0000
@@ -9,16 +9,25 @@
 // This is the server's base server name.  Example "www.google.com"
 // Note that when you Fork a FLOW, it will typically assign  either
 // "run-east.att.io" or "run-west.att.io", so be sure to check this.
-static const char * MY_SERVER_NAME       = "run-west.att.io";  //  CHECK ME, might be different
+
+//static const char * MY_SERVER_NAME       = "runm-east.att.io";  //  CHECK ME, might be different
+static const char * MY_SERVER_NAME       = "runm-west.att.io";  //  CHECK ME, might be different
 
 //This is for normal HTTP.  If you want to use TCP to a specific port, change that here:
-static const char * MY_PORT_STR         = "0000";       // CHANGE ME
+
+//static const char * MY_PORT_STR         = "32485";       // CHANGE ME
+static const char * MY_PORT_STR         = "32480";       // CHANGE ME
 
 // Only used if you program void GenerateModemString() to use them and send HTTP
+
 // These are FLOW fields from the Endpoints tab:
-#define FLOW_BASE_PATH                   "/..../in/flow"  // CHANGE ME
+
+//#define FLOW_BASE_PATH                   "/3ab29aa47262a/2297fbb55e65/968eb2cb9b84da9/in/flow"  // CHANGE ME
+#define FLOW_BASE_PATH                   "/b89259fadcfa9/8c7be95398c0/18a1705d518fb39/in/flow"  // CHANGE ME
+
 #define FLOW_INPUT_NAME                 "/buttons"
-// The full URL will be "http://"+MY_SERVER_NAME+":"+MY_PORT_STR+FLOW_PATH_PATH+FLOW_INPUT_NAME
+
+// The full URL will be "http://"+MY_SERVER_NAME+":"+MY_PORT_STR+FLOW_BASE_PATH+FLOW_INPUT_NAME
 
 // Unless you want to use a different protocol, this field should be left as is:
 #define FLOW_URL_TYPE                   " HTTP/1.1\r\nHost: "
diff -r 0afdd141157c -r 4a7aa34332b9 main.cpp
--- a/main.cpp	Fri Aug 12 21:47:22 2016 +0000
+++ b/main.cpp	Mon Apr 30 17:14:34 2018 +0000
@@ -5,6 +5,11 @@
 #include "cell_modem.h"
 #include "hardware.h"
 
+#define RX_  PTB10
+#define TX_  PTB11
+
+Serial BlueTooth(TX_, RX_);  // bluetooth serial port
+
 I2C i2c(PTC11, PTC10);    //SDA, SCL -- define the I2C pins being used
 MODSERIAL pc(USBTX, USBRX, 256, 256); // tx, rx with default tx, rx buffer sizes
 MODSERIAL mdm(PTD3, PTD2, 4096, 4096);
@@ -12,10 +17,18 @@
 DigitalOut led_red(LED_RED);
 DigitalOut led_blue(LED_BLUE);
 
+DigitalOut Green(LED_GREEN);
+DigitalOut Red(LED_RED);
+DigitalOut Blue(LED_BLUE);
+
+//DigitalIn  motion(D8);
+
 // interrupts for buttons
 InterruptIn sw3(SW3);
 InterruptIn sw2(SW2);
 
+//Thread thread1;
+
 // flag - must be volatile as changes within ISR
 // g_ prefix makes it easier to distinguish it as global
 volatile int g_sw3_flag = 0;
@@ -48,15 +61,18 @@
 
 void GenerateModemString(char * modem_string, char btn1, char btn2)
 {
+    
     sprintf(modem_string, "serial:%s button1:%c button2:%c\r\n",
             M2X_DEVICE_SERIAL, btn1, btn2
            );
     
+    
     // HTTP method
-    /*sprintf(modem_string, "GET %s%s?serial=%s&button1=%c&button2=%c %s%s\r\n\r\n",
-        FLOW_BASE_PATH, FLOW_INPUT_NAME, M2X_DEVICE_NAME,
-        btn1, btn2,
-        FLOW_URL_TYPE, MY_SERVER_NAME); */
+    /*
+    sprintf(modem_string, "GET %s%s?serial=%s&button1=%c&button2=%c %s%s\r\n\r\n",FLOW_BASE_PATH,
+    FLOW_INPUT_NAME, M2X_DEVICE_SERIAL, 
+    btn1, btn2, FLOW_URL_TYPE, MY_SERVER_NAME);
+    */
 
 } //GenerateModemString
 
@@ -149,6 +165,23 @@
     }
 }
 
+void sendMsg(char msg,int time);
+void read_BlueTooth(void);
+void LED_Color(char color,int blink);
+
+char Base_ConnectACK ='H';
+char Base_ConnectREQ = 'H';
+char ReconnectREQ = 'R';
+char IntruderAlert = 'I';
+
+bool ReconnectFlg = false; 
+bool readyFlg = true;
+bool BlueFlg = true;
+bool motionFlg = true;
+
+DigitalIn  motion(D10);
+DigitalOut camera(PTB20);
+
 int main()
 {
     //static unsigned ledOnce = 0;
@@ -169,33 +202,130 @@
     sw3.mode(PullNone);
     sw2.mode(PullNone);
 
-    // Set LED to RED until init finishes
-    SetLedColor(0x1); //Red
-    // Initialize the modem
+    LED_Color('P',0); //Red
+    
     PRINTF("\r\n");
-    cell_modem_init();
-    // Set LED BLUE for partial init
-    SetLedColor(0x4); //Blue
+    //cell_modem_init(); // Initialize the modem
 
     // Send and receive data perpetually
-    while(1) {
+    
+    sendMsg(ReconnectREQ,10); // sending master reconnection request
+    while(true) 
+    {
+        if(BlueFlg){
+            read_BlueTooth();
+        }
+        
+        if( ReconnectFlg )
+        {
+            SetLedColor(5); //purple
+            printf("Connected\n\rSending Ack to Master\n\r");
+            
+            sendMsg(Base_ConnectACK,10); // sending master acknowledgment
+            
+            //printf("System Ready\n\r"); // turn LGB LED blue upon Ack recived
+            //LED_Color('B',0);
+            //cell_modem_init(); // Initialize the modem
+            ReconnectFlg = false;
+            readyFlg = true;
+        }
+        
         if (g_sw3_flag) {
             printf("%s\n","SW3 Button");
-            led_green = 0;
+            LED_Color('Y',0);
+            sendMsg(IntruderAlert,10);
             send_button_data('0','1');
-        } else {
-            led_green = 1;
-        }
+            readyFlg = true;
+            //wait(4);
+        } 
 
-        if (g_sw2_flag) {
-            printf("%s\n","SW2 Button");
-            led_blue = 0;
-            send_button_data('1','0');
-        } else {
-            led_blue = 1;
+        if (motionFlg) {
+            if(motion){
+                printf("\n\rMotion Detected\n\r");
+                LED_Color('Y',0);
+                camera = 1;
+                sendMsg(IntruderAlert,100);
+                send_button_data('0','1');
+                camera =0;
+                motionFlg = false;
+                readyFlg = true;
+                wait(4);
+            }
+        }
+        
+        if(readyFlg)
+        {   
+            readyFlg = false;
+            BlueFlg = false;
+            motionFlg =true;
+            LED_Color('B',0);
+            cell_modem_init(); // Initialize the modem
+            LED_Color('G',0);
+            printf("System Ready\n\r");
         }
 
         // put the MCU to sleep until an interrupt wakes it up
-        sleep();
+        //sleep();
+        //printf("\rWaiting...");
     } //forever loop
 }
+
+void read_BlueTooth(){
+
+    if(BlueTooth.readable()) // read data from the bluetooth serial port
+    {
+        //printf("data:%c\n\r",BlueTooth.getc());    
+        if( BlueTooth.getc() == Base_ConnectREQ ){
+            printf("Connecting to Master\n\r");  
+            ReconnectFlg = true; 
+        }         
+    }//end if
+    
+    
+}// read_BlueTooth
+
+void sendMsg(char msg,int time){
+    //printf("send:%c\n\r",msg);
+    while(time--){
+        BlueTooth.putc(msg);
+        wait(0.1);
+    }
+}//end sendMSg
+
+void LED_Color(char color,int blink){
+    
+    /*LedsOFF (active low)*/
+    Red = 1;
+    Green = 1;
+    Blue = 1;
+    if (color == 'C')
+        return;
+    else if(color == 'G')
+        Green = 0;
+    else if(color == 'R')
+        Red = 0;
+    else if(color == 'B')
+        Blue = 0;
+    else if(color == 'Y'){
+        Red = 0;
+        Green = 0;
+    }
+    else if(color == 'P'){
+        Blue = 0;
+        Red = 0;   
+    }
+    else if(color == 'W'){
+        Blue = 0;
+        Red = 0;
+        Green = 0;   
+    }
+    else{} // do nothing
+    
+    if(blink){
+        wait(0.1f);  // wait a small period of time
+        Red = 1;
+        Green = 1;
+        Blue = 1;
+        wait(0.1f);
+     }        
+}//end LED_Color
\ No newline at end of file
diff -r 0afdd141157c -r 4a7aa34332b9 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Apr 30 17:14:34 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/mbed-rtos/#83895f30f8f2