Skip to content

Commit 2244064

Browse files
Added basic arduino async send example
1 parent d3cdce8 commit 2244064

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include "rockblock_9704.h"
2+
3+
/**
4+
* This sketch sends a "Hello World!" message via the RB9704.
5+
*
6+
* A serial connection (on Serial1) will first be attempted, if successful a request to
7+
* que the message will be issued (note: this will fail if the RB9704 is not provisioned
8+
* for the specified topic). We then setup our 4 user defined callbacks to get message provisioning,
9+
* check if our queued messages have sent, check if we received any messages and finally check the
10+
* signal strength. The script will call rbPoll() every time it loops, it is important that this is done
11+
* quite frequently (10ms in this example) as that function is responsible for listening to all the replies
12+
* from the modem. Finally the script will end the connection gracefully once the message has been sent.
13+
*
14+
* Requirements:
15+
* RB9704 needs to be provisioned for messaging topic 244.
16+
* RB9704 needs to be wired to the RX and TX pins of Serial1 (In this example we set those to be pins 21 & 22 respectively).
17+
* Have an open view of the sky where a good signal can be obtained.
18+
*
19+
*/
20+
21+
int messagesSent = 0;
22+
23+
void onMessageProvisioning(const jsprMessageProvisioning_t *messageProvisioning)
24+
{
25+
if(messageProvisioning->provisioningSet == true)
26+
{
27+
Serial.print("Device is provisioned for ");
28+
Serial.print(messageProvisioning->topicCount);
29+
Serial.println(" topics");
30+
Serial.println("Provisioned topics:");
31+
for(int i = 0; i < messageProvisioning->topicCount; i++)
32+
{
33+
Serial.print("Topic name: ");
34+
Serial.print(messageProvisioning->provisioning[i].topicName);
35+
Serial.print(", Topic number: ");
36+
Serial.println(messageProvisioning->provisioning[i].topicId);
37+
}
38+
}
39+
}
40+
41+
void onMoComplete(const uint16_t id, const rbMsgStatus_t status)
42+
{
43+
Serial.print("MO Complete: ID = ");
44+
Serial.print(id);
45+
Serial.print(", Status = ");
46+
Serial.println(status);
47+
if(status == RB_MSG_STATUS_OK)
48+
{
49+
messagesSent += 1;
50+
Serial.print("Message Sent: ");
51+
Serial.println(messagesSent);
52+
}
53+
}
54+
55+
void onMtComplete(const uint16_t id, const rbMsgStatus_t status)
56+
{
57+
Serial.print("MT Complete: ID = ");
58+
Serial.print(id);
59+
Serial.print(", Status = ");
60+
Serial.println(status);
61+
}
62+
63+
void onConstellationState(const jsprConstellationState_t *state)
64+
{
65+
Serial.print("Current Signal: ");
66+
Serial.println(state->signalBars);
67+
}
68+
69+
void setup() {
70+
Serial.begin(9600);
71+
Serial1.begin(230400, SERIAL_8N1, 21, 22);
72+
delay(1000);
73+
Serial.println("Starting\r\n");
74+
if(rbBegin("Serial1"))
75+
{
76+
delay(1000);
77+
rbCallbacks_t myCallbacks =
78+
{
79+
.messageProvisioning = onMessageProvisioning,
80+
.moMessageComplete = onMoComplete,
81+
.mtMessageComplete = onMtComplete,
82+
.constellationState = onConstellationState
83+
};
84+
//Register Callbacks
85+
rbRegisterCallbacks(&myCallbacks);
86+
Serial.println("Successfully started serial session with RB9704\r\n");
87+
//Queue and send MO
88+
const char *message = "Hello World!";
89+
if(rbSendMessageAsync(244, message, strlen(message)))
90+
{
91+
Serial.print("Sent MO: ");
92+
Serial.println(message);
93+
}
94+
else
95+
{
96+
Serial.println("Failed to queue message\r\n");
97+
}
98+
}
99+
else
100+
{
101+
Serial.println("Failed to begin the serial connection\r\n");
102+
}
103+
104+
while(true)
105+
{
106+
rbPoll();
107+
delay(10);
108+
109+
if(messagesSent > 0)
110+
{
111+
//End serial connection
112+
if(rbEnd())
113+
{
114+
Serial.println("Ended connection successfully\r\n");
115+
Serial1.end();
116+
break;
117+
}
118+
else
119+
{
120+
Serial.println("Failed to end connection\r\n");
121+
}
122+
}
123+
}
124+
}
125+
126+
void loop() {
127+
128+
}

examples/ArduinoBasicSendandReceive/ArduinoBasicSendandReceive.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void loop() {
6666
//End serial connection
6767
if(rbEnd())
6868
{
69-
Serial.println("Ended connection sucessfully\r\n");
69+
Serial.println("Ended connection successfully\r\n");
7070
Serial1.end();
7171
ended = true;
7272
}

0 commit comments

Comments
 (0)