An example program demonstrating the use of SMS with the WNC M14A2A Data Module on the Avnet AT&T Started IoT kit.

Dependencies:   WNC14A2AInterface BufferedSerial

WNC 14A2A Data Module Networking Library –SMS Example

This example demonstrates the use of the WNC14A2A Network API that has been updated to support ARMmbed v5 with SMS messages. The example uses 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.

Compiling

Compiling the example program can be performed either (1) using the online tools at https://developer.mbed.org, or (2) using the Command Line Interface (CLI) tools available from https://github.com/ARMmbed/mbed-cli. The following describes the use of the online tools. Using the CLI requires familiarity with installing compilers and other tools which are beyond the scope of this readme.

1. Launch mbed online compiler in your browser

2. Navigate to https://developer.mbed.org/teams/Avnet/code/SMS_demo/

3. On the right side of the screen, select the “Import into Compiler” button. This bring up a dialog and prompt you to enter a name for the program—suggesting SMS_demo as an example.

Once the components have been imported into your new program, simply execute the Compile button. There will be 225 warning and 1 info message generated which is expected. Copy the resulting 'SMS_demoK64F.bin' program (or whatever you named it ‘*K64F.bin’) from your browser download folder to your connected AT&T IoT Starter kit.

Discussion

The SMS API that is provided in the WNC14A2AInterface class encompases:

  • Start the SMS interface sms_start(). This allows the WNC14A2A to begin processing SMS messages.
  • getSMS is called to retrieve a SMS message that has been sent to the device.
  • sendIOTSms allows the user to send an SMS message to another device on the IoT network.
  • getSMSnbr will return the SMS ID/Number for the device this program is running on.
  • sms_listen() is called so that the device will begin monitoring for incoming SMS messages at a user specified interval. If a call-back function is attached, it will be called when a message is received. If a call-back function is not registered, nothing will be done with the SMS message. The WNC14A2A can store a maximum of 3 messages.
  • sms_attach() specifies the function that is to be called when an SMS message is received

Monitoring for SMS messages is performed by starting a thread that executes at a user defined interval. If no interval is specified, 30 seconds is assumed.

Programming & execution outcome

1. Once the program is compiled, it will be downloaded to your browser ‘Downloads’ folder. To program the IoT Starter Kit, you copy the binary file (‘*K64F.bin’) to the MBED Drive that shows up in the Windows explorer window. While the board is being programmed, the LED on the K64F board will flash rapidly and when complete, it will stop flashing.

2. Once programmed, use a serial terminal program such as Hyperterm or Putty to connect to the IoT Starter Kit. You can find the specific Communication port to use by reviewing ‘Device Manager’ on your computer where it will be displayed as mbed Serial Port (COM21)’ or whatever the correct comport is. The communications parameters for the port are 9600-N81.

3. Press the `reset` button on the K64F and the program will start running! When run, the output will look similar to:

NOTES:

i) terminal programs are inconsistent in how they treat carriage-return-linefeed sequences and their behavior can often times be adjusted using program settings. If you notice output where the text does not follow the example below, adjust the program settings so that Carriage return + line-feeds are output instead of just line-feeds.

ii) Debug output is included by default and can be disabled by modifying the following two lines of code the program:

DEBUG ON

      WNC14A2AInterface wnc(&dbg);
      wnc.doDebug(1);

DEBUG OFF

        WNC14A2AInterface wnc();
        //wnc.doDebug(1);

Sample Output

Sample Ouput

[*] 192043104 TX: AT+CMGL
[*] 192079028 RX: AT+CMGLOK
[*] 202044104 TX: AT+CMGL
[*] 202079194 RX: AT+CMGLOK
Adding DEBUG output

STARTING WNC SMS Test
 [*] 26052 TX: AT+CMGL
