• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Firebase WebApp with ESP8266, inconsistent readings

Q&A Forum › Category: ESP8266 › Firebase WebApp with ESP8266, inconsistent readings
0 Vote Up Vote Down
Joao Mendonça asked 4 years ago

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);

}
}
 

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
That’s weird. If you print the values on the Serial Monitor, what do you get? The same issue?
Regards,
Sara

0 Vote Up Vote Down
Joao Mendonça answered 4 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.