from gpiozero import StatusZero import requests from time import sleep def website_up(url): try: r = requests.get(url) return r.ok except: return False sz = StatusZero('raspberrypi', 'codeclub', 'coderdojo') while True: if website_up('https://www.google.com/'): if website_up('https://www.raspberrypi.org/'): sz.raspberrypi.green.on() sz.raspberrypi.red.off() else: sz.raspberrypi.red.on() sz.raspberrypi.green.off() if website_up('https://www.codeclub.org.uk/'): sz.codeclub.green.on() sz.codeclub.red.off() else: sz.codeclub.red.on() sz.codeclub.green.off()
from gpiozero import StatusZero, MotionSensor from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero.tools import negated from signal import pause ips = ['192.168.1.3', '192.168.1.4', '192.168.1.5'] remotes = [PiGPIOFactory(host=ip) for ip in ips] sz = StatusZero() # on this pi sensors = [MotionSensor(17, pin_factory=r) for r in remotes] # remote sensors for strip, sensor in zip(leds, sensors): strip.green.source = sensor.values strip.green.source_delay = 5 # check every 5 seconds strip.red.source = negated(strip.green.values) pause()
KEY = 'ENTER API KEY HERE' # http://openweathermap.org/ BASE_URL = 'http://api.openweathermap.org/data/2.5/forecast?APPID={}'.format( KEY) with open('cities.json') as f: cities = json.load(f) def is_raining(city, country): city_id = cities[country][city] url = '{}&id={}'.format(BASE_URL, city_id) j = requests.get(url).json() return 'rain' in j['list'][2] sz = StatusZero('dundee', 'cambridge', 'sheffield') while True: if is_raining('Dundee', 'GB'): sz.dundee.red.on() sz.dundee.green.off() else: sz.dundee.green.on() sz.dundee.red.off() if is_raining('Cambridge', 'GB'): sz.cambridge.red.on() sz.cambridge.green.off() else: sz.cambridge.green.on() sz.cambridge.red.off()
from gpiozero import StatusZero, PingServer from time import sleep sz = StatusZero('mum', 'dad', 'alice') mum = PingServer('192.168.1.3') dad = PingServer('192.168.1.4') alice = PingServer('192.168.1.5') while True: if mum.is_active: sz.mum.green.on() sz.mum.red.on() else: sz.mum.red.on() sz.mum.green.off() if dad.is_active: sz.dad.green.on() sz.dad.red.on() else: sz.dad.red.on() sz.dad.green.off() if alice.is_active: sz.alice.green.on() sz.alice.red.on() else: sz.alice.red.on() sz.alice.green.off()
from travispy import TravisPy from gpiozero import StatusZero from gpiozero.tools import negated from time import sleep from signal import pause def build_passed(repo): t = TravisPy() r = t.repo(repo) while True: yield r.last_build_state == 'passed' sz = StatusZero() repos = ['RPi-Distro/python-gpiozero', 'raspberrypi/documentation'] for strip, repo in zip(sz, repos): strip.green.source = build_passed(repo) strip.green.source_delay = 60 * 5 # check every 5 minutes strip.red.source = negated(strip.green.values) pause()
from gpiozero import StatusZero import requests from time import sleep def in_the_news(text): url = 'http://www.bbc.co.uk/news' r = requests.get(url) return text in r.text sz = StatusZero('trump', 'kim', 'may') while True: if in_the_news('Donald Trump'): sz.trump.red.on() sz.trump.green.off() else: sz.trump.green.on() sz.trump.red.on() if in_the_news('Kim Jong-Un'): sz.kim.red.on() sz.kim.green.off() else: sz.kim.green.on() sz.kim.red.on() if in_the_news('Theresa May'): sz.may.red.on() sz.may.green.off() else: sz.may.green.on()
from travispy import TravisPy from gpiozero import StatusZero from time import sleep def build_passed(repo): t = TravisPy() r = t.repo(repo) return r.last_build_state == 'passed' sz = StatusZero('gpiozero', 'documentation') while True: if build_passed('RPi-Distro/python-gpiozero'): sz.gpiozero.green.on() sz.gpiozero.red.off() else: sz.gpiozero.red.on() sz.gpiozero.green.off() if build_passed('raspberrypi/documentation'): sz.documentation.green.on() sz.documentation.red.off() else: sz.documentation.red.on() sz.documentation.green.off() sleep(60 * 5) # check every 5 minutes
#!/usr/bin/env python3 import socket from gpiozero import StatusZero HOST = '127.0.0.5' PORT = 65432 debugging = False board = StatusZero(pwm=True) def internetGood(): if debugging: print("Internet Green Light On") board.one.off() board.one.green.on() def internetOK(): if debugging: print("Internet Green Light Pulse") board.one.off() board.one.green.pulse(2, 2) def internetBad(): if debugging: print("Internet Red Light Blink") board.one.off() board.one.red.blink()
from gpiozero import StatusZero from gpiozero.tools import negated, smoothed import requests from time import sleep sz = StatusZero('raspberrypi', 'codeclub', 'coderdojo') def website_up(url): while True: try: r = requests.get(url) yield r.ok except: yield False statuses = { sz.raspberrypi: website_up('https://www.raspberrypi.org/'), sz.codeclub: website_up('https://www.codeclub.org.uk/'), sz.coderdojo: website_up('https://www.coderdojo.com/'), } for strip, website in statuses.items(): strip.green.source = smoothed(website, 2, any) # allow 1 false negative out of 2 strip.green.source_delay = 60 strip.red.source = negated(strip.green.values) strip.red.source_delay = 60 google = website_up('https://www.google.com/')
from gpiozero import StatusZero from speedtest import Speedtest from time import sleep sb = StatusZero() st = Speedtest() def update(): while True: st.get_best_server() down = st.download() up = st.upload() yield ( (None, (up > 1000000, down > 1000000)), (None, (up > 3000000, down > 3000000)), (None, (up > 5000000, down > 5000000)), (None, (up > 7000000, down > 7000000)), (None, (up > 9000000, down > 9000000)), ) sb.source = update() sb.source_delay = 60 * 10 # check every 10 minutes while True: print(tuple(sb.value)) sleep(1)
""" from gpiozero import StatusZero import requests from time import sleep def website_up(url): try: r = requests.get(url) return r.ok except: return False sz = StatusZero('mywebsite', 'discord', 'twitter') while True: if website_up('https://www.google.com/'): d = requests.get( 'https://srhpyqt94yxb.statuspage.io/api/v2/status.json').json() if website_up('https://apollodev.ml/'): sz.mywebsite.green.on() sz.mywebsite.red.off() else: sz.mywebsite.red.on() sz.mywebsite.green.off() if d['status']['indicator'] == "none": sz.discord.green.on() sz.discord.red.off()
from tubestatus import Status from gpiozero import StatusZero from time import sleep tube = Status() sz = StatusZero('central', 'northern', 'piccadilly') while True: central = tube.get_status('Central') sz.central.off() if central.description == 'Good Service': sz.central.green.on() elif central.description == 'Minor Delays': sz.central.green.blink() elif central.description == 'Severe Delays': sz.central.red.on() elif central.description == 'Part Closure': sz.central.red.blink() elif central.description == 'Service Closed': sz.central.off() northern = tube.get_status('Northern') sz.northern.off() if northern.description == 'Good Service': sz.northern.green.on() elif northern.description == 'Minor Delays': sz.northern.green.blink() elif northern.description == 'Severe Delays': sz.northern.red.on() elif northern.description == 'Part Closure':
#Python LED Web Handler from flask import Flask, request, render_template from flask_restful import Resource, Api from json import dumps from flask_jsonpify import jsonify from gpiozero import StatusZero from time import sleep sz = StatusZero() sz.off() # initialize off app = Flask(__name__) api = Api(app) class InvalidUsage(Exception): status_code = 400 def __init(self, message, status_code=None, payload=None): Exception.__init__(self) self.message = message if status_code is not None: self.status_code = status_code self.payload = payload def to_dict(self): retval = dict(self.payload or ()) retval['message'] = self.message return retval
KEY = 'ENTER API KEY HERE' # http://openweathermap.org/ BASE_URL = 'http://api.openweathermap.org/data/2.5/forecast?APPID={}'.format( KEY) with open('cities.json') as f: cities = json.load(f) def is_raining(city, country): city_id = cities[country][city] url = '{}&id={}'.format(BASE_URL, city_id) j = requests.get(url).json() return 'rain' in j['list'][2] sz = StatusZero('cambridge', 'sheffield', 'nottingham') while True: if is_raining('Cambridge', 'GB'): sz.cambridge.red.on() sz.cambridge.green.off() else: sz.cambridge.green.on() sz.cambridge.red.off() if is_raining('Sheffield', 'GB'): sz.sheffield.red.on() sz.sheffield.green.off() else: sz.sheffield.green.on() sz.sheffield.red.off()