Water level and pumps monitor with ruby and raspberry-pi
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
sensors
.gitignore
.overcommit.yml
Gemfile
LICENSE
README.md
config.yml
server.rb
server_handler.rb

README.md

This server is used for monitoring two sump pumps in a tank that collects rain water and prevents flooding of our garage. When a certain level is reached one of two sump pumps, alternatively, draws up water from the tank.

The software is running in a Raspberry-Pi with four sensors attached:

  • a temperature sensor (TMP36)
  • two load sensors (SCT 013-030) to monitor pumps usage
  • an ultrasonic range sensor (MB7040) to monitor tank water level

The temperature sensor and the two load sensors are connected to the Raspberry-PI by an ADC with SPI interface (MCP3208), the ultrasonic sensor is connected directly via i2c channel.

The server uses websockets to transmit sensors values, to do that I use the em-websocket gem. Since em-websocket uses event-machine gem, and this gem is also used by pi_piper, which has the drivers to use SPI and I2C on the Raspberry-PI, I had to fork pi_piper gem, otherwise I had to use pi_piper event-machine gem version, which is older. My pi_piper fork of the gem doesn't use event-machine so I was able to use its latest version.

Drivers and sensors are easily reusable and can be configured to work with different ADC resolutions, in fact these drivers should be in their own gem, and they will be in the future.

Security notes

Unfortunately, access on I2C and SPI channels requires root privileges, so this server must run with these privileges. In my case this is not a problem because the Raspberry-PI is connected to a specific and isolated lan, without internet access and without critical or data-sensitive sevices.

In case you'd like to use this software please, be aware of this issue.

Installation steps

install libraries and packages on Raspberry-PI

$ sudo apt-get update && sudo apt-get install ruby
$ sudo gem install bundler

$ git clone https://github.com/gabrypulzio/pumpberry-server.git /path/to/pumpberry-local-install
$ cd /path/to/pumpberry-local-install
$ sudo bundler

run

$ sudo bundle exec ruby server_handler.rb start