ESP32 support for WiFi thermostat project

07/08/2021

The WiFi thermostat project was originally created for the ESP8266 WiFi microcontroller platform from Espressif as equivalent to the Ethernet thermostat, which was built on the AVR microcontroller ATmega328P used in Arduino UNO, on which an Ethernet shield can be slid. The thermostat allows control of the GPIO output based on the measured temperature from the Dallas DS18B20 sensor (with 12-bit resolution), target temperature and hysteresis. The target temperature and hysteresis are configurable via an HTML web interface running on the microcontroller.

Experimental version of the thermostat firmware with the possibility of manual GPIO control was created for the WiFi microcontroller ESP8266, which makes it possible to deactivate the thermostat and use it all year round, for example as a thermometer available on the network at its link-local IP address or in domain name via mDNS record. 

There was no support for ESP32 in the project for a long time, as it was problematic to compile the firmware for this microcontroller with the WiFiManager library, which is officially available only for ESP8266. The release version of the library did not even count on ESP32, but in the development branch on Githube, unofficial support for ESP32 has been created, which, however, works seamlessly for a specific application.

By editing several header files, I was able to use identical source code in terms of features, which is executable with the correct library header files on both WiFi platforms without the need to modify the program. For webserver services, I used the Webserver class, beware, users often confuse it with WiFiServer, which has advanced functions for handling connections but also for taking arguments, similar to the ESP32 microcontroller. 

The firmware for the WiFi thermostat under ESP32, as well as the firmware for the ESP8266, is available in compiled code, which can be uploaded to the microcontroller via the ESPTOOL tool. The tool can be run as a .py script, or as an executable .exe application via the command line, which in this case is available in the folder of each firmware.

There is also a change in the number of arguments required for a microcontroller to load firmware. For the ESP8266, the firmware alone was enough, but for the ESP32 it is more complicated and requires 2 bootloader binaries, a partition table and the firmware itself. Each file is written to a specific (standard offset). 

Bootloader at 0x1000, partition table at 0x8000 and application at offset 0x10000. Because a partition table without an OTA partition is used, other application partitions are not written to flash memory. From the point of view of stability, the WiFi thermostat under the ESP8266 seemed more stable to me, as its dynamic HEAP memory did not fluctuate and had a constant value. 

With ESP32 HEAP it fluctuates slightly in the order of tens of bytes, but since this microcontroller has up to 500 kB of RAM, it did not happen to me that the thermostat showed signs of a jam, as it would restart the HW watchdog and reset the uptime on the thermostat website, which is bound to the millis() function, which returns the number of milliseconds since the processor started.

As of thermostat version 1.0.2.X, due to the fact that Google Chrome cannot distinguish a decimal number in the input field of the HTML form and does not allow entering a comma (or dot) for decimal representation of a number on mobile devices, the thermostat continues to use the text data type for the field. so that the user is able to enter a decimal number. 

On the WiFi thermostat website, a click has been made directly on the firmware in the "Starting the WiFi thermostat" section based on the target platform ESP8266 / ESP32. The firmware is fully ready to use, just choose one of the three supported versions and follow the instructions on the page. 

The firmware is valid for Standalone ESP32 chips, devkits and development boards equipped with e.g. with the most popular ESP-WROOM-32 / ESP32-S etc ... Even with a WiFi thermostat on ESP32, it is possible to use supported JSON clients to connect to this thermostat and push the obtained data to MQTT Broker, or to home automation (Hassio, Domoticz, Loxone and others ...). 

More about the WiFi and Ethernet thermostat project, including instructions describing the thermostat's options, can be found on its website: https://martinius96.github.io/WiFi-termostat/en/

© 2021 Martin Chlebovec - Arduino Blog - . All rights reserved
Powered by Webnode Cookies
Create your website for free! This website was made with Webnode. Create your own for free today! Get started