Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions examples/SendBoolean/SendBoolean.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
SigFox Send Boolean tutorial

This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKRFox1200.
If the application only needs to send one bit of information the transmission time
(and thus power consumption) will be much lower than sending a full 12 bytes packet.

This example code is in the public domain.
*/

#include <SigFox.h>

// We want to send a boolean value to signal a binary event
// like open/close or on/off

bool value_to_send = true;

#define DEBUG 1

void setup() {

if (DEBUG){
Serial.begin(9600);
while (!Serial) {};
}

// Initialize the SigFox module
if (!SigFox.begin()) {
if (DEBUG){
Serial.println("Sigfox module unavailable !");
}
return;
}

// If we wanto to debug the application, print the device ID to easily find it in the backend
if (DEBUG){
SigFox.debug();
Serial.println("ID = " + SigFox.ID());
}

delay(100);

// Compose a message as usual; the single bit transmission will be performed transparently
// if the data we want to send is suitable
SigFox.beginPacket();
SigFox.write(value_to_send);
int ret = SigFox.endPacket();

if (DEBUG){
Serial.print("Status : ");
Serial.println(ret);
}
}

void loop(){}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ maintainer=Arduino LLC
sentence=Helper library for MKRFox1200 board and ATAB8520E Sigfox module
paragraph=This library allows some high level operations on Sigfox module, to ease integration with existing projects
category=Device Control
url=http://arduino.cc/libraries/Sigfox
url=https://www.arduino.cc/en/Reference/SigFox
architectures=samd
51 changes: 50 additions & 1 deletion src/SigFox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ int SIGFOXClass::begin(SPIClass& spi, int reset, int poweron, int interrupt, int
int SIGFOXClass::send(unsigned char mess[], int len, bool rx)
{
if (len == 0) return -1;

if (rx == false && len == 1 && mess[0] < 2) {
//we can use send_bit command

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolsc @facchinm will this change behaviour if the remote side is expecting a 0 or 1 in a single byte?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, on the backend, the received value becomes an uint8_t, it is only sent as a single bit at the physical layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @facchinm

It's purely protocol-related .

On the backend/callback side, it's handled as an standard payload & exposed as an hexadecimal string to convert back to original data types.

return sendBit(mess[0]);
}

status();

digitalWrite(chip_select_pin, LOW);
Expand Down Expand Up @@ -204,6 +210,49 @@ int SIGFOXClass::send(unsigned char mess[], int len, bool rx)
return sig;
}

int SIGFOXClass::sendBit(bool value){
int ret;
int i = 0;
status();

digitalWrite(chip_select_pin, LOW);
delay(1);
spi_port.beginTransaction(SPICONFIG);

spi_port.transfer(0x0B);
spi_port.transfer(value ? 1 : 0);
spi_port.endTransaction();
delay(1);
digitalWrite(chip_select_pin, HIGH);

int timeout = 7000; //7 seconds

if (!debugging) {
LowPower.attachInterruptWakeup(interrupt_pin, NULL, FALLING);
LowPower.sleep(timeout);
if (digitalRead(interrupt_pin) == 0) {
status();
return statusCode(SIGFOX);
}
}

for (i = 0; i < timeout/10; i++)
{
if (digitalRead(interrupt_pin) == 0) {
status();
return statusCode(SIGFOX);
break;
}
else {
digitalWrite(led_pin, HIGH);
delay(50);
digitalWrite(led_pin, LOW);
delay(50);
}
}
return 99; //default
}

int SIGFOXClass::beginPacket() {
bool ret = (tx_buffer_index == -1);
tx_buffer_index = 0;
Expand Down Expand Up @@ -588,4 +637,4 @@ void SIGFOXClass::end()
delay(1);
}

SIGFOXClass SigFox; //singleton
SIGFOXClass SigFox; //singleton
6 changes: 6 additions & 0 deletions src/SigFox.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ class SIGFOXClass : public Stream
*/
int send(unsigned char mess[], int len = 12, bool rx = false);

/*
* Send a single bit (0 | 1) over the Sigfox network
* Returns the status code from the Atmel Sigfox chipset
**/
int sendBit(bool value);

/*
* Return atm status message
*/
Expand Down