This is an old revision of the document!
This project is meant to monitor the temperature for a certain room: the room where the sensor will be placed. It only prints data when the temperature changes by at least 0.5 °C since the last printed temperature value. It also plays a notification sound when this change of temperature occurs. It is a simplist project consisting of two parts:
Following hardware components were used in order to achieve the desired result:
The following libraries were necessary:
#include "Zanshin_BME680.h" #include <Arduino.h> #include <WiFi.h> #include <Firebase_ESP_Client.h>
The Wi-Fi setup and connection:
WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}
The BME680 setup:
// Code taken from the "I2CDemo" example.
BME680_Class BME680;
float altitude(const int32_t press, const float seaLevel = 1013.25);
float altitude(const int32_t press, const float seaLevel) {
static float Altitude;
Altitude = 44330.0 * (1.0 - pow(((float)press / 100.0) / seaLevel, 0.1903));
return (Altitude);
}
Firebase setup:
config.api_key = API_KEY;
config.database_url = DATABASE_URL;
/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")) {
Serial.println("ok");
signupOK = true;
}
else {
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
The loop() function:
void loop() {
if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 1000 || sendDataPrevMillis == 0)) {
sendDataPrevMillis = millis();
static int32_t temp, humidity, pressure, gas; // BME readings
BME680.getSensorData(temp, humidity, pressure, gas);
if (Firebase.RTDB.setFloat(&fbdo, "test/float", (float)(temp / 100.0f))) {
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
}
}
As said before, the data read from sensor is saved in Firebase and is updated in real time in the output of the python script.