This is an old revision of the document!


Temperature Monitor


  • Author: Chirilă Alexandru

Project Description


This project is meant to monitor the temperature for a certain room: the room where the sensor will be placed. It is a simplist project consisting of two parts:

  1. An arduino program which monitors the temperature and sends it to a Firebase database
  2. A Python script which can be run on any computer or even an Android phone or an iPhone (Python interpreter installation required)

Hardware Description


Following hardware components were used in order to achieve the desired result:

  • ESP32 Sparrow
  • BME680 Sensor

Software Description


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.

Running the Python script


Running the python script is as follows:

$ python .\app_client.py
Response status code: 200
Temperature: 55.01°C
Response status code: 200
Temperature: 55.01°C

References

iothings/proiecte/2024/temperature_monitor.1736794908.txt.gz · Last modified: 2025/01/13 21:01 by alexandru.chirila01
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0