Water usage tracking

We log our water usage over time in Grafana. To do so, we have a small device next to our water meter, which periodically reads the meter by taking a picture and recognizing digits in it (currently every 5 minutes). This page describes how this device is set up, how to maintain it and how to install similar ones elsewhere.

Overview of the water meter reader

Overview

The device is an ESP32-CAM board with an OV2640 camera module. It can be obtained from many suppliers (we use this one). The software on the device is the AI-on-the-edge-device firmware, which does the digitization and upload to InfluxDB directly from the board itself. General documentation for this firmware is available on its GitHub wiki, this document focuses on the Kanthaus-specific parts.

Setting up the device

First, we need a power source (5V DC) for the board. We have plenty of such adapters in the electronics workshop, all that is needed is to solder the appropriate connectors to plug the power source to the board. The camera that comes with the device is set up for a focal length that is not adapted to this use, so we need to rotate the objective to obtain a sharp image of the meter at a close distance. This requires removing the glue which holds the objective in place. This step is quite fiddly, do not bring the lens too close to the sensor either or you could break the camera. The device comes with a default firmware which lets you stream from the camera over WiFi, which helps with checking the sharpness as you make changes.

Network settings

The device runs at 192.168.5.37 in the kh-iot WiFi network, which means it has limited network access.

To access its web UI connect to the kh-admin network go to http://182.168.5.37/

The network settings for the device can be changed by taking out the SD card in it and modifying the wlan.ini file on the card.

Updating the firmware

The firmware can be updated in two ways:

  • either via the web interface
  • or by flashing the device directly, using a USB-to-Serial adapter. We have one in the electronics workshop for this.

To flash via USB, the connections look like this: Connecting a FTDI adatper to flash the firmware

Training the digitizer

Before the device can read the meter, it needs to be calibrated. This would need to be done again for instance when our water meter is renewed. This can be done from the web UI directly. Refer to the official documentation for more details about the process.

Development environment

The official documentation recommends to use VSCode with the PlatformIO extension to develop, but sadly PlatformIO is not available for VSCodium at the time of writing this. Instead you can relatively easily work with a text editor, and install PlatformIO in a Python virtualenv (from the code/ subdirectory of the repository):

python3 -m venv .venv
source .venv/bin/activate
pip install platformio esptool

and then you can compile the firmware with

platformio run --environment esp32cam

This generates the three .bin files required for flashing in the .pio/build/esp32cam subdirectory.

For debugging purposes it is useful to use the USB-to-Serial adapter to see detailed logs. First, connect the adapter to the device (by crossing the RX/TX wires and connecting GND and +5V). Then, locate the USB-to-Serial adapter by listing the USB devices before and after plugging in. Once you have the path to the device, you can then open it with: screen /dev/ttyUSB0 115200.

results matching ""

    No results matching ""