Skip to content

jpizquierdo/draco-micropython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

draco-micropython

A MicroPython-based MQTT watering system controller for the Raspberry Pi Pico W, designed to be managed from Home Assistant or any MQTT-capable service.

This is the Pico W port of Draco.


Features

  • MQTT control — subscribe to topics and toggle GPIO pins remotely from Home Assistant or any MQTT broker.
  • Relay/GPIO interface — drives a relay shield to control a water pump and a refill tank pump.
  • Heartbeat — publishes a keep-alive signal to an MQTT topic every 30 seconds so Home Assistant can detect disconnections.
  • Healthchecks.io integration — optional periodic HTTP ping so you can monitor uptime and get alerts if the Pico stops responding.
  • NTP time sync — sets the Pico's clock on boot via NTP.
  • Auto-recovery — resets the device automatically on WiFi loss or MQTT errors.

Hardware

Component Notes
Raspberry Pi Pico W Main controller
Relay shield Controls pumps via GPIO
Water pump Connected to GP20 by default
Refill tank pump Connected to GP21 by default (future use)

Project structure

draco-micropython/
├── main.py               # Entry point — WiFi init, MQTT loop, timers
├── requirements.py       # Installs MicroPython packages via mip
├── draco/
│   ├── config.py         # Configuration template (copy & fill in your values)
│   ├── mqtt_interface.py # MQTT client wrapper
│   └── wificonnection.py # WiFi connection helper
└── test/
    └── blinking.py       # LED blink test

Configuration

Copy draco/config.py and fill in your values:

WIFI_SSID = "your_ssid"
WIFI_PASSWD = "your_wifi_password"

MQTT_CLIENT = "draco-pico"
MQTT_BROKER_IP = "192.168.1.100"
MQTT_BROKER_PORT = 1883

WATERPUMP_TOPIC = "home/watering/waterpump"
DRACO_HB_TOPIC = "home/watering/DRACOHB"

WATERPUMP_PIN_OUT = "GP20"
REFILL_TANK_PIN_OUT = "GP21"

# Healthchecks.io (set to False to disable)
HEALTHCHECKSIO_ENABLE = True
HEALTHCHECKIO_URL = "https://hc-ping.com/your-uuid-here"
HEALTHCHECKIO_TIME_MS = 600000  # ping interval in ms (10 minutes)

Then update the import in main.py and requirements.py to point to your config file.


Installing dependencies

Run this once on the Pico W to install the required MicroPython packages over WiFi:

python requirements.py

This installs:

  • umqtt.simple — lightweight MQTT client
  • urllib.urequest — HTTP requests (used for healthchecks.io pings)

Running

Upload all files to the Pico W (e.g. with Thonny or mpremote), then run:

python main.py

On boot the device will:

  1. Connect to WiFi (LED blinks during connection, stays on when connected).
  2. Sync time via NTP.
  3. Connect to the MQTT broker and subscribe to the water pump topic.
  4. Start the heartbeat timer (every 30 s) and, if enabled, the healthchecks.io timer.
  5. Enter the main loop, polling MQTT messages and toggling the relay accordingly.

Controlling the pump via MQTT

Publish 1 to WATERPUMP_TOPIC to turn the pump on, 0 to turn it off:

mosquitto_pub -h 192.168.1.100 -t "home/watering/waterpump" -m "1"

Planned features

  • Soil moisture sensor support for automatic watering.
  • Temperature and relative humidity sensor integration.
  • Physical switch + second pump for autonomous tank refill.

Getting help

Open a GitHub Discussion for questions or ideas.


License

MIT

About

The tiny version of Draco implemented in micropython for raspberry pi pico W

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages