hi guys,
first of all, i love your tutorials and I’m now using esp32 and esp8266 thanks to you! thanks for the great work:)
I’m trying to do the tutorial (chapter 3.3) on the ebook with a MLX90614 temperature sensor (I don’t have any BME280 around).
Everything works perfectly for one of the two values that I am trying to send (one for object temperature and one for ambient temperature) the second value is not consistent and returns numbers out of range (like: 1037.54993). I have a test sketch to test the sensor (without firebase) and it works good.
Am I missing something? can you help with that?
thanks a lot!
here is the code I am using:
question RNT – Pastebin.com
or -
Start your code here
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MLX90614.h>
#include <Wire.h>
#include <SPI.h>
…
// Define Firebase objects
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
// Variable to save USER UID
String uid;
// Variables to save database paths
String databasePath;
String ambientTempPath;
String objectTempPath;
//String presPath;
// MLX90614 sensor
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
float ambientTemp;
float objectTemp;
// Timer variables (send new readings every three minutes)
unsigned long sendDataPrevMillis = 0;
unsigned long timerDelay = 10000; //180000
// Initialize WiFi
void initWiFi()
{
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“Connecting to WiFi ..”);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(‘.’);
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.println();
}
// Write float values to the database
void sendFloat(String path, float value)
{
if (Firebase.RTDB.setFloat(&fbdo, path.c_str(), value))
{
Serial.print(“Writing value: “);
Serial.print(value);
Serial.print(” on the following path: “);
Serial.println(path);
Serial.println(“PASSED”);
Serial.println(“PATH: ” + fbdo.dataPath());
Serial.println(“TYPE: ” + fbdo.dataType());
}
else
{
Serial.println(“FAILED”);
Serial.println(“REASON: ” + fbdo.errorReason());
}
}
void setup()
{
Serial.begin(115200);
// Initialize sensor
mlx.begin();
initWiFi();
// Assign the api key (required)
config.api_key = API_KEY;
// Assign the user sign in credentials
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
// Assign the RTDB URL (required)
config.database_url = DATABASE_URL;
Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);
// Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
// Assign the maximum retry of token generation
config.max_token_generation_retry = 5;
// Initialize the library with the Firebase authen and config
Firebase.begin(&config, &auth);
// Getting the user UID might take a few seconds
Serial.println(“Getting User UID”);
while ((auth.token.uid) == “”)
{
Serial.print(‘.’);
delay(1000);
}
// Print user UID
uid = auth.token.uid.c_str();
Serial.print(“User UID: “);
Serial.println(uid);
// Update database path
databasePath = “/UsersData/” + uid;
// Define database path for sensor readings
ambientTempPath = databasePath + “/sensor/ambientTemp”; // –> UsersData/<user_uid>/sensor/ambientTemp
objectTempPath = databasePath + “/sensor/objectTemp”; // –> UsersData/<user_uid>/sensor/objectTemp
}
void loop()
{
// Send new readings to database
if (Firebase.ready() && (millis() – sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0))
{
sendDataPrevMillis = millis();
// Get latest sensor readings
objectTemp = mlx.readObjectTempC();
ambientTemp = mlx.readAmbientTempC();
// Send readings to database:
sendFloat(objectTempPath, objectTemp);
sendFloat(ambientTempPath, ambientTemp);
}
}
Hi.
That’s weird. If you print the values on the Serial Monitor, what do you get? The same issue?
Regards,
Sara
yes, on the serial monitor I get the same values…And I tried other sensors without any problem.
I can’t find any typo that would explain the bug.
Hi.
I’m not sure. Maybe it is some incompatibility between the Adafruit Library you use for the sensor and the Firebase Client Library.
For example, I wasn’t able to get valid readings from a DHT sensor (with the ADafruit library) and use Firebase Client simultaneously.
Regards,
Sara