mobizt / Firebase-Arduino-WiFiNINA

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

Bad Request Error (arduino uno wifi firebase) #23

Closed bellybubjoe closed 3 years ago

bellybubjoe commented 3 years ago

A friend and I are working on a coding project and we are using an Arduino Wifi Rev 2 to connect to firebase. As we were doing so, we ran into a bit of an issue, but we can't figure it out. So, we simplified our code into just the connection part of it. Still, when we run our code, the error "bad request" returns. Could you help us out?

#include <ArduinoJson.h>
#include <Firebase_Arduino_WiFiNINA_HTTPClient.h>
#include <Firebase_Arduino_WiFiNINA.h>
#define FIREBASE_HOST "https://arduino-nitrate-fb-v1-default-rtdb.asia-southeast1.firebasedatabase.app"
#define FIREBASE_AUTH "8hH7udfKry2GQcjBSd3Pr2g3XQCnpIcGD7kRERC8"
#define WIFI_SSID "Dr.Asg HT-2.4g"
#define WIFI_PASSWORD "amudhan12"
FirebaseData firebaseData;
String path = "/IMU_LSM6DS3";
String jsonData;

void setup()
{
  Serial.begin(9600);
  delay(1000);
  Serial.println();
  Serial.println(" done");
  Serial.print("Connecting to WiFi…");
  int status = WL_IDLE_STATUS;
  while (status != WL_CONNECTED) {
    status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print(".");
    delay(300);
  }
  Serial.print(" IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH, WIFI_SSID, WIFI_PASSWORD);
  Firebase.reconnectWiFi(true);
}

void loop()
{
  uploadData();
  delay(2000);
}

void uploadData()
{

  Serial.println(firebaseData.dataPath() + " = " + jsonData);
// Push data using pushJSON
  jsonData = "{\"parent_001\":\"parent 001 text\", \"parent 002\":{\"child_of_002\":123.456}}";
  if (Firebase.pushJSON(firebaseData, path + "/test/append", jsonData)) {
    Serial.println(firebaseData.dataPath()); //Should be "/test/append"
  //New created key/name
  Serial.println(firebaseData.pushName());
  //Absolute path of new appended data
    Serial.println(firebaseData.dataPath() + "/"+ firebaseData.pushName());
  }
  else {
    Serial.println("Error: " + firebaseData.errorReason());
  }   
}
mobizt commented 3 years ago

In the FIREBASE_HOST, the scheme e.g. https:// and trailing / must not be included, only arduino-nitrate-fb-v1-default-rtdb.asia-southeast1.firebasedatabase.app should be ok.

This library does not trim or handle the extras https:// and trailing slash in the url for you as in other my Firebase libraries to reduce the code size in limited flash space device.