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


JSON client built on the Arduino platform, ESP8266, ESP32 allows connection via a websocket to a web server (web interface of the Level Meter). The client performs a cyclic HTTP GET request every 60 seconds to retrieve the content of the /json_output.php subpage, where the webserver distributes JSON data on water level (in centimeters), well volume (in liters) based on the currently set depth and diameter well. 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 the user application, which can be added to the existing source codes of JSON clients, it is possible to control entities based on these values, for example: automated irrigation after reaching a certain water level, water pumping, pump start, darling. Part of the firmware marked as MQTT or MQTTS (encrypted MQTT) is an extended JSON client with the ability to send - Publish data 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 level meter available in home automation systems (Hassio, Mosquitto MQTT, Domoticz, Loxone and others ...). In the current software implementation, the microcontroller (JSON client) sends the obtained data to the MQTT Broker in the topic level meter, while the individual temperatures are differentiated 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 available for ESP8266, ESP32 microcontrollers. ESP8266 and ESP32 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 individual certificates are listed in Chain-of-Trust order, i. 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 has a subscribed subscription to the main topic level meter and all its subtopics. It can also verify whether the information has been successfully published on MQTT Broker - it will write it back on the UART. 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 implementation.



    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