endPacket call kills Serial.println

If I use the endPacket function to send my payload then the Serial.println function no longer sends data out on the USB serial port to the computer. The payload does however reach the Sigfox backend. Used the most simplest of code to pinpoint this fault - see 2x code snippets below

This does NOT work.
void loop() {
SigFox.begin();
SigFox.beginPacket();
SigFox.print("123456789012");
int ret = SigFox.endPacket();
if (ret == 1)
Serial.println("OK");
else
Serial.println("KO");
while (1);
}

This works:
void loop() {
SigFox.begin();
SigFox.beginPacket();
SigFox.print("123456789012");
//int ret = SigFox.endPacket();
int ret = 1;
if (ret == 1)
Serial.println("OK");
else
Serial.println("KO");
while (1);
}

Shouldn't it be :

int ret = SigFox.endPacket(true);

Some example I have seen have the 'true' passed to endPacket but the Reference library does not mention it as a parameter. I tried passing the 'true' and it makes no difference

Solved. Need to call SigFix.Debug(). Luckily someone's example had a comment saying that this disables all power saving.

Dears

I'm also having issues by using the SigFox.beginPacket() / SigFox.print() / SigFox.endPacket() functions.
First of all, I confirm activating the debug mode with SigFox.debug() unlock somewhere (where ?!) the sending of my datas. Unfortunately as said on the description here it disable the power saving features.
Next, using SigFox.endPacket() with true as argument also allow me to have better results on the Sigfox backend. It could be find if the documentation could be updated.

Another issue for me regarding this function is about the result.
The online doc here talks about returning 1 if success but I always get 0 even if my data is correctly sent to the backend.

Any help would be very welcome as the documentation seems to be not related to the current library.
Any link to a github source code would be also appreciated :slight_smile:

Olivier

So nice,

Looking after the SigFox.h for the endPacket() function that calls the send() :

/*

  • Send an array of bytes (max 12 bytes long) as message to SIGFOX network
  • Return SIGFOX status code
    */

Then statusCode(SIGFOX) returns 0 if everything goes fine as explained here so it's just a documentation issue.

Regarding the argument of int endPacket(bool rx = false); it is directly passed as a parameter of the internal send() function.
Wthin send() i see :
if (rx) {
spi_port.transfer(0x0E);
} else {
spi_port.transfer(0x0D);
}

ATM I'm not able to identify the impact of calling spi_port.transfer with 0x0E.
I presume somewhere it ask the board to listen for incomming ack message as it now appears close to my message within the Sigfox backend the acknowledge status.

Olivier

Hi,
the issue is caused by a bad interaction within SigFox library, LowPower Library and USB/Serial USB.

When SigFox library is not in debugging mode, LowPower functions are invoked in SIGFOXClass::send (lines 162 to 170 at SigFox.cpp).

When Serial connection is made via MKRFOX1200's USB port, LowPower library messes up with USB and Serial USB therefore SIGFOXCLASS:send will never return and your code will get stuck at Sigfox.endPacket().

In order to enable MKRFOX1200 to use LowPower mode you need to disconnect the USB Serial Port (use it just for programming). If you still want to get messages via serial port you need to use Hardware Serial port (pins 13-14 and Serial1 in code). Take a look at SigFoxEventTrigger example for more information.

With this small changes you should get your MKRFOXes running smoothly in low power mode and sending (debugging) messages on hardware serial port.

Hope this helps.

Hi @manchoz

Really really helpful, many thanks :slight_smile: appreciated
Now it's time for me to enjoy the code !!

Olivier

Same problem here, thx for the solutions

With debug enabled it goes fine.

Also tried with debug disabled and USB disconnected (running on 2 AA batteries), but it seems that the problem stays.

Is it needed to explicit disable the serial connection in the code?

No,
in my experience, it's not needed.

Try disconnecting cable first and then connect/power on batteries.

Be sure also that other non-trivial modules/sensors (eg DHT11/22) will get a proper powering cycle, too: MKRFOX1200 will also get stuck at SigFox.endPacket() if something else is using/messing with interrupts.

I don't see my problem. I detached the USB cable before connecting the batteries.
Here you can find my code. I use the onboard LED to test my code, so I don't need any serial communication. I wrote the "blinkin()" funtion to light up the LED a given number of times (second variable). The code stops after the LED lights up 5 times and a message was send. So my code stops at line 76 (int result = SigFox.endPacket(true);). So it indicates that the problem is still in the endPacket() function.

