Wasserqualitätsüberwacher für einen Pool.
Dieser sollte z.B. im Pumpenhaus untergebracht, täglich über WLAN Messwerte an einen WEB-Server oder per mail übertragen.
Dabei kann ein ESP32 dauerhaft stromversorgt werden und eine Verbindung zum WLAN aufrechterhalten.
So könnte man feststellen, ob der ordentlich gewartet wird oder ob der Pool kurz vorm Umkippen ist.

- Lösungsansatz Der ESP32 sendet den Messwert über einen MQTT-Server an einen zweiten ESP32, der die Messwerte darstellt.
Files:
main.py
ESP32 Überwachung
Complete project details at https://RandomNerdTutorials.com/micropython-programming-with-esp32-and-esp8266/
def sub_cb(topic, msg):
# print((‚Uebertragung: ‚, topic, msg))
msg=str(msg)
msg= msg[2:]
msg=msg[:-5]
print((‚NTC3905-100k: ‚, msg))
# print [„%0.2f“ % i]
def connect_and_subscribe():
global client_id, mqtt_server, topic_sub
client = MQTTClient(client_id, mqtt_server, user=mqtt_user, password=mqtt_pass, ssl=True)
client.set_callback(sub_cb)
client.connect()
client.subscribe(topic_sub)
print(‚Connected to %s MQTT broker, subscribed to %s topic‘ % (mqtt_server, topic_sub))
return client
def restart_and_reconnect():
print(‚Failed to connect to MQTT broker. Reconnecting…‘)
time.sleep(10)
machine.reset()
try:
client = connect_and_subscribe()
except OSError as e:
restart_and_reconnect()
while True:
try:
new_message = client.wait_msg()
client.publish(topic_pub, b’received‘)
time.sleep(1)
except OSError as e:
restart_and_reconnect()
#————————————————–
boot.py:
Complete project details at https://RandomNerdTutorials.com/micropython-programming-with-esp32-and-esp8266/
import time
from umqttsimple import MQTTClient
import ubinascii
import machine
import micropython
import network
import esp
esp.osdebug(None)
import gc
gc.collect()
# ==> eigene Werte einfuegen
ssid = ‚ssid‚
password = ‚password‚
mqtt_server = ‚mqtt_server‚
mqtt_user = ‚mqtt_user‚
mqtt_pass = ‚mqtt_password‚
EXAMPLE IP ADDRESS
mqtt_server = ‚192.168.1.144‘
client_id = ubinascii.hexlify(machine.unique_id())
topic_sub = b’hello‘
topic_pub = b’notification‘
last_message = 0
message_interval = 5
counter = 0
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
while station.isconnected() == False:
pass
print(‚Connection successful‘)
print(station.ifconfig())
#————————————————–
zusätzlich Datei ‚umqttsimple.py‘ und eine SSL-Library auf den ESP32 schreiben.
2. Software- und Kalibrierungsaktualisierung
Die Aktualisierung des Messprogramms bzw. von Kalibrier-
Faktoren geschieht OTA (over the air) mit Hilfe eines GitHUB-
Repositories (https://github.com/proess/ESP32_OTA), welches die Aktualisierungen mit Hilfe von
Versionsnummern (Software bzw. Kalibrierwerte) ermöglicht.
ReadMe.md: MicroPython Over-the-Air updater
This library enables you to update your MicroPython projects over the air, at start-up, or whenever you choose.
To use this code:
- Add the
ota.py
to your MicroPython device - Create a file named
WIFI_CONFIG.py
on your MicroPython device, which contains two variables:SSID
andPASSWORD
:SSID = "my wifi hotspot name" PASSWORD = "wifi password"
- Add this to your main program code:
from ota import OTAUpdater from WIFI_CONFIG import SSID, PASSWORD firmware_url = "https://raw.githubusercontent.com/<username>/<repo_name>/<branch_name>"
where<username>
is your github username,<repo_name>
is the name of the repository to check for updates and<branch_name>
is the name of the branch to monitor. - Add this to your main program code:
ota_updater = OTAUpdater(SSID, PASSWORD, firmware_url, "test.py") ota_updater.download_and_install_update_if_available()
- On your GitHub repository, add a
version.json
file, and add aversion
element to the JSON file, with a version number:{ "version":3 }
The OTA-Updater
will connect to github over wifi using your provided wifi credentials, check what the most up-to-date version of the firmware is, compare this to a local file present on the device named version.json
, which contains the version number of the current on device firmware.
If the local file is not present it will create one with a version number of 0
. If the Github version is newer, it will download the latest file and overwrite the file on the device with the same name, then restart the MicroPython board.
If you find this useful, please let me know on our discord server: https://www.kevsrobots.com/discord
ota_test.py
from ota import OTAUpdater
from WIFI_CONFIG import SSID, PASSWORD
firmware_url = „https://github.com/proess/ESP32_OTA/blob/main“
ota_updater = OTAUpdater(SSID, PASSWORD, firmware_url, „main.py“)
ota_updater.download_and_install_update_if_available()
Beispiel zur Messwertübertragung und -darstellung
So könnte es aussehen, wenn man in Spanien einen Temperatur-Messfühler anfasst und wieder loslässt 🙂
