I have been following a tutorial to send data to a Firebase database using Arduino.
I am using an Arduino Uno WiFi Rev2, below is the code that simply connects to the WiFi and then sends data to Firebase.
I have previously had success pinging websites with this Arduino using the WiFiNINA library, so assumed that this Firebase WiFiNINA library should work too.
#include <Arduino_LSM6DS3.h>
#include <Firebase_Arduino_WiFiNINA.h>
#define FIREBASE_HOST "compost-app-4a252.firebaseio.com"
#define FIREBASE_AUTH "QKaV81CbgJcnN5zI8mSwpzkoHcWmNIVZyRv1H4dM"
#define WIFI_SSID "VM7923466 2.4GHz"
#define WIFI_PASSWORD "mrRkhbxj5smt"
FirebaseData firebaseData;
String path = "/IMU_LSM6DS3";
String jsonStr;
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println();
Serial.print("Initialize IMU sensor…");
if (!IMU.begin()) {
Serial.println(" failed!");
while (1);
}
Serial.println(" done");
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
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()
{
float x, y, z;
// Read IMU acceleration data
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
// Send data to Firebase with specific path
if (Firebase.setFloat(firebaseData, path + "/1-setFloat/X", x)) {
Serial.println(firebaseData.dataPath() + " = " + x);
}
if (Firebase.setFloat(firebaseData, path + "/1-setFloat/Y", y)) {
Serial.println(firebaseData.dataPath() + " = " + y);
}
if (Firebase.setFloat(firebaseData, path + "/1-setFloat/Z", z)) {
Serial.println(firebaseData.dataPath() + " = " + z);
}
// Push data using pushJSON
jsonStr = "{\"X\":" + String(x,6) + ",\"Y\":" + String(y,6) + ",\"Z\":" + String(z,6) + "}";
if (Firebase.pushJSON(firebaseData, path + "/2-pushJSON", jsonStr)) {
Serial.println(firebaseData.dataPath() + " = " + firebaseData.pushName());
}
else {
Serial.println("Error: " + firebaseData.errorReason());
}
Serial.println();
delay(2000);
}
}
However when I Upload my code, I get the following error: (included the relevant parts)
Arduino: 1.8.16 (Windows 10), Board: "Arduino Uno WiFi Rev2, None (ATMEGA4809)"
...
firebase_test:37:20: error: 'WL_CONNECTED' was not declared in this scope
while (status != WL_CONNECTED) {
...
firebase_test:43:18: error: 'WiFi' was not declared in this scope
Serial.println(WiFi.localIP());
...
exit status 1
'WL_IDLE_STATUS' was not declared in this scope
Telling me that a bunch of values and 'WiFi' are not declared in the scope.
-
Previously when using the The WiFiNINA library, these values were not declared and just recognised as globals.
-
The exact code I am using seems to have been used by others on the same Arduino so I am assuming my issue is something to do with the installed libraries.
Any help is massively appreciated!