
Shows how to send and receive SMS messages using a Vodafone USB dongle.
Dependencies: VodafoneUSBModem mbed-rtos mbed
main.cpp@5:92271e224db9, 2013-10-08 (annotated)
- Committer:
- ashleymills
- Date:
- Tue Oct 08 20:21:53 2013 +0000
- Revision:
- 5:92271e224db9
- Parent:
- 4:9bfe20a36f47
Uncommented wakeup section and put dummy number in.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 1:38c9e35517ea | 1 | // stuff to use DBG debug output |
ashleymills | 1:38c9e35517ea | 2 | #define __DEBUG__ 4 //Maximum verbosity |
ashleymills | 1:38c9e35517ea | 3 | #ifndef __MODULE__ |
ashleymills | 1:38c9e35517ea | 4 | #define __MODULE__ "main.cpp" |
ashleymills | 1:38c9e35517ea | 5 | #endif |
ashleymills | 1:38c9e35517ea | 6 | |
ashleymills | 1:38c9e35517ea | 7 | // relevant headers |
ashleymills | 0:675760d79fa5 | 8 | #include "mbed.h" |
ashleymills | 0:675760d79fa5 | 9 | #include "VodafoneUSBModem.h" |
ashleymills | 0:675760d79fa5 | 10 | |
ashleymills | 5:92271e224db9 | 11 | #define TEST_NUMBER "0000" |
ashleymills | 0:675760d79fa5 | 12 | #define MAX_SMS_LEN 256 |
ashleymills | 0:675760d79fa5 | 13 | |
ashleymills | 0:675760d79fa5 | 14 | int main() { |
ashleymills | 1:38c9e35517ea | 15 | // setup debug macro |
ashleymills | 1:38c9e35517ea | 16 | DBG_INIT(); |
ashleymills | 1:38c9e35517ea | 17 | DBG_SET_SPEED(115200); |
ashleymills | 1:38c9e35517ea | 18 | DBG_SET_NEWLINE("\r\n"); |
ashleymills | 0:675760d79fa5 | 19 | |
ashleymills | 0:675760d79fa5 | 20 | // construct modem object |
ashleymills | 0:675760d79fa5 | 21 | VodafoneUSBModem modem; |
ashleymills | 0:675760d79fa5 | 22 | |
ashleymills | 0:675760d79fa5 | 23 | // locals |
ashleymills | 0:675760d79fa5 | 24 | size_t smCount = 0; |
ashleymills | 0:675760d79fa5 | 25 | char numBuffer[32], msgBuffer[256]; |
ashleymills | 0:675760d79fa5 | 26 | |
ashleymills | 0:675760d79fa5 | 27 | // send a wake-up SMS |
ashleymills | 1:38c9e35517ea | 28 | DBG("Sending test SMS to %s",TEST_NUMBER); |
ashleymills | 5:92271e224db9 | 29 | if(modem.sendSM(TEST_NUMBER,"Hello!")!=0) { |
ashleymills | 5:92271e224db9 | 30 | DBG("Error sending test SMS!"); |
ashleymills | 5:92271e224db9 | 31 | } |
ashleymills | 0:675760d79fa5 | 32 | |
ashleymills | 0:675760d79fa5 | 33 | // loop forever printing received SMSs |
ashleymills | 0:675760d79fa5 | 34 | while(1) { |
ashleymills | 0:675760d79fa5 | 35 | |
ashleymills | 0:675760d79fa5 | 36 | // get SM count |
ashleymills | 0:675760d79fa5 | 37 | if(modem.getSMCount(&smCount)!=0) { |
ashleymills | 1:38c9e35517ea | 38 | DBG("Error receiving SMS count!"); |
ashleymills | 0:675760d79fa5 | 39 | continue; |
ashleymills | 0:675760d79fa5 | 40 | } |
ashleymills | 0:675760d79fa5 | 41 | |
ashleymills | 0:675760d79fa5 | 42 | // if SMS in mailbox |
ashleymills | 0:675760d79fa5 | 43 | if(smCount>0) { |
ashleymills | 0:675760d79fa5 | 44 | |
ashleymills | 0:675760d79fa5 | 45 | // get SMS and sender |
ashleymills | 0:675760d79fa5 | 46 | if(modem.getSM(numBuffer,msgBuffer,MAX_SMS_LEN)!=0) { |
ashleymills | 1:38c9e35517ea | 47 | DBG("Error retrieving SMS from mailbox!"); |
ashleymills | 0:675760d79fa5 | 48 | continue; |
ashleymills | 0:675760d79fa5 | 49 | } |
ashleymills | 0:675760d79fa5 | 50 | |
ashleymills | 0:675760d79fa5 | 51 | // print SMS and sender |
ashleymills | 1:38c9e35517ea | 52 | DBG("SMS: \"%s\", From: \"%s\"",msgBuffer,numBuffer); |
ashleymills | 0:675760d79fa5 | 53 | |
ashleymills | 0:675760d79fa5 | 54 | } |
ashleymills | 0:675760d79fa5 | 55 | |
ashleymills | 0:675760d79fa5 | 56 | // wait 1 second |
ashleymills | 0:675760d79fa5 | 57 | Thread::wait(1000); |
ashleymills | 0:675760d79fa5 | 58 | } |
ashleymills | 0:675760d79fa5 | 59 | } |