Skip to content

Commit 9ba098f

Browse files
nicolscfacchinm
authored andcommitted
Add function to send a single bit (true | false) over the Sigfox network This uses a different SPI transaction (0x0B), and allows to send empty frames for basic applications such as buttons, door opening systems, ... Added a simple example called _SendBoolean_
Let me know if I need to structure this differently to fit with the lib architecture :)
1 parent 3f7ba75 commit 9ba098f

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <SigFox.h>
2+
#define VALUE_TO_SEND 1
3+
#define DEBUG 1
4+
void setup() {
5+
6+
if (DEBUG){
7+
Serial.begin(9600);
8+
while (!Serial) {};
9+
}
10+
11+
if (!SigFox.begin()) {
12+
if (DEBUG){
13+
Serial.println("Sigfox module unavailable !");
14+
}
15+
return;
16+
}
17+
if (DEBUG){
18+
SigFox.debug();
19+
Serial.println("ID = " + SigFox.ID());
20+
}
21+
delay(100);
22+
int ret = SigFox.sendBit(VALUE_TO_SEND);
23+
if (DEBUG){
24+
Serial.print("Status : ");
25+
Serial.println(ret);
26+
}
27+
}
28+
29+
void loop(){}

src/SigFox.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,48 @@ int SIGFOXClass::send(unsigned char mess[], int len, bool rx)
203203

204204
return sig;
205205
}
206+
int SIGFOXClass::sendBit(bool value){
207+
int ret;
208+
int i = 0;
209+
status();
206210

211+
digitalWrite(chip_select_pin, LOW);
212+
delay(1);
213+
spi_port.beginTransaction(SPICONFIG);
214+
215+
spi_port.transfer(0x0B);
216+
spi_port.transfer(value ? 1 : 0);
217+
spi_port.endTransaction();
218+
delay(1);
219+
digitalWrite(chip_select_pin, HIGH);
220+
221+
int timeout = 7000; //7 seconds
222+
223+
if (!debugging) {
224+
LowPower.attachInterruptWakeup(interrupt_pin, NULL, FALLING);
225+
LowPower.sleep(timeout);
226+
if (digitalRead(interrupt_pin) == 0) {
227+
status();
228+
return statusCode(SIGFOX);
229+
}
230+
}
231+
232+
for (i = 0; i < timeout/10; i++)
233+
{
234+
if (digitalRead(interrupt_pin) == 0) {
235+
status();
236+
return statusCode(SIGFOX);
237+
break;
238+
}
239+
else {
240+
digitalWrite(led_pin, HIGH);
241+
delay(50);
242+
digitalWrite(led_pin, LOW);
243+
delay(50);
244+
}
245+
}
246+
return 99; //default
247+
}
207248
int SIGFOXClass::beginPacket() {
208249
bool ret = (tx_buffer_index == -1);
209250
tx_buffer_index = 0;

src/SigFox.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class SIGFOXClass : public Stream
8282
template <typename T> inline size_t write(T val) {return write((uint8_t*)&val, sizeof(T));};
8383
using Print::write;
8484

85+
/*
86+
* Send a single bit (0 | 1) over the Sigfox network
87+
* Returns the status code from the Atmel Sigfox chipset
88+
**/
89+
int sendBit(bool value);
90+
8591
//makes no sense in Sigfox world
8692
void flush() {};
8793

0 commit comments

Comments
 (0)