01 /*
02 SigFox send message.
03 /
04
05 #include <SigFox.h>
06 #include <ArduinoLowPower.h>
07
08 // Wait x (first number) minutes
09 unsigned long timeBetweenMessages = 1 * 60 * 1000;
10 bool debugViaLedFull = true;
11 bool debugViaLedSend = false;
12 bool debugViaLedSetup = false;
13 bool sigfoxDebug = false;
14 int messageCounter = 0;
15
16 void setup() {
17 // On MKRFOX1200 the onboard LED is connected to D6
18 pinMode(6, OUTPUT);
19 // Reset Sigfox module
20 SigFox.reset();
21 delay(1000);
22 // Start the module
23 if (!SigFox.begin()) {
24 // Something is really wrong, try rebooting
25 // Reboot is useful if we are powering the board using an unreliable power source
26 // (eg. solar panels or other energy harvesting methods)
27 reboot();
28 }
29 // Wait at least 30mS after first configuration (100mS before)
30 delay(100);
31 if (sigfoxDebug) SigFox.debug();
32 // Shut down module, back to standby
33 SigFox.end();
34 // Blink when setup is ready
35 if (debugViaLedSetup or debugViaLedFull) blinking(100,2);
36 }
37
38 /
Main loop /
39 void loop()
40 {
41 if (debugViaLedFull) blinking(300,1);
42 messageCounter = messageCounter+1;
43 String TextToSend = "VNP" + SigFox.ID() + String(messageCounter);
44 sigfoxSend(TextToSend);
45 if (sigfoxDebug) {
46 delay(timeBetweenMessages);
47 } else {
48 LowPower.sleep(timeBetweenMessages);
49 }
50 if (debugViaLedFull) blinking(300,8);
51 }
52
53 /
Funtion to send messages over Sigfox /
54 void sigfoxSend(String str) {
55 // the software has 3 attempts to transmit the packet
56 int retransmitNeeded = 3;
57 while (retransmitNeeded > 0) {
58 if (debugViaLedFull) blinking(300,2);
59 // Start the module
60 if (!SigFox.begin()) {
61 // Something is really wrong, try rebooting
62 // Reboot is useful if we are powering the board using an unreliable power source
63 // (eg. solar panels or other energy harvesting methods)
64 reboot();
65 }
66 // Wait at least 30mS after first configuration (100mS before)
67 delay(100);
68 // Clears all pending interrupts
69 SigFox.status();
70 delay(1);
71 if (debugViaLedSend or debugViaLedFull) blinking(300,3);
72 SigFox.beginPacket();
73 if (debugViaLedFull) blinking(300,4);
74 SigFox.print(str);
75 if (debugViaLedFull) blinking(300,5);
76 int result = SigFox.endPacket(true);
77 if (debugViaLedFull) blinking(300,6);
78 // shut down module, back to standby
79 SigFox.end();
80 if (result == 0) {
81 // OK - the packet was sent successfully
82 retransmitNeeded = 0;
83 if (debugViaLedSend or debugViaLedFull) blinking(1000,2);
84 } else {
85 // KO - there was an error
86 retransmitNeeded = retransmitNeeded-1;
87 if (debugViaLedSend or debugViaLedFull) blinking(300,7);
88 // Reset Sigfox module
89 SigFox.reset();
90 // Wait 15 minutes before resend
91 LowPower.sleep(15
601000);
92 }
93 }
94 }
95
96 /
Funtion to use the onboard LED for debug /
97 /
Parameters: - upTime: number of ms the LED is up /
98 /
- xTimes: number of blinks /
99 void blinking(unsigned long upTime,int xTimes) {
100 delay(3000);
101 for (int x = 0; x<xTimes; x++) {
102 digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
103 delay(upTime); // wait for [upTime] ms
104 digitalWrite(6, LOW); // turn the LED off by making the voltage LOW
105 delay(upTime); // wait for [upTime] ms
106 }
107 }
108
109 /
Reboot */
110 void reboot() {
111 NVIC_SystemReset();
112 while (1) ;
113 }

Hi,

pietervannuffel:
So my code stops at line 76 (int result = SigFox.endPacket(true))

Just notice that passing true to SigFox.endPacket() will made the SigFox API wait for a response from the SigFox server (which in turn will respond directly or will wait a response from a BIDIR callback).

What happens without true?

Eventually, SigFox.endPacket() will timeout after 60 seconds... maybe you just need to wait a little more to see next blinks?

I removed the "true" parameter, result was the same.

I think the code hangs, because I don't get any blinks anymore. Also not after waiting very long.

I also don't get any messages anymore after receiving the first one.

This is the information of the message that I received:

MessageCounter: 1

BoardID: FFFFFFFF
String: VNP
alarmID:
device: 18BC8E
time: 1496267791
duplicate: false
snr: 38.53
station: 063F
data: 564e50464646464646464631
avgSnr: 35.11
lat: 51.0
lng: 4.0
rssi: -113.00
seqNumber: 586

It also surprises me that there is "BoardID: FFFFFFFF" in the message. With debugging enabled, I received "BoardID: 0018BC8E".
This is a result of "String TextToSend = "VNP" + SigFox.ID() + String(messageCounter);". The boardID comes from the SigFox.ID() function. So there is also something weird with the SigFox.ID() function when sigfox.debug() is not active.

Any new evolutions on this topic?