This project is about reading the counter of diaphragm gas volume meter which is commonly installed in residential properties to count and bill the consumed gas. The last dial of the meter has a reflective sticker, which can be utilised to detect a full revolution of the dial.
In some meters the reflective sticker is made from a magnetic material and a very sensitive magnetometer is sufficient to detect the changes in the earth magnetic field when the sticker passes by the sensor. In the first version of this project used the SparkFun 3-axis magnetometer to detect a full revolution of the .001 m³ digit wheel. Since my gas meter was replaced with a new non-magnetic version, the magenetometer sensor doesn't work anymore.
Here I describe a new sensor device, which uses an infrared LED and a phototransistor to detect the changes in reflectivity when the reflective sticker on the last dial passes by the phototransitor. The measurement principle was inspired by the pulsemeter and the device looks like this when mounted in front of the gas meter:
The schematics, board layout and part list of the gasmeter dongle hardware is described in more detail in the Gasmeter wiki.
On the software side, the Gasmeter program reads the current gas volume from the meter and forwards it to a MQTT broker on the network. The data is stored in a TimescaleDB database and visualised on a Grafana dashboard. The installation of the software stack, including the setup and maintainance of the database, is described on the Smartmeter wiki pages.
To compile Gasmeter from source, a Makefile for (cross-)compilation is provided:
make CROSS_COMPILE=aarch64-unknown-linux-gnu
make install
Alternatively, there is also an Arch Linux package called gasmeter published in the AUR.
The hardware dongle needs firmware for the Atmel microcontroller in order to communicate with the gasmeter program. To compile the firmware, first install the AVR toolchain through your package manager. On Arch Linux, install avr-gcc
and avr-libc
packages and then make upload
to compile and upload the firwmare. On a new microcontroller, a bootloader needs to be flashed first to accept a firmware image via upload. The preparation of a new µC is described in the wiki.
The Arch Linux package provides a systemd service file and installs the configuration file in /etc/gasmeter/gasmeter.conf
. The service can be started with:
systemctl start gasmeter
When building directly from source, the daemon can be directly started with:
gasmeter --config resources/config/gasmeter_example.conf
The Arch Linux package installs a docker compose in /etc/gasmeter/docker-compose.yaml
and a Dockerfile
. Alternatively, these files are also in the root folder or the source. Before building and starting the container, the serial device used by the gasmeter hardware needs to be set in docker-compose.yaml
in addtion to gasmeter.conf
to give Docker access to the device.
docker-compose up --build
The Gasmeter program is configured with a configuration file located in /etc/gasmeter/gasmeter.conf
. At least the serial device of the hardware, the MQTT hostname and topic to publish to needs to be set. Optionally, Gasmeter supports MQTT password authentication and TLS connection encryption. Finally, the gas tariff, which consists price per kWh, a yearly service charge and the gas conversion factor (found on the last bill), needs to be set here for the current bill to be shown on the dashboard.
On first run, the low and high threshold parameters need to be determined. For this, there is a special raw_mode
option in the config file, which outputs the raw sensor values to the console. To record values create a log file with:
gasmeter --config gasmeter.conf | tee raw_values.log