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 13:18:31 2012 +0000
Revision:
0:5136cdfaebd0
Child:
1:3c9d0c9dffa4
changed phone number

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 0:5136cdfaebd0 38 extern "C" void HardFault_Handler() {
nherriot 0:5136cdfaebd0 39 error("Hard Fault!\n");
nherriot 0:5136cdfaebd0 40 }
nherriot 0:5136cdfaebd0 41
nherriot 0:5136cdfaebd0 42 DigitalOut led1(LED1);
nherriot 0:5136cdfaebd0 43 DigitalOut led2(LED2);
nherriot 0:5136cdfaebd0 44 DigitalOut led3(LED3);
nherriot 0:5136cdfaebd0 45 DigitalOut led4(LED4);
nherriot 0:5136cdfaebd0 46
nherriot 0:5136cdfaebd0 47 void test(void const*) {
nherriot 0:5136cdfaebd0 48 VodafoneK3770 threeg;
nherriot 0:5136cdfaebd0 49
nherriot 0:5136cdfaebd0 50 DBG("Hello!");
nherriot 0:5136cdfaebd0 51
nherriot 0:5136cdfaebd0 52 threeg.sendSM(MY_PHONE_NUMBER, "Hello from mbed:)");
nherriot 0:5136cdfaebd0 53
nherriot 0:5136cdfaebd0 54 while(true)
nherriot 0:5136cdfaebd0 55 {
nherriot 0:5136cdfaebd0 56 char num[17];
nherriot 0:5136cdfaebd0 57 char msg[64];
nherriot 0:5136cdfaebd0 58 size_t count;
nherriot 0:5136cdfaebd0 59 int ret = threeg.getSMCount(&count);
nherriot 0:5136cdfaebd0 60 if(ret)
nherriot 0:5136cdfaebd0 61 {
nherriot 0:5136cdfaebd0 62 WARN("getSMCount returned %d", ret);
nherriot 0:5136cdfaebd0 63 Thread::wait(3000);
nherriot 0:5136cdfaebd0 64 continue;
nherriot 0:5136cdfaebd0 65 }
nherriot 0:5136cdfaebd0 66 if( count > 0)
nherriot 0:5136cdfaebd0 67 {
nherriot 0:5136cdfaebd0 68 DBG("%d SMS to read", count);
nherriot 0:5136cdfaebd0 69 ret = threeg.getSM(num, msg, 64);
nherriot 0:5136cdfaebd0 70 if(ret)
nherriot 0:5136cdfaebd0 71 {
nherriot 0:5136cdfaebd0 72 WARN("getSM returned %d", ret);
nherriot 0:5136cdfaebd0 73 Thread::wait(3000);
nherriot 0:5136cdfaebd0 74 continue;
nherriot 0:5136cdfaebd0 75 }
nherriot 0:5136cdfaebd0 76
nherriot 0:5136cdfaebd0 77 DBG("%s : %s", num, msg);
nherriot 0:5136cdfaebd0 78 }
nherriot 0:5136cdfaebd0 79 Thread::wait(3000);
nherriot 0:5136cdfaebd0 80 }
nherriot 0:5136cdfaebd0 81
nherriot 0:5136cdfaebd0 82 }
nherriot 0:5136cdfaebd0 83
nherriot 0:5136cdfaebd0 84 void keepAlive(void const*) {
nherriot 0:5136cdfaebd0 85 while(1)
nherriot 0:5136cdfaebd0 86 {
nherriot 0:5136cdfaebd0 87 led1=!led1;
nherriot 0:5136cdfaebd0 88 Thread::wait(500);
nherriot 0:5136cdfaebd0 89 }
nherriot 0:5136cdfaebd0 90 }
nherriot 0:5136cdfaebd0 91
nherriot 0:5136cdfaebd0 92 void tick()
nherriot 0:5136cdfaebd0 93 {
nherriot 0:5136cdfaebd0 94 led4=!led4;
nherriot 0:5136cdfaebd0 95 }
nherriot 0:5136cdfaebd0 96
nherriot 0:5136cdfaebd0 97 int main() {
nherriot 0:5136cdfaebd0 98 Ticker t;
nherriot 0:5136cdfaebd0 99 t.attach(tick,1);
nherriot 0:5136cdfaebd0 100 DBG_INIT();
nherriot 0:5136cdfaebd0 101
nherriot 0:5136cdfaebd0 102 Thread testTask(test, NULL, osPriorityNormal, 1024*4);
nherriot 0:5136cdfaebd0 103 keepAlive(NULL);
nherriot 0:5136cdfaebd0 104
nherriot 0:5136cdfaebd0 105
nherriot 0:5136cdfaebd0 106 return 0;
nherriot 0:5136cdfaebd0 107 }