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:
10:c8a6f2822068
Parent:
8:1b4e84f4c451
Child:
11:769f2b28b236
--- a/main.cpp	Sun Sep 16 20:35:27 2012 +0000
+++ b/main.cpp	Tue Sep 18 15:20:28 2012 +0000
@@ -31,7 +31,7 @@
 #include "core/fwk.h"
 #include "mbed.h"
 #include "rtos.h"
-#include "VodafoneK3770.h"
+#include "VodafoneUSBModem.h"
 
 #include <string>
 
@@ -44,24 +44,28 @@
 DigitalOut  led3(LED3);                     // LED 3 is use to indicate if the relay is being switched on to open the door
 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, this works in reverse
+DigitalIn   doorProximitySwitch(p6);       // create a digital pin object to sense door position proximity switch, this works in reverse
                                             // the switch senses positive when the door is closed - need to be sure when it's closed! :-)
 bool        openTheDoor = false;            // create a state variable which is set to indicate the mbed should open the door
                                             // this variable will be used hold the latch open until it knows the door has been open.
+int read_digital(void) {
+    DigitalIn mydigital(p6);
+    return(mydigital.read());
+}
 
 void test(void const*) {
-  VodafoneK3770 connectionManager;                     // create a connection manager object
+  VodafoneUSBModem connectionManager;                     // create a connection manager object
 
   DBG("Hello world and Vodafone K3770 test program!");
     
   connectionManager.sendSM(MY_PHONE_NUMBER, "Hello from mbed door controller:)");
 
+  char num[17];                                           // create a buffer to hold the telephone number in
+  char msg[160];                                          // create a buffer to hold the text message in
+  size_t count;
+
   while(true)
   {
-    char num[17];                                           // create a buffer to hold the telephone number in
-    char msg[160];                                          // create a buffer to hold the text message in
-    size_t count;
-    
     
     // if this state variable has been set I need to keep the doorContactor on until the door is open
     if ((openTheDoor) || (doorProximitySwitch.read() == 0))
@@ -74,7 +78,8 @@
     }
     
     // check the state of the door and switch the LED light to 'ON' for door open and 'OFF' for door closed.
-    if (doorProximitySwitch.read() == 0)
+    //if (doorProximitySwitch.read() == 0)
+    if (read_digital() == 0)
     {
         DBG("The door proximity switch is: %d so I think it's open", doorProximitySwitch.read() );
         led1 = 1;
@@ -91,19 +96,20 @@
     if(ret)
     {
       WARN("getSMCount returned %d", ret);
-      Thread::wait(3000);
+      Thread::wait(125);
       continue;
     }
-    
+        
+    DBG("The SMS count is now at: %d for this modem", count);
     if( count > 0)                                          // if there are messages in the mailbox start pulling them off the queue
     {
       DBG("%d SMS to read", count);
-      ret = connectionManager.getSM(num, msg, 64);
+      ret = connectionManager.getSM(num, msg, 160);
     
       if(ret)
       {
         WARN("getSM returned %d", ret);
-        Thread::wait(3000);
+        Thread::wait(125);
         continue;
       }