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 21:7068b39d3006, committed 2012-09-27
- Comitter:
- donatien
- Date:
- Thu Sep 27 14:49:15 2012 +0000
- Parent:
- 20:27f878df6d14
- Parent:
- 18:ad4ae0caf337
- Child:
- 24:e825e2b57d62
- Commit message:
- Fixed ATCommandInterface.cpp
Changed in this revision
--- a/VodafoneUSBModem_bleedingedge.lib Thu Sep 27 13:18:02 2012 +0000 +++ b/VodafoneUSBModem_bleedingedge.lib Thu Sep 27 14:49:15 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#8ad4cb12749d +http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#54ca82a7644c
--- a/VodafoneUSBModem_bleedingedge.lib.orig Thu Sep 27 13:18:02 2012 +0000 +++ b/VodafoneUSBModem_bleedingedge.lib.orig Thu Sep 27 14:49:15 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#c1fd83bd31b4 +http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#8ad4cb12749d
--- a/main.cpp Thu Sep 27 13:18:02 2012 +0000
+++ b/main.cpp Thu Sep 27 14:49:15 2012 +0000
@@ -23,12 +23,12 @@
#define __DEBUG__ 4 //Maximum verbosity
#ifndef __MODULE__
-// #define __MODULE__ "net_voda_k3770_test.cpp"
+#define __MODULE__ "net_voda_k3770_test.cpp"
#endif
#define MY_PHONE_NUMBER "+447717275049"
-#include "core/fwk.h"
+//#include "core/fwk.h"
#include "mbed.h"
#include "rtos.h"
#include "VodafoneUSBModem.h"
@@ -70,7 +70,8 @@
LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN; // an enum to hold the type of bearer established by the connection manager
int rssi = -1000; // a signal strength indicator variable - set to a very default low value.
-
+ int ret = connectionManager.getLinkState(&rssi, ®State, &bearer);
+
// LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_HOME_NETWORK;
// before we do anything we need to make sure we have a connection to a network.
@@ -79,8 +80,8 @@
while(detectRegState)
{
- if(connectionManager.getLinkState(&rssi, ®State, &bearer)==0)
- //if (detectRegState ==1)
+ //if(connectionManager.getLinkState(&rssi, ®State, &bearer)==0)
+ if (detectRegState ==1)
{
if(rssi==-1000)
{
@@ -115,19 +116,14 @@
break;
default:
DBG("regState: ERROR. Failing.");
- break;
+
}
}
Thread::wait(500);
}
-
-
-
-
- connectionManager.sendSM(MY_PHONE_NUMBER, "Hello from mbed door controller:)");
-
-
+ ret = connectionManager.sendSM(MY_PHONE_NUMBER, "Hello from mbed door controller");
+
while(true)
{
@@ -221,7 +217,6 @@
}
Thread::wait(500);
}
-
}
void keepAlive(void const*) {
@@ -242,8 +237,8 @@
//t.attach(tick,1);
DBG_INIT();
DBG_SET_SPEED(115200);
+ Thread testTask(test, NULL, osPriorityNormal, 1024*6);
- Thread testTask(test, NULL, osPriorityNormal, 1024*5);
keepAlive(NULL);
--- a/main.cpp.orig Thu Sep 27 13:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,177 +0,0 @@
-/* net_sms_test.cpp */
-/*
-Copyright (C) 2012 ARM Limited.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-#define __DEBUG__ 4 //Maximum verbosity
-#ifndef __MODULE__
-#define __MODULE__ "main.cpp"
-#endif
-
-#define MY_PHONE_NUMBER "+447717275049"
-
-#include "core/fwk.h"
-#include "mbed.h"
-#include "rtos.h"
-#include "VodafoneUSBModem.h"
-
-#include <string>
-
-extern "C" void HardFault_Handler() {
- error("Hard Fault!\n");
-}
-
-DigitalOut led1(LED1); // LED 1 is used to show the state of the door. ON is door open, and OFF is door close.
-DigitalOut led2(LED2);
-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(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*) {
- 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)
- {
-
- // if this state variable has been set I need to keep the doorContactor on until the door is open
- if ((openTheDoor) || (doorProximitySwitch.read() == 0))
- {
-
- doorContactorRelay = 0; // door must be open now so switch relay off.
- openTheDoor = false; // the door is open now so set it to false.
- led3 = 0; // switch the LED light off to indicate I'm switching the relay off
-
- }
-
- // 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 (read_digital() == 0)
- {
- DBG("The door proximity switch is: %d so I think it's open", doorProximitySwitch.read() );
- led1 = 1;
- }
- else
- {
- DBG("The door proximity switch is: %d so I think it's closed", doorProximitySwitch.read() );
- led1 = 0;
- }
-
-
-
- int ret = connectionManager.getSMCount(&count); // check to see if there is an incoming SMS message
- if(ret)
- {
- WARN("getSMCount returned %d", ret);
- 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, 160);
-
- if(ret)
- {
- WARN("getSM returned %d", ret);
- Thread::wait(125);
- continue;
- }
-
- DBG("The message is from number: %s and the message is: \"%s\"", num, msg);
-
- if (strcmp (msg, "open") ==0)
- {
- DBG("The SMS message indicates I should open the door");
-
- // 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;
- openTheDoor = true; // set the state vairable to let the door contoller know it needs to open the door
- 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");
- connectionManager.sendSM(num, " Wrong password sir... Try 'open' and I'll open! ;-) ");
- }
-
-
-
- }
- Thread::wait(500);
- }
-
-}
-
-void keepAlive(void const*) {
- while(1)
- {
- led2=!led2;
- Thread::wait(500);
- }
-}
-
-void tick()
-{
- led4=!led4;
-}
-
-int main() {
- Ticker t;
- t.attach(tick,1);
- DBG_INIT();
- DBG_SET_SPEED(115200);
-
- Thread testTask(test, NULL, osPriorityNormal, 1024*5);
- keepAlive(NULL);
-
-
- return 0;
-}




