Closed JacobEPTechnologies421 closed 2 months ago
Hi @JacobEPTechnologies421 -- It seems like the issue you're experiencing is related to network connectivity rather than the Arduino Firebase library itself, as these errors typically occur with ESP devices due to DNS, socket, or SSL/TLS connection problems. I haven't encountered this specific issue before. Could you please share more details about the MCU and IDE you're using? Additionally, if possible, sharing your code would help in debugging the issue further.
Hi,
thank you for getting back to me! I am using VSC with esp idf 5.1.4 with esp32 c3 mini dev board,
the library takes so much in updating to database, well you can troubleshoot with the code below,
Firebase fb(REFERENCE_URL); String batteryCAN[8] = {}; String motorCAN[8] = {}; char batteryCANString[50]; bool dataReceived = false; // Flag to check if data is received
// Function to initialize the TWAI driver void initTwai(void) { twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(CAN_TX_GPIO, CAN_RX_GPIO, TWAI_MODE_NORMAL); twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
// Install TWAI driver
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
printf("Driver installed\n");
} else {
printf("Failed to install driver\n");
return;
}
// Start TWAI driver
if (twai_start() == ESP_OK) {
printf("Driver started\n");
} else {
printf("Failed to start driver\n");
return;
}
}
// Task to read CAN messages void readCAN(void *pvParameters) { while (true) { twai_message_t message; if (twai_receive(&message, pdMS_TO_TICKS(3000)) == ESP_OK) { printf("Message received\n");
// Handling the received message
switch (message.identifier) {
case 0x18205FE5: {
printf("Handling message with ID 18205FE5\n");
batteryCAN[0] = message.data[0];
batteryCAN[1] = message.data[1];
batteryCAN[2] = message.data[2];
batteryCAN[3] = message.data[3];
batteryCAN[4] = message.data[4];
batteryCAN[5] = message.data[5] * 10;
batteryCAN[6] = message.data[6] * 10;
batteryCAN[7] = message.data[7] * 10;
snprintf(batteryCANString, sizeof(batteryCANString), "%u %u %u %u %u %u %u %u",
message.data[0], message.data[1], message.data[2], message.data[3], message.data[4], message.data[5], message.data[6], message.data[7]);
printf("Concatenated String: %s\n", batteryCANString);
dataReceived = true; // Set the flag to indicate data is available
break;
}
case 0x18215FE5: {
printf("Handling message with ID 18215FE5\n");
motorCAN[0] = message.data[0];
motorCAN[1] = message.data[1];
motorCAN[2] = message.data[2];
motorCAN[3] = message.data[3];
motorCAN[4] = message.data[4];
motorCAN[5] = message.data[5] * 10;
motorCAN[6] = message.data[6] * 10;
motorCAN[7] = message.data[7] * 10;
dataReceived = true; // Set the flag to indicate data is available
break;
}
default: {
printf("Unknown message ID: %X\n", (unsigned int)message.identifier);
break;
}
}
} else {
printf("Failed to receive message\n");
}
}
vTaskDelay(pdMS_TO_TICKS(10));
}
// Task to push CAN data to Firebase void pushCAN(void *pvParameters) {
while (true) {
Serial.println("Call Started for push data at: ");
String timenow= fb.getString("DuCan/Saildrive/1200/Status/LastSeen");
Serial.println(timenow);
// Check if data is received and batteryCAN array is not empty,
if (dataReceived && sizeof(batteryCAN)!=0) {
fb.setInt("DuCan/Saildrive/1200/Status/Online", 1);
fb.setString("DuCan/Saildrive/1200/Status/LastSeen", timenow);
fb.setString("DuCan/Saildrive/1200/Battery/SOC", batteryCAN[0]);
fb.setString("DuCan/Saildrive/1200/Battery/HighestCellTemperature", batteryCAN[1]);
fb.setString("DuCan/Saildrive/1200/Battery/LowestCellTemperature", batteryCAN[2]);
fb.setString("DuCan/Saildrive/1200/Battery/HighestCellVoltage", batteryCAN[3]);
fb.setString("DuCan/Saildrive/1200/Battery/LowestCellVoltage", batteryCAN[4]);
fb.setString("DuCan/Saildrive/1200/Battery/rDCL", batteryCAN[5]);
fb.setString("DuCan/Saildrive/1200/Battery/rVoltage", batteryCAN[6]);
fb.setString("DuCan/Saildrive/1200/Battery/rCurrent", batteryCAN[7]);
fb.setString("DuCan/Saildrive/1200/Battery/LVVolatge", motorCAN[0]);
///////////////////////////////////////////////////////////////
//fb.setInt("DuCan/Saildrive/1200/Motor/Motor_RPM", motorCAN[1]);
fb.setString("DuCan/Saildrive/1200/Motor/Mototr_Current", motorCAN[2]);
fb.setString("DuCan/Saildrive/1200/Motor/Motor_Voltage", motorCAN[3]);
//fb.setInt("DuCan/Saildrive/1200/Motor/LegATemp", motorCAN[4]);
//fb.setInt("DuCan/Saildrive/1200/Motor/LegBTemp", motorCAN[5]);
//fb.setInt("DuCan/Saildrive/1200/Motor/LegCTemp", motorCAN[6]);
//fb.setInt("DuCan/Saildrive/1200/Motor/Motor_Temp1", motorCAN[7]);
printf("Pushed data to Firebase\n");
dataReceived = false; // Reset the flag after pushing data
}
else{
fb.setInt("DuCan/Saildrive/1200/Status/Online", 0);
printf("No data pushed to Firebase\n");
}
// Delay for 10 seconds
fb.setInt("DuCan/Saildrive/1200/Status/Online", 0);
vTaskDelay(pdMS_TO_TICKS(10000));
}
}
extern "C" void app_main(void) { initArduino(); Serial.begin(115200); Serial.println("Hello World");
// Set up WiFi
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
Serial.print("Connecting to: ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print("-");
delay(500);
}
Serial.println();
Serial.println("WiFi Connected");
// Initialize TWAI
initTwai();
// Create the FreeRTOS tasks
xTaskCreate(readCAN, "readCAN", 4096, NULL, 10, NULL);
xTaskCreate(pushCAN, "pushCAN", 4096, NULL, 8, NULL);
}
@JacobEPTechnologies421 -- The latency issue you are encountering can easily be solved if you update the library to version 1.0.1, which includes new methods: setJson(), pushJson(), getJson(). By replacing the individual setString() instances with one setJson() instance, you can avoid a lot of delay. Take a look at the JSON example code. Let me know if that solves your problem.
still the issue persits, [137857][E][NetworkClient.cpp:315] setSocketOption(): fail on 0, errno: 9, "Bad file number"--my internet connection is right as far as i can understand Int values are written with no issues but when i try to get string the issue rises up
is this something related to wificlinetsecure and esp32 is not defined
Hi @JacobEPTechnologies421 -- It could be an issue with WiFiClientSecure. You can place the following line under #include
This should raise an error if the code is getting into the correct if macro.
I am assuming the issue has been resolved. I'll go ahead and close this for now. If the problem persists or you have any other questions, feel free to reopen the issue or create a new one. Thanks!
Hi,
Im using this library to update a quite few items to the firebase RTDB, whenever I run the code i recive the message, [111354][E][NetworkClient.cpp:315] setSocketOption(): fail on 0, errno: 9, "Bad file number
or when I start the esp fresh I get this - [ 11086][E][NetworkManager.cpp:130] hostByName(): DNS Failed for 'dcan-e1c1c-default-rtdb.europe-west1.firebasedatabase.app' with error '-54' [ 29361][E][NetworkClientSecure.cpp:159] connect(): start_ssl_client: connect failed: -1
not sure on how to counter this, any help or is this normal?