Skip to content

Instantly share code, notes, and snippets.

@einarjh
Created December 25, 2019 15:19
Show Gist options
  • Save einarjh/bf09885841f4d1e181b3d15808502c01 to your computer and use it in GitHub Desktop.
Save einarjh/bf09885841f4d1e181b3d15808502c01 to your computer and use it in GitHub Desktop.
Simple script to poll moisture status for a https://thepihut.com/products/soil-moisture-sensor - suitable for Icinga monitoring
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
# Disable warnings
GPIO.setwarnings(False)
# Define channels
switch = 18
sensor = 17
# Set our GPIO numbering to BCM
GPIO.setmode(GPIO.BCM)
# Set inputs and outputs
GPIO.setup(switch, GPIO.OUT)
GPIO.setup(sensor, GPIO.IN)
# Activate sensor
GPIO.output(switch, GPIO.HIGH)
time.sleep(0.1)
if GPIO.input(sensor) == 0:
print("OK")
GPIO.output(switch, GPIO.LOW)
exit(0)
else:
print("MOISTURIZE ME")
GPIO.output(switch, GPIO.LOW)
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment