Skip to content

Commit aaf8a00

Browse files
authored
Merge pull request TwilioDevEd#736 from TwilioDevEd/konopka-wireless
changed library in m2m_commands_wiolte.ino
2 parents 12364d4 + fec5c67 commit aaf8a00

File tree

1 file changed

+52
-54
lines changed

1 file changed

+52
-54
lines changed
Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
/*
22
Twilio Machine to Machine Commands Quickstart for the Seeed Studio Wio LTE
33
*/
4+
#include "wio_tracker.h"
45

5-
#include <WioLTEforArduino.h>
6-
#define INTERVAL (1000)
6+
/*
7+
Globals for receiving incoming Commands
8+
*/
9+
uint16_t newSMSNumber = -1;
10+
char receivedMessage[128];
711

8-
WioLTE Wio;
12+
/*
13+
Create a Wio instance
14+
*/
15+
WioTracker wio = WioTracker();
916

1017
void setup() {
11-
SerialUSB.println("");
12-
SerialUSB.println("--- START ---------------------------------------------------");
13-
1418
/*
15-
Seeed Studio Wio LTE setup
19+
Modem setup
1620
*/
17-
SerialUSB.println("### I/O Initialize");
18-
Wio.Init();
19-
20-
SerialUSB.println("### Power supply ON");
21-
Wio.PowerSupplyLTE(true);
22-
delay(500);
21+
wio.Power_On();
22+
SerialUSB.println("Power On!");
23+
SerialUSB.println("Start network registration...");
2324

24-
SerialUSB.println("### Turn on or reset");
25-
if (!Wio.TurnOnOrReset()) {
26-
SerialUSB.println("### ERROR! ###");
25+
/*
26+
Network registration
27+
*/
28+
if (!wio.waitForNetworkRegister())
29+
{
30+
SerialUSB.println("Network error");
2731
return;
32+
} else {
33+
SerialUSB.println("Network registration complete");
2834
}
29-
delay(3000);
30-
31-
SerialUSB.println("### Setup completed");
32-
delay(3000);
35+
36+
/*
37+
Set all "REC UNREAD SMS" to "REC READ SMS"
38+
*/
39+
wio.readAllRecUnreadSMS();
3340

3441
/*
3542
Keep `command` under 160 ASCII characters, or 67 UCS-2 characters.
3643
https://www.twilio.com/docs/glossary/what-sms-character-limit
3744
*/
38-
SerialUSB.println("### Sending Command");
45+
SerialUSB.println("Sending Command");
3946
char message[128] = "Hello from the Wio LTE!";
4047

4148
/*
@@ -44,46 +51,37 @@ void setup() {
4451
4552
Write a Twilio M2M command.
4653
*/
47-
if (!Wio.SendSMS("2936", message)) {
48-
SerialUSB.println("### ERROR! ###");
49-
return;
54+
if (wio.sendSMS("2936", message))
55+
{
56+
SerialUSB.println("Command Sent");
57+
}
58+
else
59+
{
60+
SerialUSB.println("Send Error");
5061
}
51-
SerialUSB.println("### Command Sent");
52-
delay(3000);
53-
SerialUSB.println("### Waiting for Command");
62+
SerialUSB.println("Waiting for Command");
5463
}
5564

5665
void loop() {
57-
while (true) {
66+
/*
67+
Detect unread Commands
68+
*/
69+
int id = wio.detectRecUnreadSMS();
5870

59-
char str[100];
71+
/*
72+
Define the index of the incoming Commands
73+
*/
74+
if (-1 != id) {
75+
newSMSNumber = id;
6076

6177
/*
62-
Read a Twilio M2M command. Note that it will find the lowest
63-
indexed one with the code as is; in your code. if you cache the
64-
index you can start the next read_command to move to the next one.
78+
Read a Twilio M2M command. Note that it will find the lowest
79+
indexed one with the code as is; in your code. if you cache the
80+
index you can start the next read_command to move to the next one.
6581
*/
66-
int strLen = Wio.ReceiveSMS(str, sizeof (str));
67-
68-
if (strLen < 0) {
69-
SerialUSB.println("### ERROR! ###");
70-
goto err;
71-
}
72-
73-
/* Receive command */
74-
if (strLen == 0) break;
75-
SerialUSB.println("### Command Received");
76-
77-
/* Print the command */
78-
SerialUSB.println(str);
79-
80-
/* Delete the stored command */
81-
if (!Wio.DeleteReceivedSMS()) {
82-
SerialUSB.println("### ERROR! ###");
83-
goto err;
84-
}
82+
wio.readSMS(newSMSNumber, receivedMessage, 128);
83+
SerialUSB.println("Command Received");
84+
SerialUSB.println(receivedMessage);
8585
}
86-
87-
err:
88-
delay(INTERVAL);
86+
delay(1000);
8987
}

0 commit comments

Comments
 (0)