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.

Committer:
nherriot
Date:
Tue May 15 16:19:09 2012 +0000
Revision:
2:bcc9256ecaab
Parent:
1:3c9d0c9dffa4
Child:
3:0a8eebcb0acf
trying out door opener code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nherriot 0:5136cdfaebd0 1 /* net_sms_test.cpp */
nherriot 0:5136cdfaebd0 2 /*
nherriot 0:5136cdfaebd0 3 Copyright (C) 2012 ARM Limited.
nherriot 0:5136cdfaebd0 4
nherriot 0:5136cdfaebd0 5 Permission is hereby granted, free of charge, to any person obtaining a copy of
nherriot 0:5136cdfaebd0 6 this software and associated documentation files (the "Software"), to deal in
nherriot 0:5136cdfaebd0 7 the Software without restriction, including without limitation the rights to
nherriot 0:5136cdfaebd0 8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
nherriot 0:5136cdfaebd0 9 of the Software, and to permit persons to whom the Software is furnished to do
nherriot 0:5136cdfaebd0 10 so, subject to the following conditions:
nherriot 0:5136cdfaebd0 11
nherriot 0:5136cdfaebd0 12 The above copyright notice and this permission notice shall be included in all
nherriot 0:5136cdfaebd0 13 copies or substantial portions of the Software.
nherriot 0:5136cdfaebd0 14
nherriot 0:5136cdfaebd0 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
nherriot 0:5136cdfaebd0 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
nherriot 0:5136cdfaebd0 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
nherriot 0:5136cdfaebd0 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
nherriot 0:5136cdfaebd0 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nherriot 0:5136cdfaebd0 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
nherriot 0:5136cdfaebd0 21 SOFTWARE.
nherriot 0:5136cdfaebd0 22 */
nherriot 0:5136cdfaebd0 23
nherriot 0:5136cdfaebd0 24 #define __DEBUG__ 4 //Maximum verbosity
nherriot 0:5136cdfaebd0 25 #ifndef __MODULE__
nherriot 0:5136cdfaebd0 26 #define __MODULE__ "net_voda_k3770_test.cpp"
nherriot 0:5136cdfaebd0 27 #endif
nherriot 0:5136cdfaebd0 28
nherriot 0:5136cdfaebd0 29 #define MY_PHONE_NUMBER "+447717275049"
nherriot 0:5136cdfaebd0 30
nherriot 0:5136cdfaebd0 31 #include "core/fwk.h"
nherriot 0:5136cdfaebd0 32 #include "mbed.h"
nherriot 0:5136cdfaebd0 33
nherriot 0:5136cdfaebd0 34 #include "rtos.h"
nherriot 0:5136cdfaebd0 35
nherriot 0:5136cdfaebd0 36 #include "if/VodafoneK3770.h"
nherriot 0:5136cdfaebd0 37
nherriot 2:bcc9256ecaab 38 #include <string>
nherriot 2:bcc9256ecaab 39
nherriot 0:5136cdfaebd0 40 extern "C" void HardFault_Handler() {
nherriot 0:5136cdfaebd0 41 error("Hard Fault!\n");
nherriot 0:5136cdfaebd0 42 }
nherriot 0:5136cdfaebd0 43
nherriot 0:5136cdfaebd0 44 DigitalOut led1(LED1);
nherriot 0:5136cdfaebd0 45 DigitalOut led2(LED2);
nherriot 0:5136cdfaebd0 46 DigitalOut led3(LED3);
nherriot 0:5136cdfaebd0 47 DigitalOut led4(LED4);
nherriot 0:5136cdfaebd0 48
nherriot 0:5136cdfaebd0 49 void test(void const*) {
nherriot 0:5136cdfaebd0 50 VodafoneK3770 threeg;
nherriot 0:5136cdfaebd0 51
nherriot 1:3c9d0c9dffa4 52 DBG("Hello world and Vodafone K3770 test program!");
nherriot 0:5136cdfaebd0 53
nherriot 0:5136cdfaebd0 54 threeg.sendSM(MY_PHONE_NUMBER, "Hello from mbed:)");
nherriot 0:5136cdfaebd0 55
nherriot 0:5136cdfaebd0 56 while(true)
nherriot 0:5136cdfaebd0 57 {
nherriot 0:5136cdfaebd0 58 char num[17];
nherriot 0:5136cdfaebd0 59 char msg[64];
nherriot 0:5136cdfaebd0 60 size_t count;
nherriot 0:5136cdfaebd0 61 int ret = threeg.getSMCount(&count);
nherriot 0:5136cdfaebd0 62 if(ret)
nherriot 0:5136cdfaebd0 63 {
nherriot 0:5136cdfaebd0 64 WARN("getSMCount returned %d", ret);
nherriot 0:5136cdfaebd0 65 Thread::wait(3000);
nherriot 0:5136cdfaebd0 66 continue;
nherriot 0:5136cdfaebd0 67 }
nherriot 0:5136cdfaebd0 68 if( count > 0)
nherriot 0:5136cdfaebd0 69 {
nherriot 0:5136cdfaebd0 70 DBG("%d SMS to read", count);
nherriot 0:5136cdfaebd0 71 ret = threeg.getSM(num, msg, 64);
nherriot 0:5136cdfaebd0 72 if(ret)
nherriot 0:5136cdfaebd0 73 {
nherriot 0:5136cdfaebd0 74 WARN("getSM returned %d", ret);
nherriot 0:5136cdfaebd0 75 Thread::wait(3000);
nherriot 0:5136cdfaebd0 76 continue;
nherriot 0:5136cdfaebd0 77 }
nherriot 0:5136cdfaebd0 78
nherriot 2:bcc9256ecaab 79 DBG("The message is from number: %s and the message is: %s", num, msg);
nherriot 2:bcc9256ecaab 80 if (strcmp (msg, "OPEN") ==0)
nherriot 2:bcc9256ecaab 81 {
nherriot 2:bcc9256ecaab 82 DBG("The SMS message indicates I should open the door");
nherriot 2:bcc9256ecaab 83 // do something to open the door
nherriot 2:bcc9256ecaab 84 }
nherriot 2:bcc9256ecaab 85 else
nherriot 2:bcc9256ecaab 86 {
nherriot 2:bcc9256ecaab 87 DBG("The SMS message is not recognized");
nherriot 2:bcc9256ecaab 88 }
nherriot 2:bcc9256ecaab 89
nherriot 2:bcc9256ecaab 90
nherriot 2:bcc9256ecaab 91
nherriot 0:5136cdfaebd0 92 }
nherriot 0:5136cdfaebd0 93 Thread::wait(3000);
nherriot 0:5136cdfaebd0 94 }
nherriot 0:5136cdfaebd0 95
nherriot 0:5136cdfaebd0 96 }
nherriot 0:5136cdfaebd0 97
nherriot 0:5136cdfaebd0 98 void keepAlive(void const*) {
nherriot 0:5136cdfaebd0 99 while(1)
nherriot 0:5136cdfaebd0 100 {
nherriot 0:5136cdfaebd0 101 led1=!led1;
nherriot 0:5136cdfaebd0 102 Thread::wait(500);
nherriot 0:5136cdfaebd0 103 }
nherriot 0:5136cdfaebd0 104 }
nherriot 0:5136cdfaebd0 105
nherriot 0:5136cdfaebd0 106 void tick()
nherriot 0:5136cdfaebd0 107 {
nherriot 0:5136cdfaebd0 108 led4=!led4;
nherriot 0:5136cdfaebd0 109 }
nherriot 0:5136cdfaebd0 110
nherriot 0:5136cdfaebd0 111 int main() {
nherriot 0:5136cdfaebd0 112 Ticker t;
nherriot 0:5136cdfaebd0 113 t.attach(tick,1);
nherriot 0:5136cdfaebd0 114 DBG_INIT();
nherriot 0:5136cdfaebd0 115
nherriot 0:5136cdfaebd0 116 Thread testTask(test, NULL, osPriorityNormal, 1024*4);
nherriot 0:5136cdfaebd0 117 keepAlive(NULL);
nherriot 0:5136cdfaebd0 118
nherriot 0:5136cdfaebd0 119
nherriot 0:5136cdfaebd0 120 return 0;
nherriot 0:5136cdfaebd0 121 }