Project repository with source code for JSON clients - Github: WiFi thermostat
ESP8266 ESP32 WiFi DS18B20 OneWire Dallas HTML Webserver WebSocket JSON mDNS UART
JSON DATA
JSON DATA
ArduinoJSON
ArduinoJSON
MQTT
MQTT
HTTP
HTTP

JSON clients - WiFi thermostat


JSON client built on Arduino platform, ESP8266, ESP32 allows connection via websocket to WiFi thermostat. The client performs a cyclic HTTP GET request every 15 seconds to retrieve the content of the /get_data.json subpage, where the web server distributes target temperature, hysteresis, and currently measured temperature data to the DS18B20 sensor on the OneWire bus in JSON format. The loaded JSON payload can parse the JSON client from the HTTP response and then deserialize this string. After deserialization, it is possible to access the individual keys to which the values are assigned and obtain them -> parse. The matched data is written to the UART - Serial line - 115200 baud / s. In a user application that can be added to existing JSON client source codes, entities can be controlled based on these values, for example: radiator valve opening, solenoid, ventilation, window closing, etc. Alternatively, it is possible to archive data - send it to a web server, where it can be stored, for example, in a MySQL database, in Loxone home automation. Part of the firmware marked as MQTT or MQTTS (encrypted MQTT) is an extended JSON client with the ability to send - Publish to MQTT Broker IoT Industries Slovakia - Slovak free MQTT Broker designed for developers. Both the MQTT and MQTTS variants use a socket, which is also used for HTTP requests to obtain JSON payloads. The existing MQTT server can be replaced in your source code by yours, so you can also make the data from the thermostat available to home automation systems (Hassio, Mosquitto MQTT, Domoticz, Loxone and others ...). In the current software implementation, the microcontroller (JSON client) sends the acquired data to the MQTT Broker in the thermostat topic, while the individual temperatures are differentiated in subtopics.

Source codes for MQTT / MQTT + JSON clients are available at: JSON clients example codes

Available libraries for microcontrollers (Arduino / ESP) - JSON clients


Library archive (.zip) extract to C:/Users/[User]/Documents/Arduino/libraries
Library name Library function Download
PubSubClient

Library for AVR microcontrollers (ATmega) Arduino Uno / Nano / Mega, ESP8266 and ESP32. It enables communication via the MQTT protocol, it is also possible to implement an encrypted connection with the MQTT Broker, the use of WiFiClientSecure is required for ESP microcontrollers.

Download
ArduinoJson

Library for AVR microcontrollers (ATmega) Arduino Uno / Nano / Mega, ESP8266 and ESP32. It allows you to deserialize a string in a JSON structure, it can parse the value that is assigned to a key.

Download

Sample data listing in JSON format - WiFi thermostat


{
"Hysteresis":0.25,
"Target_Temperature":21.75,
"Actual_Temperature":21.43
}
MQTTS implementation is only available for ESP8266, ESP32 platforms. Both microcontrollers use a Root CA certificate for encrypted connection to the MQTT server. The encrypted port of the MQTT server is 8883 by default, unencrypted 1883. To obtain a Root CA certificate for a specific MQTT server (domain), it is possible to use the OpenSSL tool, which allows easy retrieval and display of the information in question. The statement is implemented in the Chain of Trust hierarchy, i. the first certificate is Root CA, followed by Intermediate CA.
Root CA Certificate Command for Server:
openssl s_client -showcerts -verify 5 -connect mqttserver.com:8883 < /dev/null

The topics used for Publish on MQTT Broker are:

  • termostat/hysteresis - for hysteresis
  • termostat/actual_temp - for the currently measured temperature
  • termostat/target_temp - for the target (reference) temperature
  • Topic for Subscribe:

  • termostat/# - takes all subtopics under the termostat/, ie hysteresis, current and target temperature
  • The MQTT client has a subscribed subscription to the main topic thermostat and all its subtopics. It can also verify whether the information has been successfully published on MQTT Broker. WARNING: MQTT Broker IoT Industries Slovakia, which is used in the sample implementation, is public and so the data can be changed, overwritten, read by any user! If any other user uploads the JSON client firmware to their microcontroller without change, the data in the predefined topic will be overwritten by you, as well as by him. It is therefore advisable to choose another topic where the data will be sent during the actual implementation.

    Block diagram - description of JSON client functionality:

    JSON klient - Arduino, ESP8266, ESP32, MQTT integrácia - WiFi termostat

    JSON client - UART output (Serial line):

    JSON client pre WiFi termostat - UART výstup

    HiveMQ client - Subscribe topic termostat/#

    JSON client MQTT Broker IoT Industries Slovakia - výstup topicu - Subscribe termostat