⚡ Pi Read Meter! 🎥
Raspberry Pi + Camera + pi-read-meter = reading gas meter every month automatically.
Instead of taking the number every month manually on the first day of a month, I made it automatic by one old Raspberry Pi Model B and Raspberry Pi NOIR camera V2.
Perfect use of Go in my opinion! I really enjoy building binary on my Mac, transporting it to Pi and running there. Very convenient!
How did I do it?
Here I'll go over the steps to set something similar up to yourself. These are notes for future self and for anyone who is interested in it.
Basic equipment
- (Gas/water/electricity) meter to read
- Raspberry Pi with memory card and connection to internet
- Raspberry Pi camera or some other camera. It must be possible to capture image using command line command.
- In case of dark room, some low consumption night light or similar might be necessary
- Other computer (can be done on Pi as well) to build Go binaries on (this code right here)
Setting it up from scratch
- Get Raspbian (Lite is fine) running in your Pi: https://www.raspberrypi.org/downloads/raspbian/
- Boot up the Pi and make sure to have access to the command line.
- Check your Pi ARM version:
cat /proc/cpuinfo
- Clone this repository to a computer with Go installed
- Change ARM version in
Makefile
if yours is different from the one I used inbuild-pi
command. - Build the binary for Pi using
make build-pi
- When you have the binary, move it to Pi (using
scp
or some other means) - Move also the
config.example.json
from this repository to Pi - Modify
config.example.json
to have correct informationcapture_command
for Pi camera israspistill
. If you use something else, make sure to change it in the config file.capture_command_args
are passed in to the command. Modify these according to your needs.%s
in this list of args denotes the file name where the image is saved.file_path
is a full path to the captured image.%s
here is replaced with date and time.dropbox_token
can be acquired from https://www.dropbox.com/developers/apps/create. Create an app with access to only its directory, this is where the images will be.
- Run the binary on Pi:
./pi-read-meter-armv6 config.json
(I hope you named your configconfig.json
) - If all goes well, you should have the image in your Dropbox's app folder (
/Apps/APP_NAME
in Dropbox) - To make it run automatically, configure cron using
crontab -e
command. In there,- Specify cron shell, I used bash like this:
SHELL=/bin/bash
- Make it run every night:
0 0 * * * /home/pi/pi-read-meter-armv6 config.json >> /home/pi/pi-read-meter.log 2>&1
- Assuming the binary is at
/home/pi/pi-read-meter-armv6
- Assuming the config is at
/home/pi/config.json
- Assuming that logs will be created to
/home/pi/pi-read-meter.log
- Feel free to change it however you like better
- Assuming the binary is at
- Specify cron shell, I used bash like this:
- Now enjoy the pictures coming to Dropbox!
I plan to add OCR at some point as well, so that Pi would be able to send the data "Pi" itself! 😍
Contributing
Contributions are welcome!
If you are using it locally (in development), then use config.dev.json
file for specifing the config.