Door controller and proximity switch detection.

Dependencies:   mbed-rtos mbed VodafoneUSBModem_bleedingedge

This program takes in a digital input - which is a reed switch for a door - and an output to a relay. The door is open with a simple 'text' to the modem on the USB bus (i used k3770 vodafone dongle).

The door will send an alarm message to your nominated numbers at the start of the program if the door is open without a command being sent.

Very simple - and just meant as a demonstration of how to incorporate GSM/3G functionality to a evice.

Revision:
7:316c2dac06a5
Parent:
6:5a892c3d738e
Child:
8:1b4e84f4c451
--- a/main.cpp	Wed Jul 25 10:33:28 2012 +0000
+++ b/main.cpp	Sun Sep 16 10:53:33 2012 +0000
@@ -39,24 +39,25 @@
     error("Hard Fault!\n");
 }
 
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-DigitalOut doorOpen(p5);
+DigitalOut  led1(LED1);
+DigitalOut  led2(LED2);
+DigitalOut  led3(LED3);
+DigitalOut  led4(LED4);
+DigitalOut  doorContactorRelay(p5);        // create a digital pin object to control the door contactor relay
+DigitalIn   doorProximitySwitch(p20);       // create a digital pin object to sense door position proximity switch
 
 
 void test(void const*) {
-  VodafoneK3770 threeg;
+  VodafoneK3770 connectionManager;                     // create a connection manager object
 
   DBG("Hello world and Vodafone K3770 test program!");
     
-  threeg.sendSM(MY_PHONE_NUMBER, "Hello from mbed:)");
+  connectionManager.sendSM(MY_PHONE_NUMBER, "Hello from mbed door controller:)");
 
   while(true)
   {
     char num[17];
-    char msg[64];
+    char msg[160];
     size_t count;
     if (doorOpen)
     {
@@ -64,17 +65,17 @@
         led3=0;
     
     }
-    int ret = threeg.getSMCount(&count);
+    int ret = connectionManager.getSMCount(&count);         // check to see if there is an incoming SMS message
     if(ret)
     {
       WARN("getSMCount returned %d", ret);
       Thread::wait(3000);
       continue;
     }
-    if( count > 0)
+    if( count > 0)                                          // if there are messages in the mailbox start pulling them off the queue
     {
       DBG("%d SMS to read", count);
-      ret = threeg.getSM(num, msg, 64);
+      ret = connectionManager.getSM(num, msg, 64);
       if(ret)
       {
         WARN("getSM returned %d", ret);
@@ -83,24 +84,26 @@
       }
 
       DBG("The message is from number: %s and the message is: \"%s\"", num, msg);
-      if(strcmp(num,"+447836503274")==0) {
-        threeg.sendSM("07836503274","SPAM ALERT! UNKNOWN NUMBER");
-        threeg.sendSM("07836503274","INITIATING DEFENSE MECHANISM: 1 DAY OF RETALIATION SMS");
-        for(int i=0; i<10; i++) {
-            threeg.sendSM("07836503274","ANTI-SPAM SMS PUNISHMENT. DON'T SPAM THE DOOR!!");
-            Thread:wait(10000);
-        }
-      }
       
       if (strcmp (msg, "open") ==0) {
         DBG("The SMS message indicates I should open the door");
-        // do something to open the door
-        doorOpen = 1;
-        led3 = 1;
-        threeg.sendSM(num, " Door open sir... Welcome home! ");
+        
+        // check the door is not already open if it is do nothing and send a warning back to the sender
+        // for this door the switch 'true' then its closed - we have to have an active signal to show it's securely closed
+        if ( doorProximitySwitch.read() == 0)
+        {
+            DBG("The door is already open - so I'll do nothing");
+            connectionManager.sendsm(num, " WARNING - The door is already open sir! ");
+        }
+        else
+        {
+            doorContactorRelay = 1;
+            led3 = 1;
+            DBG("The relay has been activated to open the door");
+            connectionManager.sendsm(num, " Door open sir... Welcome home! " );
       } else {
         DBG("The SMS message is not recognized");
-        threeg.sendSM(num, " Wrong password sir... Try 'open' and I'll open! ;-) ");
+        connectionManager.sendSM(num, " Wrong password sir... Try 'open' and I'll open! ;-) ");
       }