A JSON client, compatible with the Arduino platform, ESP8266, and ESP32, enables seamless connection via a websocket to a web server, specifically the web interface of the Water Level Meter. The client executes a periodic HTTP GET request every 60 seconds to fetch the content of the subpage: /json_output.php. Where the webserver distributes JSON data on water level (in centimeters) and well volume (in liters) based on the currently set depth and diameter of the well. The loaded JSON payload can be parsed by the JSON client from the HTTP response and subsequently deserialized. After deserialization, it is possible to access individual keys to which values are assigned and retrieve them -> parse. The parsed data is then written to UART - Serial line - 115200 baud / s. In the user application, which can be seamlessly integrated into existing JSON client source codes, it becomes possible to control entities based on these values. For instance: automated irrigation upon reaching a specific water level, water pumping, pump activation, and more. Part of the firmware, identified as MQTT or MQTTS (encrypted MQTT), features an extended JSON client capable of sending - publishing data to the MQTT Broker IoT Industries Slovakia - a Slovak free MQTT Broker designed for developers. Both MQTT and MQTTS variants utilize a socket, which is also employed for HTTP requests to obtain JSON payloads. The existing MQTT server can be substituted in your source code with your own, allowing you to make data from the level meter accessible in various home automation systems (Hassio, Mosquitto MQTT, Domoticz, Loxone, and others ...). In the current software implementation, the microcontroller (JSON client) transmits the obtained data to the MQTT Broker under the topic 'level meter,' with individual temperatures distinguished in subtopics.
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 |
openssl s_client -showcerts -verify 5 -connect mqttserver.com:8883 < /dev/null
The MQTT client subscribes to the main topic 'level meter' and all of its subtopics, allowing it to confirm the successful publication of information on the MQTT Broker - subsequently logging this on the UART. WARNING: The MQTT Broker IoT Industries Slovakia, utilized in this example, is public, exposing data to potential changes, overwrites, and reads by any user! If another user uploads the JSON client firmware to their microcontroller without modification, the data in the predefined topic may be overwritten both by them and by you. Hence, it is strongly recommended to opt for a unique topic during implementation to prevent unintended data overwrites.