[*] 50003 RX:
[*] 66667 readSMSLog: Failed!
[*] 98968 Waiting for WNC to Initialize...
Waiting 12
[*] 28487188
Toggling Wakeup...
[*] 30563648 Toggling complete.
[*] 30596056 TX: AT%PDNSET=1,m2m.com.attz,IP
[*] 30670478 RX: AT%PDNSET=1,m2m.com.attz,IPOK
[*] 30718552 TX: AT+CSQ
[*] 30750365 RX: AT+CSQ+CSQ: 16,0OK
[*] 30786980 TX: AT+CPIN?
[*] 30821393 RX: AT+CPIN?+CPIN: READYOK
[*] 30862090 TX: AT+CREG?
[*] 30897702 RX: AT+CREG?+CREG: 2,1,2717,0BAA1410,7OK
[*] 30953039 Start AT init of WNC:
[*] 30990522 TX: AT
[*] 31016540 RX: ATOK
[*] 31038543 TX: AT
[*] 31064351 RX: ATOK
[*] 31086355 TX: AT+GMR
[*] 31125514 RX: AT+GMRMPSS: M14A2A_v11.50.164451 APSS: M14A2A_v11.53.164451OK
[*] 31206876 TX: ATE0
[*] 31234188 RX: ATE0OK
[*] 31258230 TX: AT+CMEE=2
[*] 31292674 RX: AT+CMEE=2OK
[*] 31321980 TX: AT+CMGF=1
[*] 31377687 RX: AT+CMGF=1OK
[*] 31406981 TX: AT+CPMS="SM","SM","SM"
[*] 31472104 RX: AT+CPMS="SM","SM","SM"+CPMS: 0,3,0,3,0,3OK
[*] 31533647 TX: AT
[*] 31559358 RX: ATOK
[*] 31581356 TX: AT@INTERNET=1
[*] 31625232 RX: AT@INTERNET=1OK
[*] 31658647 TX: AT@SOCKDIAL=1
[*] 31711994 RX: AT@SOCKDIAL=1OK
[*] 31745417 SUCCESS: AT init of WNC!
[*] 31786048 TX: AT+CGCONTRDP=1
[*] 31837126 RX: AT+CGCONTRDP=1+CGCONTRDP: 1,5,"m2m.com.a...252,10.192.205.165,8.8.8.8,8.8.4.4,,,OK
[*] 31940525 ~~~~~~~~~~ WNC IP Stats ~~~~~~~~~~~~
[*] 31993542 ip: 10.192.205.166
[*] 32027917 mask: 255.255.255.252
[*] 32065417 gateway: 10.192.205.165
[*] 32105000 dns pri: 8.8.8.8
[*] 32137292 dns sec: 8.8.4.4
[*] 32169583 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 WNC Initialized
 [*] 32240436 TX: AT+CMGD=1
[*] 32279640 RX: AT+CMGD=1+CMS ERROR: 321
[*] 32322522 TX: AT+CMGD=2
[*] 32361632 RX: AT+CMGD=2+CMS ERROR: 321
[*] 32404501 TX: AT+CMGD=3
[*] 32443645 RX: AT+CMGD=3+CMS ERROR: 321
[*] 32486474 TX: AT%CCID
[*] 32520383 RX: AT%CCID89011702272014195991OK
My number: 882350201419599
-->Pausing 30 seconds then check for SMS received from the console
 [*] 62666364 TX: AT+CMGL
[*] 62701097 RX: AT+CMGLOK
Checked, there are 0 SMS messages

Start Monitoring thread to check every 10 seconds for incomming messages
 [*] 62840905 TX: AT+CMGD=1
[*] 62879902 RX: AT+CMGD=1+CMS ERROR: 321
[*] 62922731 TX: AT+CMGD=2
[*] 62961815 RX: AT+CMGD=2+CMS ERROR: 321
[*] 63004710 TX: AT+CMGD=3
[*] 63043601 RX: AT+CMGD=3+CMS ERROR: 321
sending SMS #1 to 5277..GO;
 [*] 63115647 TX: AT+CSQ
