Skip to content

Instantly share code, notes, and snippets.

@spynappels
Created November 28, 2017 21:49
Show Gist options
  • Save spynappels/57283e98c210c5492e20fc1088455bbe to your computer and use it in GitHub Desktop.
Save spynappels/57283e98c210c5492e20fc1088455bbe to your computer and use it in GitHub Desktop.
Equally simple and dirty Python3 monitoring script for Brandmeister Repeaters, using the Brandmeister API rather than querying a Master server directly. It check whether the last_updated timestamp occurred within the last 5 minutes. This could probably be tuned down.
#!/usr/bin/python3
from gpiozero import StatusBoard
import requests
import datetime
import time
# instantiate a StatusBoard instance
status = StatusBoard('gb7ny', 'gb7hi', 'gb7mw','gb7ah','gb7ni')
# define the check function
def bmcheck():
threshold = datetime.datetime.now()-datetime.timedelta(minutes=5)
# gb7ny
gb7ny = requests.get('http://api.brandmeister.network/v1.0/repeater/?action=GET&q=235510')
nydata = gb7ny.json()
nyts = nydata['last_updated']
if nyts > str(threshold):
status.gb7ny.lights.green.on()
status.gb7ny.lights.red.off()
else:
status.gb7ny.lights.green.off()
status.gb7ny.lights.red.on()
# gb7hi
gb7hi = requests.get('http://api.brandmeister.network/v1.0/repeater/?action=GET&q=235526')
hidata = gb7hi.json()
hits = hidata['last_updated']
if hits > str(threshold):
status.gb7hi.lights.green.on()
status.gb7hi.lights.red.off()
else:
status.gb7hi.lights.green.off()
status.gb7hi.lights.red.on()
# gb7mw
gb7mw = requests.get('http://api.brandmeister.network/v1.0/repeater/?action=GET&q=235506')
mwdata = gb7mw.json()
mwts = mwdata['last_updated']
if mwts > str(threshold):
status.gb7mw.lights.green.on()
status.gb7mw.lights.red.off()
else:
status.gb7mw.lights.green.off()
status.gb7mw.lights.red.on()
# gb7ah
gb7ah = requests.get('http://api.brandmeister.network/v1.0/repeater/?action=GET&q=235507')
ahdata = gb7ah.json()
ahts = ahdata['last_updated']
if ahts > str(threshold):
status.gb7ah.lights.green.on()
status.gb7ah.lights.red.off()
else:
status.gb7ah.lights.green.off()
status.gb7ah.lights.red.on()
# gb7ni
gb7ni = requests.get('http://api.brandmeister.network/v1.0/repeater/?action=GET&q=235516')
nidata = gb7ni.json()
nits = nidata['last_updated']
if nits > str(threshold):
status.gb7ni.lights.green.on()
status.gb7ni.lights.red.off()
else:
status.gb7ni.lights.green.off()
status.gb7ni.lights.red.on()
time.sleep(60)
# Run the function forever
while True:
bmcheck()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment