(Suburban) Grass Farmer is a Nerves Project with a Pheonix/LiveView server embedded in the same application. In contrast to a poncho project, there is only one application supervision tree containing the Phoenix Endpoint and any processes running on the device.
Currently the versions included are:
nerves
- 1.9.3phoenix
- 1.7.2phoenix_liveview
- 0.18.18tailwindcss
- 0.2.0
Urban Grass Farmer is a hobby application sprinkler control system written in Elixir Nerves. The basic stack is:
- Elixir/Nerves is our core language/system
- Circuits GPIO - connect to the controller board (Hardware)
- LiveView - this will power the front end presentation
- Nerves Time Zones - required to manage the schedule in your local time zone
- VintageNet - so that you can connect to your wifi and internet connection for configuring on a browser and getting weather updates
- TBD - provides permance of configurations, schedules, and state in case of power outage (either db or just write to file - haven't decided, yet)
I started this project because the only nerves-based sprinkler controller I could find was pretty old and the interface and general concept didn't match what I was looking for. I'm currently using Open Sprinkler (python-based) but the interface is pretty clunky. It seemed like this was low-hanging fruit.
You can find the vision/design and my messy notes on this Figma page.
If you are a fellow nerves enthusiast and would like to contribute to this project, please do. I'm not super-experience in managing open repositories like this but I'm sure you can clone and submit a pull request. If you need help, just message me and I'll try to figure it out.
I'm developing this on a Mango Pi MQ Pro but you should be able to deploy to any nerves target if you keep an eye on your configs. Raspberry Pi and Mango Pi have different pinouts, but that shouldn't be a problem.
In addition to the Mango or Raspberry Pi you will need a Relay Module with enough channels for the number of zones you have (6 is pretty common, I have 5). I use something like this.
If you already have a dumb (or smart) controller, you'll just replace what you have. When you implement the board, remember to chain together the ground lines on the board and connect them all to the ground from your valve controller.
The order of configuration is loaded in a specific order:
config.exs
host.exs
ortarget.exs
based onMIX_TARGET
prod.exs
,dev.exs
, ortest.exs
based onMIX_ENV
runtime.exs
at runtime
To make configuration slightly more straightforward, the application is run
with MIX_ENV=prod
when on the device. Therefore, the configuration for
phoenix on the target device is in the prod.exs
config file.
You can start the application just like any Phoenix project:
iex -S mix phx.server
You can burn the first image with the following commands:
# NOTE - I've changed the default target on the Nerves examples hello live view to the mango pi.
# If you want to enable wifi:
# export NERVES_SSID="NetworkName" && export NERVES_PSK="password"
MIX_ENV=prod MIX_TARGET=host mix do deps.get, assets.deploy
MIX_ENV=prod MIX_TARGET=mangopi_mq_pro mix do deps.get, firmware, burn
Once the image is running on the device, the following will build and update the firmware over ssh.
# If you want to enable wifi:
# export NERVES_SSID="NetworkName" && export NERVES_PSK="password"
MIX_ENV=prod MIX_TARGET=host mix do deps.get, assets.deploy
MIX_ENV=prod MIX_TARGET=mangopi_mq_pro mix do deps.get, firmware, upload grass_farmer.local
To run the firmware interactively in the host environment:
MIX_ENV=prod MIX_TARGET=host mix do deps.get, assets.deploy
MIX_ENV=dev MIX_TARGET=host iex -S mix phx.server
The network and WiFi configuration are specified in the target.exs
file. In order to
specify the network name and password, they must be set as environment variables NERVES_SSID
NERVES_PSK
at runtime.
If they are not specified, a warning will be printed when building firmware, which either gives you a chance to stop the build and add the environment variables or a clue as to why you are no longer able to access the device over WiFi.
Special thanks to Frank Hunleth, the beating heart of the Nerves Project, Alex McLain, host of the Nerves Meetup, Bruce Tate from Grox whose videos inspired me to get involved in Nerves in the first place, and, of course, Jose Valim, who brought us all Elixir! Special shout out also to Chris McCord, who brought us Phoenix and LiveView.