The project involves the creation of one or more monitoring stations of the domestic environment which can possibly, with due care, be extended to public and / or corporate environments.

Idea
The project was born from the idea of raising awareness on issues such as environmental comfort and how the latter affects personal health. During the last period of the pandemic we may have found ourselves locked in the house without being ready for it: from temporary workstations to poorly lit environments, the problems can be different.
There are several factors that contribute to environmental comfort and their optimization allows you to improve your health. I wrote several articles on this:
The project was also born as a reinforcement of the @ TCS project, reinforcing some design points but expanding from temperature / humidity to other factors.
Various topics are covered such as the importance of lighting, air quality, soundproofing and problems related to ergonomics in the workplace.
Everything is developed on an open source platform so that it can be easily replicated by anyone. It uses NodeMCU, designed for the IoT, which allows you to easily read different sensors and integrate with web systems. There is also a server where all the data is collected so that you can always have the history of the previous months and be able to estimate the necessary corrections.
All the software and hardware used is opensource and the entire project is based on the Arduino and NodeMCU development environment.

The system will focus more on general control and integration with home automation currently on the market, also mentioning the possibility of setting basic controls with actuators.

The monitoring project
Within the project we want to show the importance of having a comfortable environment and how environmental well-being is fundamental for health within both the home and the workplace. Various factors are taken into consideration such as temperature and humidity, lighting, noise pollution and air quality, considering the presence of particulate matter and constant renewal.
NodeMCU
NodeMCU is an open source platform developed specifically for the IoT. It includes a firmware that works through the ESP8266 wifi module and comes with several hardware bases. The ESP12E module was used in the following examples. The chip is easily programmable with Arduino IDE by integrating the necessary libraries.
Reading sensors
With this device you can easily control various digital sensors such as the DHT22 for temperature and humidity or the DS18B20 for temperature, even in immersion.
Trivially, to read the sensor it is sufficient to refer to the relative libraries, for example:
#include "DHT.h"
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();


Web pages
You can easily connect to the internet either by using the device as an access point or by connecting to an existing network. Using the AsyncWebServer and AsyncTCP libraries, a web server is easily created in which sensor data can be integrated. For example, you create an HTLM page with containers for the data:
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"</i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">°C</sup>
</p>
Then we add a Javascript algorithm to automatically update the containers.
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
</script>
Clearly it is also necessary to use a function that is called for a chosen time interval so as to request data with the url / data:
xhttp.open("GET", "/data", true);
xhttp.send();
}, 10000 ) ;
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
Then you pass the data to a function that takes care of updating the containers in the HTLM page
String processor(const String& var){
//Serial.println(var);
if(var == "TEMPERATURE"){
return String(t);
}
else if(var == "DATA"){
return String(data);
}
return String();
}
For complete codes refer to the GitHub repository.
tempcontrol (this link opens in a new window) by mastroalex (this link opens in a new window)
The purpose of this project is to create a station for monitoring the environmental conditions for home.
Alexa integration
The Sinric Pro platform was used to quickly integrate the system with Alexa. The code provided is used, setting the parameters and the device correctly. Then add the “SinricPro” skill on Alexa and after login you will be able to see the temperature sensor.

Database
The repository contains both the procedure for building a database on Raspberry Pi that can be used in the LAN and the procedure for a remote host. The procedure is very similar. A MySQL table is created by associating a sensor to each column:
CREATE TABLE SensorData (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
sensor VARCHAR(30) NOT NULL,
location VARCHAR(30) NOT NULL,
value1 VARCHAR(10),
value2 VARCHAR(10),
value3 VARCHAR(10),
reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
Then a .php page is created containing the code to write the data in the database received through a POST request from the ESP.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$api_key = test_input($_POST["api_key"]);
if($api_key == $api_key_value) {
$sensor = test_input($_POST["sensor"]);
$location = test_input($_POST["location"]);
$value1 = test_input($_POST["value1"]);
$value2 = test_input($_POST["value2"]);
$value3 = test_input($_POST["value3"]);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO SensorData (sensor, location, value1, value2, value3)
VALUES ('" . $sensor . "', '" . $location . "', '" . $value1 . "', '" . $value2 . "', '" . $value3 . "')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
The ESP must be configured to make the POST request correctly by sending a message containing the chained sensor data in the correct order.
// Your Domain name with URL path or IP address with path
http.begin(serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName + "&location=" + sensorLocation + "&value1=" + String(bme.readTemperature()) + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
int httpResponseCode = http.POST(httpRequestData);
Then there is another php page which reads the values from the database and creates the graphs passing the data to the Highcharts library.
var chartH = new Highcharts.Chart({
chart:{ renderTo:'chart-humidity' },
title: { text: 'Humidity' },
series: [{
showInLegend: false,
data: value2
}],
plotOptions: {
line: { animation: false,
dataLabels: { enabled: true }
}
},
xAxis: {
type: 'datetime',
//dateTimeLabelFormats: { second: '%H:%M:%S' },
categories: reading_time
},
yAxis: {
title: { text: 'Humidity (%)' }
},
credits: { enabled: false }
});

For complete codes refer to the GitHub repository.
tempcontrol (this link opens in a new window) by mastroalex (this link opens in a new window)
The purpose of this project is to create a station for monitoring the environmental conditions for home.
Tasmota and smart home monitoring
It may be usefull to integrate these sensors with actuators. For example, it may be useful to activate a fan when a certain temperature is exceeded or to turn on a light when the ambient lighting falls up to more sophisticated controllers such as thermostats, dimmers for lighting, ventilation for air quality, etc.
A simple way to integrate the ESP platform with Alexa and the remote control of the actuators is the firmware offered by Tasmota. It is an alternative open source firmware that allows you to control different outputs on the ESP while also setting smart outputs, conditions and timers.
Just install the Tasmotizer software and load the correct firmware.


Then you can connect to the ip address of the device and configure the desired outputs.
The system can be integrated with Alexa and accessible from a web server.

Future developments
It is clear the possibility of optimizing everything by transferring it to a PCB circuit, eliminating all that is useless and using only the devices necessary for operation. This certainly implies an increase in production costs but would allow for a considerable reduction in size. It is clear that a large-scale production must be evaluated first and certainly not for the test phase.
Examples
24-hour reading of temperature and humidity from a room in July:
The graph contains a spline on the points obtained from a sampling every 5 minutes.
Reading in a week in July:
Acknowledgements
- Termo Clima Service , for having supplied part of the material and equipment for the realization of the prototypes
- Leto Informatics , for providing the hosting server and part of the configuration
- Alina Elena Mihai, for graphics
References
- ESP32/ESP8266 Publish Data to Raspberry Pi LAMP Server
- ESP8266 DS18B20
- ALEXA ECHO comunica con ESP32 and ESP8266 utilizzando SINRIC
- SinricPro (ESP8266 / ESP32 SDK)
- ESP32 DHT11/DHT22 Web Server
- Alexa comunica con ESP32 and ESP8266 utilizzando SINRIC con sonoff
- DIY Cloud Weather Station with ESP32/ESP8266
- Control ESP32 and ESP8266 GPIOs from Anywhere in the World
- ESP8266 DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE
- Sinric.com
- SinricPro (ESP8266 / ESP32 SDK)
- Sinric Example for ESP
- DIY Air Quality Monitor
- Visualize Your Sensor Readings from Anywhere in the World
- Thermal comfort
- A Meta-Analysis of Performance Response Under Thermal Stressors
- Thermoregulatory responses to environmental toxicants
- The Importance of Humidity in the Relationship between Heat and Population Mental Health
- Why is lighting in the workplace important?
- Lighting Ergonomics – General
- Eye Discomfort in the Office
- Lighting Ergonomics – Survey and Solutions
- 3 basics type of lighting
- Computer vision syndrome in the time of COVID-19
- Lighting in the Home and Health
- Lighting Quality and its Effects on Productivity and Human Healts
- Health Effects of Artificial Light
- IESNA – The lighting handbook
- Illuminazione degli ambienti: attenzione ai problemi di vista
Read more: https://github.com/mastroalex/tempcontrol