Created
December 25, 2019 15:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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