Repository of the level meter project with source codes for JSON clients - Github: Water Level Meter
Arduino Ethernet Wiznet W5100 / W5500 ESP8266 ESP32 Ultrasonic HC-SR04 JSN-SR04T Sigfox JSON MQTT
JSON DATA
JSON DATA
ArduinoJSON
ArduinoJSON
MQTT
MQTT
HTTP
HTTP

JSON Clients - Water Level Monitor project


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.

Example source codes for JSON Clients are available: HERE

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
MQTTS implementation is readily available for ESP8266 and ESP32 microcontrollers. Both microcontrollers utilize a Root CA certificate for secure connections to the MQTT server. The default encrypted port for the MQTT server is 8883, while the unencrypted port is set to 1883. To acquire a Root CA certificate for a specific MQTT server (domain), you can employ the OpenSSL tool, which facilitates the straightforward retrieval and display of pertinent information. The individual certificates are presented in the Chain-of-Trust order, i.e., from Root CA to Intermediate.
Command to obtain the Root CA certificate that issued the certificate for the MQTT server (Issuer):
openssl s_client -showcerts -verify 5 -connect mqttserver.com:8883 < /dev/null

Sample data listing in JSON format

{
"value": 378,
"volume": 1900.04
}

The topics used for Publish to MQTT Broker are:


  • hladinomer/objem - for well volume in liters
  • hladinomer/vyska - pfor the current water level in centimeters

  • Topic for Subscribe:


  • hladinomer/# - takes all subtopics below the main hladinomer/ topic, ie volume, height
  • 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.



    JSON PHP output, parsing & Publish to MQTT Broker:


    JSON client (Arduino, ESP8266, ESP32) for Water Level Monitor

    Screenshot HiveMQ client - Subscribe of topic hladinomer/#

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