Shows how to send and receive SMS messages using a Vodafone USB dongle.
Dependencies: VodafoneUSBModem mbed-rtos mbed
main.cpp
- Committer:
- ashleymills
- Date:
- 2012-11-08
- Revision:
- 0:675760d79fa5
- Child:
- 1:38c9e35517ea
File content as of revision 0:675760d79fa5:
#include "mbed.h" #include "VodafoneUSBModem.h" #define TEST_NUMBER "07825608771" #define MAX_SMS_LEN 256 int main() { // construct serial object for console monitor Serial pc(USBTX, USBRX); pc.baud(115200); // construct modem object VodafoneUSBModem modem; // locals size_t smCount = 0; char numBuffer[32], msgBuffer[256]; // send a wake-up SMS pc.printf("Sending test SMS to %s\r\n",TEST_NUMBER); if(modem.sendSM(TEST_NUMBER,"Hello!")!=0) { pc.printf("Error sending test SMS!\r\n"); } // loop forever printing received SMSs while(1) { // get SM count if(modem.getSMCount(&smCount)!=0) { pc.printf("Error receiving SMS count!\r\n"); continue; } // if SMS in mailbox if(smCount>0) { // get SMS and sender if(modem.getSM(numBuffer,msgBuffer,MAX_SMS_LEN)!=0) { pc.printf("Error retrieving SMS from mailbox!\r\n"); continue; } // print SMS and sender pc.printf("SMS: \"%s\", From: \"%s\"\r\n",msgBuffer,numBuffer); } // wait 1 second Thread::wait(1000); } }