[*] 63147475 RX: AT+CSQ+CSQ: 20,99OK
[*] 63185105 TX: AT+CPIN?
[*] 63220029 RX: AT+CPIN?+CPIN: READYOK
[*] 63260733 TX: AT+CREG?
[*] 63296071 RX: AT+CREG?+CREG: 2,1,2717,0BAA1410,7OK
[*] 63351373 TX: AT+CMGF=1
[*] 63386029 RX: AT+CMGF=1OK
[*] 63415326 TX: AT+CMGS="5277"
[*] 63456175 RX: AT+CMGS="5277"ERROR
[*] 63493762 sendSMSText: Failed!
wait 60 seconds and check for incomming SMS msgs...
 [*] 73087104 TX: AT+CMGL
[*] 73122001 RX: AT+CMGLOK
[*] 83087104 TX: AT+CMGL
[*] 83122046 RX: AT+CMGLOK
[*] 93087104 TX: AT+CMGL
[*] 93122185 RX: AT+CMGLOK
[*] 103087104 TX: AT+CMGL
[*] 103122584 RX: AT+CMGLOK
[*] 113087104 TX: AT+CMGL
[*] 113122528 RX: AT+CMGLOK
[*] 123087104 TX: AT+CMGL
[*] 123122591 RX: AT+CMGLOK
sending SMS #2 to 5277..GO;
 [*] 123611585 TX: AT+CSQ
[*] 123644367 RX: AT+CSQ+CSQ: 21,99OK
[*] 123683022 TX: AT+CPIN?
[*] 123718451 RX: AT+CPIN?+CPIN: READYOK
[*] 123760212 TX: AT+CREG?
[*] 123796733 RX: AT+CREG?+CREG: 2,1,2717,0BAA1410,7OK
[*] 123853144 TX: AT+CMGF=1
[*] 123889282 RX: AT+CMGF=1OK
[*] 123919596 TX: AT+CMGS="5277"
[*] 124255814 RX: AT+CMGS="5277">
[*] 124291360 TX: SMS #2
[*] 125292410 RX: SMS #2+CMGS: 96OK
wait 60 seconds and check for incomming SMS msgs...
 [*] 133088104 TX: AT+CMGL
[*] 133145992 RX: AT+CMGL+CMGL: 1,"REC UNREAD",6,96,"5277"..,08:02:03-28","17/05/01,08:02:03-28",0OK
[*] 133250421 TX: AT+CMGD=1
[*] 133290054 RX: AT+CMGD=1OK
msg_rcvd called, msg from: '5277'
msg_rcvd from: '17/05/01'
msg_rcvd at '08:02:03-28'
msg_rcvd contained '"17/05/01,08:02:03-28",0'

The message received at *17/05/01,08:02:03-28* was sent from the AT&T SIM Control Center to show receipt of an SMS.

WNC FIRMWARE VERSION

