This is a demonstration program that shows operation of SMS using the WNC Interface.

Dependencies:   WNCInterface mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* =====================================================================
00002    Copyright © 2016, Avnet (R)
00003 
00004    Contributors:
00005      * James M Flynn, www.em.avnet.com 
00006  
00007    Licensed under the Apache License, Version 2.0 (the "License"); 
00008    you may not use this file except in compliance with the License.
00009    You may obtain a copy of the License at
00010 
00011     http://www.apache.org/licenses/LICENSE-2.0
00012 
00013    Unless required by applicable law or agreed to in writing, 
00014    software distributed under the License is distributed on an 
00015    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
00016    either express or implied. See the License for the specific 
00017    language governing permissions and limitations under the License.
00018 
00019     @file          WNCInterface.cpp
00020     @version       1.0
00021     @date          Sept 2016
00022 
00023 ======================================================================== */
00024 
00025 // Touch to work-around mbed tag.
00026 
00027 #include "mbed.h"
00028 #include "WNCInterface.h"
00029 #include "Sms/IOTSMS.h"
00030 
00031 #define MBED_PLATFORM
00032 #define CRLF    "\n\r"
00033 
00034 MODSERIAL pc(USBTX,USBRX,256,256);
00035 
00036 void msg_rcvd( WNCSmsMsg& msg ) {
00037   pc.printf("msg_rcvd called, msg from: '%s'" CRLF, msg.number.c_str());
00038   pc.printf("msg_rcvd from: '%s'" CRLF, msg.date.c_str());
00039   pc.printf("msg_rcvd at '%s'" CRLF, msg.time.c_str());
00040   pc.printf("msg_rcvd contained '%s'" CRLF, msg.msg.c_str());
00041   
00042 }
00043     
00044 int main() {
00045     int cnt=1;
00046     char buf[80];
00047     char nbr[25];
00048     string dest = "5277";
00049     WNCInterface wnc;
00050     WNCSms iotsms;
00051 
00052     pc.baud(115200);    
00053     pc.printf(CRLF "STARTING WNC SMS Test" CRLF);
00054     wnc.init(NULL,&pc);  
00055     
00056     pc.printf(" WNC Initialized" CRLF); 
00057     wnc.doDebug(0);                 
00058     iotsms.init(1,msg_rcvd);
00059 //    iotsms.init();
00060     pc.printf(" SMS Initialized" CRLF "get my number: ");
00061 
00062     strncpy(nbr, iotsms.getSMSNbr(), 25);
00063     pc.printf("%s" CRLF, nbr);
00064     
00065     while( 1 ) {
00066       pc.printf("sending SMS #%d to %s", cnt, dest.c_str() );
00067       sprintf(buf, "SMS #%d", cnt++);
00068       pc.printf("..GO; ");
00069       iotsms.send(dest.c_str(), buf);
00070       pc.printf("waiting..." CRLF);
00071       Thread::wait(20000);
00072       }
00073 }
00074