mobizt / Firebase-Arduino-WiFiNINA

Firebase Arduino Library for ARM/AVR WIFI Dev Boards based on WiFiNINA
MIT License
65 stars 12 forks source link

Firebase.deleteNode strange behavior #24

Closed ChahlaWissam closed 3 years ago

ChahlaWissam commented 3 years ago

Hello, I am facing a strange behavior with the Firebase.deleteNode function. Firebase_Arduino_WiFiNINA.h library version 1.1.4

I want to delete a node at a certain path in a firebase realtime database , and created the following function.

void deleteFBNode(String nodePath) {

       Serial.println ("Delete Update Node Received ...");

       Serial.println (" Deleting at:" + nodePath);

        if ( Firebase.deleteNode(firebaseData,nodePath))
           {Serial.println ("Successfully deleted node at:");
             Serial.println (nodePath);}
       else
         {Serial.println ("Error deleteing data at:");
          Serial.println (nodePath);
          Serial.println(firebaseData.errorReason());}  

}

if i call this function from the void setup () section , it works well and deletes the node. while if i call it from the void loop() section based on a trigger condition, it doesn't delete the node and it returns a "Successfully deleted node at:" ... the path provided.

the same nodePath value is passed to the function , and i tested it with passing a constant string value as a nodePath value.

Appreciate any input on this matter.

Regards

mobizt commented 3 years ago

As I reply your email, this is not the issue as you can use any function in loop without problem.

Delete is just a simple function as get function, nothing is special as it use HTTP delete request.

You should debug by yourself first and if you can't find solution, you may need to create test example code which clean and clear and keep minimum that can reproduce the issue and post here.

mobizt commented 3 years ago

This is the test example that works without problem


#include "Firebase_Arduino_WiFiNINA.h"

#define FIREBASE_HOST "xxxxxxxxxxxxxxxxxxxxxxx"
#define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxx"
#define WIFI_SSID "xxxxxxxxxxxxxxxxxx"
#define WIFI_PASSWORD "xxxxxxxxxxxxxxx"

//Define Firebase data object
FirebaseData firebaseData;

unsigned long prevMillis = 0;
int count = 0;

void setup()
{

  Serial.begin(9600);
  delay(100);
  Serial.println();

  Serial.print("Connecting to Wi-Fi");
  int status = WL_IDLE_STATUS;
  while (status != WL_CONNECTED)
  {
    status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  //Provide the autntication data
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH, WIFI_SSID, WIFI_PASSWORD);
  Firebase.reconnectWiFi(true);

}

void loop()
{

  if (millis() - prevMillis > 20) {
    prevMillis = millis();

    if (Firebase.setInt(firebaseData, "/test/int", count))
    {
      Serial.print("Set data ");
      Serial.print(count);
      Serial.println(" ok");
    } else {
      Serial.println("Set data failed, " + firebaseData.errorReason());
    }
    if (count >= 9)
    {
      count = 0;
      if (Firebase.deleteNode(firebaseData, "/tesst/int"))
      {
        Serial.println("Delete data ok");
      } else {
        Serial.println("Delete data failed, " + firebaseData.errorReason());
      }
    }

    count++;
  }
}

Serial printing result


Connecting to Wi-Fi.
Connected with IP: 192.168.1.111

Set data 0 ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok
Set data 1 ok
Set data 2 ok
Set data 3 ok
Set data 4 ok
Set data 5 ok
Set data 6 ok
Set data 7 ok
Set data 8 ok
Set data 9 ok
Delete data ok