Skip to content

Instantly share code, notes, and snippets.

@maggiben
Last active August 18, 2024 03:09
Show Gist options
  • Save maggiben/82239f15d46f7255943de8b26c730469 to your computer and use it in GitHub Desktop.
Save maggiben/82239f15d46f7255943de8b26c730469 to your computer and use it in GitHub Desktop.
Remote Watering System Setup

Remote Watering System Setup

Requisites

  1. Raspberry PI Zero 2W (any PI should work ok)
  2. nodemcu-32s
  3. USB OTG Cable, Power Supply, etc...

Preparation

  1. Flash the OS into the SD card (32gb is plenty) (Config: Username, Wifi and SSH)
  2. Connect the i2c RTC module to the rpi
  3. Connect the USB OTG cable from the raspberry pi to the nodemcu-32s
  4. Boot the raspberry pi (first time takes time to expand fs and setup)
  5. First time boot: make sure the os is up to date sudo apt-get update and sudo apt-get upgrade
  6. Intall the at command sudo apt-get install at
  7. Check for usb to serial device under /dev/ttyUSBX where X is usually 0, this utility python script can be used to find the first available ttyUSB device regardless of the number
  8. Setup PI i2c hardware clock

Now the system is ready for setup

Setup Tailscale:

  1. Install curl -fsSL https://tailscale.com/install.sh | sh
  2. Configure sudo tailscale up

NodeMcu preparation and setup

  1. Download plataformio cli tool here

Is a good idea to use set the path: Edit $HOME/.profile add this at the botom:

# set PATH so it includes plataformio if it exists
if [ -d "$HOME/.platformio/penv/bin" ] ; then
    PATH="$HOME/.platformio/penv/bin:$PATH"
fi
  1. Cd to / and clone the repo git clone https://github.com/maggiben/smart-green.git try not to use root user

do not try to compile the code in a raspberry pi zero 2w because it will hang, compile the code elsewhere and deploy using this tool build-and-deploy.sh to upload the compiled firmware.bin and firmware.elf to the target raspberry pi system, to use the tool, setup variables RASPBERRY_PI_USER, RASPBERRY_PI_IP and REMOTE_PATH to you desired user, destination ip and firmware path for plataformio

  1. Set the date on the nodemcu:
python3 serial-ping.py -m set-rtc:$(date +"%Y-%m-%dT%H:%M:%S")
  1. Check the time:
python3 serial-ping.py -m time
  1. Set the alarms on the nodemcu:
python3 serial-ping.py -m 'set-alarms:{"alarm":[[{"id":0,"weekday":2,"hour":19,"minute":30,"status":1},{"id":0,"weekday":2,"hour":19,"minute":31,"status":1}],[{"id":1,"weekday":8,"hour":19,"minute":30,"status":1},{"id":1,"weekday":8,"hour":19,"minute":31,"status":1}],[{"id":2,"weekday":64,"hour":19,"minute":30,"status":1},{"id":2,"weekday":64,"hour":19,"minute":31,"status":1}]]}'
  1. Set the planst on the nodemcu:
python3 serial-ping.py -m 'set-plants:{"plants":[{"id":0,"size":10,"status":1},{"id":1,"size":18,"status":1},{"id":2,"size":18,"status":1},{"id":3,"size":18,"status":1},{"id":4,"size":18,"status":1},{"id":5,"size":18,"status":1},{"id":6,"size":18,"status":1},{"id":7,"size":18,"status":1},{"id":8,"size":18,"status":1},{"id":9,"size":18,"status":1},{"id":10,"size":18,"status":1}]}'
  1. Get the time untill the next alarm
python3 serial-ping.py -m next-alarm
  1. Reset Task Values
python3 serial-ping.py -m reset-task
  1. Check the total watering time
python3 serial-ping.py -m get-watering-time

Setup Watchdog

here: link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment