Hi, I and my team are making a library to use LoRa in an IoT project. The project involves several measuring devices sending Strings (it contains a json with data) to a master device (named bridge), in the tests we use the Heltec WiFi LoRa 32 (V2) board. When the bridge receives a message it may, sporadically, print an error message on the serial. This occurs at some point in the process, we do not identify an exact point or a specific frequency for the error to occur.
Code:
/*
a simple bridge code using the default config:
(timeout = 500 ms / txPower = 20 dBm / PaBoost = false / frequência = 915 MHz)
*/
#include <UnifyBridge.h> //Include the library
#include "env.h" //include a file with the WiFi SSID and password and also the HTTP server url (for testing only)
#include <SPIFFS.h>
#include <FS.h>
int httpCode;
const uint8_t localAddress = 1; //address of this device
UnifyBridge bridge(localAddress); //declares the UnifyBridge class object
//SPIFFS functions:
int listDir() { //return number of files
File root = SPIFFS.open("/");
if (!root) { return -1; } //Open the "directory" where the files are in SPIFFS and check if there is a failure, if so it returns -1.
File file = root.openNextFile(); //Reports the next file in the "directory" and passes the return to the File type variable.
int qtdFiles = 0; //variable that stores the number of files in the specified directory.
while (file) { //As long as there are files in the "directory" that have not been seen, execute the while loop.
qtdFiles++;
file = root.openNextFile();
}
file.close(); // close the last file
return qtdFiles;
}
String readFile(String path) {
String content;
File file = SPIFFS.open(path); //Opens the SPIFFS file path and passes the return to a variable of type File.
if (!file) return ""; //If there is a failure to open the path, it returns an empty String.
while (file.available()){ //As long as there are any bytes available for reading the file, it executes the reading.
char caractere = file.read();
content += caractere;
}
file.close();
return content; // return the content
}
bool writeFile(String path, String message) {
File file = SPIFFS.open(path, FILE_WRITE); //Opens the file in writing mode and passes the return to a variable of type File.
if (!file) { return false; } //If there is a failure to open the path, it returns false
if (!file.print(message)) { return false; } //If writing the file with its content gives an error, it returns false
file.close();
return true;
}
bool deleteFile(String path) {
if (SPIFFS.remove(path)) { return true; } //deletes the file passing the path/name (path). If the deletion is successful, returns true
return false; //if there is an error, return false
}
void setup() {
Serial.begin(115200);
Serial.println("Starting bridge…");
bridge.begin(BRIDGE, SSID, password); //start the bridge
pinMode(LED_BUILTIN, OUTPUT);
Serial.print("connected to the network: ");
Serial.println(SSID);
Serial.println("setting server...");
bridge.addServer(serverN);
Serial.println("entrando em void loop...");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
SPIFFS.begin(); //start SPIFFS
}
void loop() {
String json; //String that will store received json.
//wait a message
if(bridge.receiveLoRa()){
digitalWrite(LED_BUILTIN, HIGH);
json = bridge.getMessage();
Serial.println("message: " + json); //print the message on the serial monitor
Serial.print("RSSI: " + String(bridge.getRSSI())); //print RSSI on the serial monitor
Serial.print("| Json error: " + bridge.getError() + " | "); //print message json error on serial monitor
bridge.sendResponse(bridge.montarJson()); //responds to a message reporting an error in a json assembled for this type of communication
if(bridge.getError() == "Ok"){
//checks if the json is intact
Serial.println("Json is intact");
if(bridge.isConnected()){
httpCode = bridge.postHTTP(json);
// HTTP header has been send and Server response header has been handled
Serial.print("[HTTP] POST code: ");
Serial.println(httpCode);
}else{
Serial.println("WiFi is not connected");
String dir = "/data/" + String(listDir() + 1) + ".txt"; //creates file based on the number of files in the directory in ascending order
Serial.println("Store data in: " + dir);
writeFile(dir, json);
}
}else{
Serial.println("Json is not intact");
}
}else if(bridge.isConnected() && listDir() > 0){//check wifi and file usage on SPIFFS
String dir = "/data/" + String(listDir()) + ".txt";
String Content = readFile(dir);
Serial.println("Posting content from: " + dir);
httpCode = bridge.postHTTP(Content);
// HTTP header has been send and Server response header has been handled
Serial.print("[HTTP] POST code: ");
Serial.println(httpCode);
if(httpCode > 199 && httpCode < 300){
deleteFile(dir);
}
}
//reading the serial to access SPIFFS
if(Serial.available() > 0){
char incomingByte = Serial.read();
switch (incomingByte){
case 'p': //lowercase p to print all files
for(int i = listDir(); i > 0; i--){
String dir = "/data/" + String(i) + ".txt";
String Content = readFile(dir);
Serial.println("============================================================================================");
Serial.println();
Serial.print("Content from : ");
Serial.println(dir);
Serial.println(Content);
Serial.println();
}
break;
case 'd': //lowercase d to delete all files
for(int i = listDir(); i > 0; i--){ //if there is, send it in a loop until there is none left
String dir = "/data/" + String(i) + ".txt";
if(deleteFile(dir)){
Serial.print(dir);
Serial.println("was deleted");
}else{
Serial.print(dir);
Serial.println("was not deleted because of an error");
}
}
break;
case 'f': //lowercase f to format
Serial.println("formatting SPIFFS...");
SPIFFS.format();
Serial.println("SPIFFS Formated!");
break;
}
}
digitalWrite(LED_BUILTIN, LOW);
delay(10);
}
Error:
assert failed: xQueueSemaphoreTake queue.c:1554 (!( ( xTaskGetSchedulerState() == ( ( BaseType_t ) 0 ) ) && ( xTicksToWait != 0 ) ))
Backtrace: 0x4008383d:0x3ffbf27c |<-CORRUPTED
ELF file SHA256: 61b4cca081570768
After the error the board restarts automatically. UnifyBridge contains the libraries RH_RF95 e RHmesh (part of Radiohead library), WiFi.h, ArduinoJson, HTTPclient and SPI.
The error appears to be related to an assertion failure during code execution. The message indicates that the failure occurred in the xQueueSemaphoreTake function in the queue.c file, line 1554, a FreeRTOS component. The failed assertion is checking some conditions related to the state of the task scheduler and the waiting time. It appears that the assertion is being violated, which may indicate an unexpected condition in the program's execution flow.
When trying to locate the queue.c file in the Arduino IDE folders we were unable to find it, only similar ones with the .h extension or no extension. And these files do not have the long-awaited line 1554, when it exists it does not have the xQueueSemaphoreTake function.
When trying to locate the queue.c file in the Arduino IDE folders we were unable to find it, only similar ones with the .h extension or no extension. And these files do not have the long-awaited line 1554, when it exists it does not have the xQueueSemaphoreTake function.
When doing a test on another example without using SPIFFS (last functionality to be added) I don't get the same error, I can't simply remove SPIFFS as it is a fundamental part of the project since we are avoiding the use of SD card modules . This error compromises the functioning of the device and our development as there are more features to be included in our device, all of which are strictly necessary.
We need help with this, we don't have much idea what to do