The WNC14A2AInterface class currently supports the following version(s):

  • MPSS: M14A2A_v11.50.164451 APSS: M14A2A_v11.53.164451

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:
Sun Apr 23 17:01:12 2017 +0000
Revision:
3:7ed7c680ebf0
Parent:
0:8ef17b8b7104
changed debug settings.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-Avnet 0:8ef17b8b7104 1 WNC 14A2A Data Module Networking Library
group-Avnet 0:8ef17b8b7104 2 ========================================
group-Avnet 0:8ef17b8b7104 3
group-Avnet 0:8ef17b8b7104 4 This example shows how to use the WNC14A2A Network API that has been updated to support ARMmbed v5
group-Avnet 0:8ef17b8b7104 5 with SMS messages. The example uses the AT&T IoT Kit is sold by
group-Avnet 0:8ef17b8b7104 6 [[http://cloudconnectkits.org/product/att-cellular-iot-starter-kit|Avnet]].
group-Avnet 0:8ef17b8b7104 7
group-Avnet 0:8ef17b8b7104 8 __**NOTE:**__ Using SMS messages in conjunction with the AT&T IoT Kit are not standard SMS messages.
group-Avnet 0:8ef17b8b7104 9 These messages are intended to send messages between IoT devices and services such as
group-Avnet 0:8ef17b8b7104 10 FLOW (https://flow.att.com/). The SMS capability does not allow for interaction with a standard
group-Avnet 0:8ef17b8b7104 11 cellular phone number, instead, it uses a 15 digit MSIDN. This 15 digit MSIDN is displayed to the
group-Avnet 0:8ef17b8b7104 12 user when the program starts.
group-Avnet 0:8ef17b8b7104 13
group-Avnet 0:8ef17b8b7104 14 1. Launch [[https://mbed.org/compiler/|mbed online compiler]] in your browser
group-Avnet 0:8ef17b8b7104 15 2. Right clicking on "My Programs", the select "Import Program", followed by "From URL ..." This will
group-Avnet 0:8ef17b8b7104 16 bring up a dialog for you to select the Source URL:. Enter [[https://github.com/jflynn129/WNC14A2ASms_demo]]
group-Avnet 0:8ef17b8b7104 17 ensuring Import As: Program is selected. Once "main.cpp" has been imported you will have a new entry
group-Avnet 0:8ef17b8b7104 18 in "My Programs" titled WNC14A2A_socket_example
group-Avnet 0:8ef17b8b7104 19 3. Right click on the WNC14A2A_socket_example and again "Import Prgram" followed by "From URL ...".
group-Avnet 0:8ef17b8b7104 20 This time import the ARMmbed v5.x O/S from [[https://github.com/ARMmbed/mbed-os]]
group-Avnet 0:8ef17b8b7104 21 4. Right click on the WNC14A2A_socket_example and again "Import Prgram" followed by "From URL ...".
group-Avnet 0:8ef17b8b7104 22 This time import the WNC14A2AInterface from [[https://github.com/jflynn129/WNC14A2AInterface]]
group-Avnet 0:8ef17b8b7104 23 5. As a final step, click on the WNC14A2A_socket_example and again "Import Prgram" folloed by
group-Avnet 0:8ef17b8b7104 24 "From URL ..." then select [[https://developer.mbed.org/teams/Avnet/code/WncControllerK64F/]].
group-Avnet 0:8ef17b8b7104 25 The library (which will blso ring includes the WncController class which implements the AT commands
group-Avnet 0:8ef17b8b7104 26 necessary to control the WNC14A2A module.
group-Avnet 0:8ef17b8b7104 27
group-Avnet 0:8ef17b8b7104 28 With all the components in-place, simply execute the **Compile** button. There will be several warning
group-Avnet 0:8ef17b8b7104 29 and 1 info message generated which is expected. Copy the resulting 'SMS_demoK64F.bin' program
group-Avnet 0:8ef17b8b7104 30 to your connect kit.
group-Avnet 0:8ef17b8b7104 31
group-Avnet 0:8ef17b8b7104 32 =Discussion=
group-Avnet 0:8ef17b8b7104 33 SMS is provided in the WNC14A2AInterface class. It provides APIs to:
group-Avnet 0:8ef17b8b7104 34 * Start the SMS interface **sms_start()**. This allows the WNC14A2A to begin processing SMS messages.
group-Avnet 0:8ef17b8b7104 35 * getSMS is called to retrieve a SMS message that has been sent to the device.
group-Avnet 0:8ef17b8b7104 36 * sendIOTSms allows the user to send an SMS message to another device on the IoT network.
group-Avnet 0:8ef17b8b7104 37 * getSMSnbr will return the SMS ID/Number for this device
group-Avnet 0:8ef17b8b7104 38 * sms_listen() is called so that the device will begin monitoring for incomming SMS messages at a user
group-Avnet 0:8ef17b8b7104 39 specified interval. If a call-back function is attached, it will be called when a message is received. If
group-Avnet 0:8ef17b8b7104 40 a call-back function is not registered, nothing will be done with the SMS message. The WNC14A2A can store a
group-Avnet 0:8ef17b8b7104 41 maximum of 3 messages.
group-Avnet 0:8ef17b8b7104 42 * sms_attach() specifies the function that is to be called when an SMS message is received
group-Avnet 0:8ef17b8b7104 43
group-Avnet 0:8ef17b8b7104 44 Monitoring for an SMS is performed by starting a thread that executes at a user defined interval. If no interval is
group-Avnet 0:8ef17b8b7104 45 specified, 30 seconds is assumed.
group-Avnet 0:8ef17b8b7104 46
group-Avnet 0:8ef17b8b7104 47 ==Expected execution outcome==
group-Avnet 0:8ef17b8b7104 48
group-Avnet 0:8ef17b8b7104 49 Once the program is compiled and downloaded to the IoT Kit, perform the following steps:
group-Avnet 0:8ef17b8b7104 50
group-Avnet 0:8ef17b8b7104 51 1. Using a terminal program such as Hyperterm or Putty, connect to the Kit (select comm parameters of 115200-N81)
group-Avnet 0:8ef17b8b7104 52
group-Avnet 0:8ef17b8b7104 53 2. Press the `reset` button, then you should see the program start running! When it runs, the output will look similar to:
group-Avnet 0:8ef17b8b7104 54
group-Avnet 0:8ef17b8b7104 55 <<code title=Sample Ouput>>
group-Avnet 0:8ef17b8b7104 56 =Sample Output=
group-Avnet 0:8ef17b8b7104 57
group-Avnet 0:8ef17b8b7104 58 STARTING WNC SMS Test
group-Avnet 0:8ef17b8b7104 59
group-Avnet 0:8ef17b8b7104 60 Toggling Wakeup...
group-Avnet 0:8ef17b8b7104 61
group-Avnet 0:8ef17b8b7104 62 Toggling complete.
group-Avnet 0:8ef17b8b7104 63
group-Avnet 0:8ef17b8b7104 64 WNC Initialized
group-Avnet 0:8ef17b8b7104 65
group-Avnet 0:8ef17b8b7104 66 SMS Initialized
group-Avnet 0:8ef17b8b7104 67
group-Avnet 0:8ef17b8b7104 68 get my number: 882350201419599
group-Avnet 0:8ef17b8b7104 69
group-Avnet 0:8ef17b8b7104 70 sending SMS #1 to 5277..GO; waiting...
group-Avnet 0:8ef17b8b7104 71
group-Avnet 0:8ef17b8b7104 72 msg_rcvd called, msg from: '5277'
group-Avnet 0:8ef17b8b7104 73
group-Avnet 0:8ef17b8b7104 74 msg_rcvd from: '16/11/14'
group-Avnet 0:8ef17b8b7104 75
group-Avnet 0:8ef17b8b7104 76 msg_rcvd at '13:17:20-32'
group-Avnet 0:8ef17b8b7104 77
group-Avnet 0:8ef17b8b7104 78 msg_rcvd contained '"16/11/14,13:17:20-32",0'
group-Avnet 0:8ef17b8b7104 79
group-Avnet 0:8ef17b8b7104 80 sending SMS #2 to 5277..GO; msg_rcvd called, msg from: '5277'
group-Avnet 0:8ef17b8b7104 81
group-Avnet 0:8ef17b8b7104 82 msg_rcvd from: '16/11/14'
group-Avnet 0:8ef17b8b7104 83
group-Avnet 0:8ef17b8b7104 84 msg_rcvd at '13:17:41-32'
group-Avnet 0:8ef17b8b7104 85
group-Avnet 0:8ef17b8b7104 86 msg_rcvd contained '"16/11/14,13:17:41-32",0'
group-Avnet 0:8ef17b8b7104 87
group-Avnet 0:8ef17b8b7104 88 waiting...
group-Avnet 0:8ef17b8b7104 89
group-Avnet 0:8ef17b8b7104 90 sending SMS #3 to 5277..GO; waiting...
group-Avnet 0:8ef17b8b7104 91
group-Avnet 0:8ef17b8b7104 92 msg_rcvd called, msg from: '5277'
group-Avnet 0:8ef17b8b7104 93
group-Avnet 0:8ef17b8b7104 94 msg_rcvd from: '16/11/14'
group-Avnet 0:8ef17b8b7104 95
group-Avnet 0:8ef17b8b7104 96 msg_rcvd at '13:18:02-32'
group-Avnet 0:8ef17b8b7104 97
group-Avnet 0:8ef17b8b7104 98 msg_rcvd contained '"16/11/14,13:18:02-32",0'
group-Avnet 0:8ef17b8b7104 99
group-Avnet 0:8ef17b8b7104 100 .
group-Avnet 0:8ef17b8b7104 101
group-Avnet 0:8ef17b8b7104 102 .
group-Avnet 0:8ef17b8b7104 103
group-Avnet 0:8ef17b8b7104 104 .
group-Avnet 0:8ef17b8b7104 105
group-Avnet 0:8ef17b8b7104 106 sending SMS #64 to 5277..GO; waiting...
group-Avnet 0:8ef17b8b7104 107
group-Avnet 0:8ef17b8b7104 108 msg_rcvd called, msg from: '5277'
group-Avnet 0:8ef17b8b7104 109
group-Avnet 0:8ef17b8b7104 110 msg_rcvd from: '16/11/14'
group-Avnet 0:8ef17b8b7104 111
group-Avnet 0:8ef17b8b7104 112 msg_rcvd at '13:39:43-32'
group-Avnet 0:8ef17b8b7104 113
group-Avnet 0:8ef17b8b7104 114 msg_rcvd contained '"16/11/14,13:39:43-32",0'
group-Avnet 0:8ef17b8b7104 115
group-Avnet 0:8ef17b8b7104 116 msg_rcvd called, msg from: '5277'
group-Avnet 0:8ef17b8b7104 117
group-Avnet 0:8ef17b8b7104 118 msg_rcvd from: '16/11/14'
group-Avnet 0:8ef17b8b7104 119
group-Avnet 0:8ef17b8b7104 120 msg_rcvd at '13:39:46-32'
group-Avnet 0:8ef17b8b7104 121
group-Avnet 0:8ef17b8b7104 122 msg_rcvd contained 'This is a test...'
group-Avnet 0:8ef17b8b7104 123
group-Avnet 0:8ef17b8b7104 124
group-Avnet 0:8ef17b8b7104 125 <</code>>
group-Avnet 0:8ef17b8b7104 126
group-Avnet 0:8ef17b8b7104 127 The message received at *13:39:46-32* was sent from the AT&T SIM Control Center to show receipt of an SMS.
group-Avnet 0:8ef17b8b7104 128
group-Avnet 0:8ef17b8b7104 129
group-Avnet 0:8ef17b8b7104 130 WNC FIRWARE VERSION
group-Avnet 0:8ef17b8b7104 131 ===================
group-Avnet 0:8ef17b8b7104 132
group-Avnet 0:8ef17b8b7104 133 The WNCInterface class currently supports the following version(s):
group-Avnet 0:8ef17b8b7104 134 * MPSS: M14A2A_v11.21.162331 APSS: M14A2A_v11.27.162331
group-Avnet 0:8ef17b8b7104 135
group-Avnet 0:8ef17b8b7104 136
group-Avnet 0:8ef17b8b7104 137 License
group-Avnet 0:8ef17b8b7104 138 =======
group-Avnet 0:8ef17b8b7104 139 This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
group-Avnet 0:8ef17b8b7104 140 file except in compliance with the License and may obtain a copy of the License at
group-Avnet 0:8ef17b8b7104 141
group-Avnet 0:8ef17b8b7104 142 http://www.apache.org/licenses/LICENSE-2.0
group-Avnet 0:8ef17b8b7104 143
group-Avnet 0:8ef17b8b7104 144 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
group-Avnet 0:8ef17b8b7104 145 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
group-Avnet 0:8ef17b8b7104 146 language governing permissions and limitations under the License.
group-Avnet 0:8ef17b8b7104 147
group-Avnet 0:8ef17b8b7104 148