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

Dependencies:   WNCInterface mbed-rtos mbed

This example program demonstrates the use of SMS with the AT&T IoT Kit which is sold by Avnet.

NOTE: Using SMS messages in conjunction with the AT&T IoT Kit are not standard SMS messages. These messages are intended to send messages between IoT devices and services such as FLOW (https://flow.att.com/). The SMS capability does not allow for interaction with a standard cellular phone number, instead, it uses a 15 digit MSIDN. This 15 digit MSIDN is displayed to the user when the program starts.

DESCRIPTION

The SMS example program generates a static SMS message and increasing sequence number that is sent every 30 seconds to 5277 (this is the default number for the AT&T SIM Control Center). Additionally, if a message is sent from the AT&T SIM Control Center it is displayed on the users console. The typical use case for SMS is that messages are sent via the provided via the AT&T APIs (https://starterkit.att.com/docs#sms-resource). For details on how and to-whom to send / receive SMS messages, please contact AT&T.

Discussion

The SMS example program defines two threads of operation. One thread—main—simply sends a SMS message every 20 seconds. The second thread is started when the WNCSms object is initialized. The initialization allows the user to specify a time period (in seconds) to check for messages and a function to call when a message is received. In the example program, incoming messages are checked for every second and if one is received, the function msg_rcvd() is called.

The msg_rcvd() function expect to be passed a single parameter—WNCSmsMsg&. This will contain all the information associated with the incoming SMS.

Expected execution outcome

Once the program is compiled and downloaded to the IoT Kit, perform the following steps:

1. Using a terminal program such as Hyperterm or Putty, connect to the Kit (select comm parameters of 115200-N81)

2. Press the `reset` button, then you should see the program start running! When it runs, the output will look similar to:

Sample Ouput

=Sample Output=

STARTING WNC SMS Test

Toggling Wakeup...
Toggling complete.
 WNC Initialized
 SMS Initialized
get my number: 882350201419599
sending SMS #1 to 5277..GO; waiting...
msg_rcvd called, msg from: '5277'
msg_rcvd from: '16/11/14'
msg_rcvd at '13:17:20-32'
msg_rcvd contained '"16/11/14,13:17:20-32",0'
sending SMS #2 to 5277..GO; msg_rcvd called, msg from: '5277'
msg_rcvd from: '16/11/14'
msg_rcvd at '13:17:41-32'
msg_rcvd contained '"16/11/14,13:17:41-32",0'
waiting...
sending SMS #3 to 5277..GO; waiting...
msg_rcvd called, msg from: '5277'
msg_rcvd from: '16/11/14'
msg_rcvd at '13:18:02-32'
msg_rcvd contained '"16/11/14,13:18:02-32",0'
.
.
.
sending SMS #64 to 5277..GO; waiting...
msg_rcvd called, msg from: '5277'
msg_rcvd from: '16/11/14'
msg_rcvd at '13:39:43-32'
msg_rcvd contained '"16/11/14,13:39:43-32",0'
msg_rcvd called, msg from: '5277'
msg_rcvd from: '16/11/14'
msg_rcvd at '13:39:46-32'
msg_rcvd contained 'This is a test...'

The message received at *13:39:46-32* was sent from the AT&T SIM Control Center to show receipt of an SMS.

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
JMF
Date:
Tue Dec 06 23:10:46 2016 +0000
Revision:
6:8b680309328e
Parent:
1:09f0433c50db
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:73b377d2f2c5 1 /* =====================================================================
JMF 0:73b377d2f2c5 2 Copyright © 2016, Avnet (R)
JMF 0:73b377d2f2c5 3
JMF 0:73b377d2f2c5 4 Contributors:
JMF 0:73b377d2f2c5 5 * James M Flynn, www.em.avnet.com
JMF 0:73b377d2f2c5 6
JMF 0:73b377d2f2c5 7 Licensed under the Apache License, Version 2.0 (the "License");
JMF 0:73b377d2f2c5 8 you may not use this file except in compliance with the License.
JMF 0:73b377d2f2c5 9 You may obtain a copy of the License at
JMF 0:73b377d2f2c5 10
JMF 0:73b377d2f2c5 11 http://www.apache.org/licenses/LICENSE-2.0
JMF 0:73b377d2f2c5 12
JMF 0:73b377d2f2c5 13 Unless required by applicable law or agreed to in writing,
JMF 0:73b377d2f2c5 14 software distributed under the License is distributed on an
JMF 0:73b377d2f2c5 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
JMF 0:73b377d2f2c5 16 either express or implied. See the License for the specific
JMF 0:73b377d2f2c5 17 language governing permissions and limitations under the License.
JMF 0:73b377d2f2c5 18
JMF 0:73b377d2f2c5 19 @file WNCInterface.cpp
JMF 0:73b377d2f2c5 20 @version 1.0
JMF 0:73b377d2f2c5 21 @date Sept 2016
JMF 0:73b377d2f2c5 22
JMF 0:73b377d2f2c5 23 ======================================================================== */
JMF 0:73b377d2f2c5 24
fkellermavnet 1:09f0433c50db 25 // Touch to work-around mbed tag.
fkellermavnet 1:09f0433c50db 26
JMF 0:73b377d2f2c5 27 #include "mbed.h"
JMF 0:73b377d2f2c5 28 #include "WNCInterface.h"
JMF 0:73b377d2f2c5 29 #include "Sms/IOTSMS.h"
JMF 0:73b377d2f2c5 30
JMF 0:73b377d2f2c5 31 #define MBED_PLATFORM
JMF 0:73b377d2f2c5 32 #define CRLF "\n\r"
JMF 0:73b377d2f2c5 33
JMF 0:73b377d2f2c5 34 MODSERIAL pc(USBTX,USBRX,256,256);
JMF 0:73b377d2f2c5 35
JMF 0:73b377d2f2c5 36 void msg_rcvd( WNCSmsMsg& msg ) {
JMF 0:73b377d2f2c5 37 pc.printf("msg_rcvd called, msg from: '%s'" CRLF, msg.number.c_str());
JMF 0:73b377d2f2c5 38 pc.printf("msg_rcvd from: '%s'" CRLF, msg.date.c_str());
JMF 0:73b377d2f2c5 39 pc.printf("msg_rcvd at '%s'" CRLF, msg.time.c_str());
JMF 0:73b377d2f2c5 40 pc.printf("msg_rcvd contained '%s'" CRLF, msg.msg.c_str());
JMF 0:73b377d2f2c5 41
JMF 0:73b377d2f2c5 42 }
JMF 0:73b377d2f2c5 43
JMF 0:73b377d2f2c5 44 int main() {
JMF 0:73b377d2f2c5 45 int cnt=1;
JMF 0:73b377d2f2c5 46 char buf[80];
JMF 0:73b377d2f2c5 47 char nbr[25];
JMF 0:73b377d2f2c5 48 string dest = "5277";
JMF 0:73b377d2f2c5 49 WNCInterface wnc;
JMF 0:73b377d2f2c5 50 WNCSms iotsms;
JMF 0:73b377d2f2c5 51
JMF 0:73b377d2f2c5 52 pc.baud(115200);
JMF 0:73b377d2f2c5 53 pc.printf(CRLF "STARTING WNC SMS Test" CRLF);
JMF 0:73b377d2f2c5 54 wnc.init(NULL,&pc);
JMF 0:73b377d2f2c5 55
JMF 0:73b377d2f2c5 56 pc.printf(" WNC Initialized" CRLF);
JMF 0:73b377d2f2c5 57 wnc.doDebug(0);
JMF 0:73b377d2f2c5 58 iotsms.init(1,msg_rcvd);
JMF 0:73b377d2f2c5 59 // iotsms.init();
JMF 0:73b377d2f2c5 60 pc.printf(" SMS Initialized" CRLF "get my number: ");
JMF 0:73b377d2f2c5 61
JMF 0:73b377d2f2c5 62 strncpy(nbr, iotsms.getSMSNbr(), 25);
JMF 0:73b377d2f2c5 63 pc.printf("%s" CRLF, nbr);
JMF 0:73b377d2f2c5 64
JMF 0:73b377d2f2c5 65 while( 1 ) {
JMF 0:73b377d2f2c5 66 pc.printf("sending SMS #%d to %s", cnt, dest.c_str() );
JMF 0:73b377d2f2c5 67 sprintf(buf, "SMS #%d", cnt++);
JMF 0:73b377d2f2c5 68 pc.printf("..GO; ");
JMF 0:73b377d2f2c5 69 iotsms.send(dest.c_str(), buf);
JMF 0:73b377d2f2c5 70 pc.printf("waiting..." CRLF);
JMF 0:73b377d2f2c5 71 Thread::wait(20000);
JMF 0:73b377d2f2c5 72 }
JMF 0:73b377d2f2c5 73 }
JMF 0:73b377d2f2c5 74