Skip to content

Commit 6deddbf

Browse files
committed
Improve SendBoolean example
1 parent e11db72 commit 6deddbf

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

examples/SendBoolean/SendBoolean.ino

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1+
/*
2+
SigFox Send Boolean tutorial
3+
4+
This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKRFox1200.
5+
If the application only needs to send one bit of information the transmission time
6+
(and thus power consumption) will be much lower than sending a full 12 bytes packet.
7+
8+
This example code is in the public domain.
9+
*/
10+
111
#include <SigFox.h>
2-
#define VALUE_TO_SEND 1
12+
13+
// We want to send a boolean value to signal a binary event
14+
// like open/close or on/off
15+
16+
bool value_to_send = true;
17+
318
#define DEBUG 1
19+
420
void setup() {
521

622
if (DEBUG){
723
Serial.begin(9600);
824
while (!Serial) {};
925
}
1026

27+
// Initialize the SigFox module
1128
if (!SigFox.begin()) {
1229
if (DEBUG){
1330
Serial.println("Sigfox module unavailable !");
1431
}
1532
return;
1633
}
34+
35+
// If we wanto to debug the application, print the device ID to easily find it in the backend
1736
if (DEBUG){
1837
SigFox.debug();
1938
Serial.println("ID = " + SigFox.ID());
2039
}
40+
2141
delay(100);
22-
int ret = SigFox.sendBit(VALUE_TO_SEND);
42+
43+
// Compose a message as usual; the single bit transmission will be performed transparently
44+
// if the data we want to send is suitable
45+
SigFox.beginPacket();
46+
SigFox.write(value_to_send);
47+
int ret = SigFox.endPacket();
48+
2349
if (DEBUG){
2450
Serial.print("Status : ");
2551
Serial.println(ret);

0 commit comments

Comments
 (0)