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:24:31 2012 +0000
Revision:
4:99bbdfe42ae0
Parent:
3:0a8eebcb0acf
Child:
5:ca4f06634bcb
updating errors

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 3:0a8eebcb0acf 48 DigitalOut doorOpen(p5);
nherriot 3:0a8eebcb0acf 49
nherriot 0:5136cdfaebd0 50
nherriot 0:5136cdfaebd0 51 void test(void const*) {
nherriot 0:5136cdfaebd0 52 VodafoneK3770 threeg;
nherriot 0:5136cdfaebd0 53
nherriot 1:3c9d0c9dffa4 54 DBG("Hello world and Vodafone K3770 test program!");
nherriot 0:5136cdfaebd0 55
nherriot 0:5136cdfaebd0 56 threeg.sendSM(MY_PHONE_NUMBER, "Hello from mbed:)");
nherriot 0:5136cdfaebd0 57
nherriot 0:5136cdfaebd0 58 while(true)
nherriot 0:5136cdfaebd0 59 {
nherriot 0:5136cdfaebd0 60 char num[17];
nherriot 0:5136cdfaebd0 61 char msg[64];
nherriot 0:5136cdfaebd0 62 size_t count;
nherriot 3:0a8eebcb0acf 63 if (doorOpen)
nherriot 3:0a8eebcb0acf 64 {
nherriot 3:0a8eebcb0acf 65 doorOpen = 0;
nherriot 4:99bbdfe42ae0 66 led3=0;
nherriot 3:0a8eebcb0acf 67
nherriot 3:0a8eebcb0acf 68 }
nherriot 0:5136cdfaebd0 69 int ret = threeg.getSMCount(&count);
nherriot 0:5136cdfaebd0 70 if(ret)
nherriot 0:5136cdfaebd0 71 {
nherriot 0:5136cdfaebd0 72 WARN("getSMCount returned %d", ret);
nherriot 0:5136cdfaebd0 73 Thread::wait(3000);
nherriot 0:5136cdfaebd0 74 continue;
nherriot 0:5136cdfaebd0 75 }
nherriot 0:5136cdfaebd0 76 if( count > 0)
nherriot 0:5136cdfaebd0 77 {
nherriot 0:5136cdfaebd0 78 DBG("%d SMS to read", count);
nherriot 0:5136cdfaebd0 79 ret = threeg.getSM(num, msg, 64);
nherriot 0:5136cdfaebd0 80 if(ret)
nherriot 0:5136cdfaebd0 81 {
nherriot 0:5136cdfaebd0 82 WARN("getSM returned %d", ret);
nherriot 0:5136cdfaebd0 83 Thread::wait(3000);
nherriot 0:5136cdfaebd0 84 continue;
nherriot 0:5136cdfaebd0 85 }
nherriot 0:5136cdfaebd0 86
nherriot 2:bcc9256ecaab 87 DBG("The message is from number: %s and the message is: %s", num, msg);
nherriot 2:bcc9256ecaab 88 if (strcmp (msg, "OPEN") ==0)
nherriot 2:bcc9256ecaab 89 {
nherriot 2:bcc9256ecaab 90 DBG("The SMS message indicates I should open the door");
nherriot 2:bcc9256ecaab 91 // do something to open the door
nherriot 3:0a8eebcb0acf 92 doorOpen = 1;
nherriot 4:99bbdfe42ae0 93 led3 = 1
nherriot 2:bcc9256ecaab 94 }
nherriot 2:bcc9256ecaab 95 else
nherriot 2:bcc9256ecaab 96 {
nherriot 2:bcc9256ecaab 97 DBG("The SMS message is not recognized");
nherriot 2:bcc9256ecaab 98 }
nherriot 2:bcc9256ecaab 99
nherriot 2:bcc9256ecaab 100
nherriot 2:bcc9256ecaab 101
nherriot 0:5136cdfaebd0 102 }
nherriot 0:5136cdfaebd0 103 Thread::wait(3000);
nherriot 0:5136cdfaebd0 104 }
nherriot 0:5136cdfaebd0 105
nherriot 0:5136cdfaebd0 106 }
nherriot 0:5136cdfaebd0 107
nherriot 0:5136cdfaebd0 108 void keepAlive(void const*) {
nherriot 0:5136cdfaebd0 109 while(1)
nherriot 0:5136cdfaebd0 110 {
nherriot 0:5136cdfaebd0 111 led1=!led1;
nherriot 0:5136cdfaebd0 112 Thread::wait(500);
nherriot 0:5136cdfaebd0 113 }
nherriot 0:5136cdfaebd0 114 }
nherriot 0:5136cdfaebd0 115
nherriot 0:5136cdfaebd0 116 void tick()
nherriot 0:5136cdfaebd0 117 {
nherriot 0:5136cdfaebd0 118 led4=!led4;
nherriot 0:5136cdfaebd0 119 }
nherriot 0:5136cdfaebd0 120
nherriot 0:5136cdfaebd0 121 int main() {
nherriot 0:5136cdfaebd0 122 Ticker t;
nherriot 0:5136cdfaebd0 123 t.attach(tick,1);
nherriot 0:5136cdfaebd0 124 DBG_INIT();
nherriot 0:5136cdfaebd0 125
nherriot 0:5136cdfaebd0 126 Thread testTask(test, NULL, osPriorityNormal, 1024*4);
nherriot 0:5136cdfaebd0 127 keepAlive(NULL);
nherriot 0:5136cdfaebd0 128
nherriot 0:5136cdfaebd0 129
nherriot 0:5136cdfaebd0 130 return 0;
nherriot 0:5136cdfaebd0 131 }