Ejemplo n.º 1
0
def main():
    debug = os.environ.get('DEBUG')
    logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
    delay = int(os.environ.get('POLL_PERIOD', '60'))
    server = os.environ['JENKINS_URI']
    status = StatusBoard(pwm=True)
    job_names = [os.environ.get('JENKINS_JOB_%d' % (i + 1)) for i in range(5)]
    job_color = [None for _ in job_names]
    ssh_relay = os.environ.get('SSH_RELAY')
    ssh_user = os.environ.get('SSH_USER')
    ssh_key = os.environ.get('SSH_KEY')

    while True:
        try:
            logging.info("Setting up ssh tunnel via %s@%s", ssh_user,
                         ssh_relay)
            url = urlparse(server)
            host = url.netloc.split(':')[0]
            port = url.port if url.port else 80
            with sshtunnel.open_tunnel(ssh_relay,
                                       ssh_username=ssh_user,
                                       ssh_pkey=ssh_key,
                                       remote_bind_address=(host, port),
                                       local_bind_address=('localhost',
                                                           12345)):

                poll_server(
                    url._replace(netloc='localhost:12345').geturl(), status,
                    job_names, job_color)
                time.sleep(delay)

        except ConnectionError:
            logging.exception("Unable to connect")
            display_warning(delay, status)
            job_color = [None for _ in job_names]
Ejemplo n.º 2
0
def monitor_websites():
    """
    Continuously update the led to reflect status of websites.
    """
    urls = [
        ('https://google.com/', None),
        ('https://stackoverflow.com/', None),
        ('https://github.com/ErrorActionPreference/', None),
        ('https://azure.microsoft.com/en-us/status/feed/', 'UK South'),
        ('https://grantadesign.com/', 'Software Engineer'),
    ]

    with StatusBoard() as status_board:
        #  Status board is upside down so run from top to bottom
        updates = [
            (status_board.five, 'https://www.google.com/', None),
            (status_board.four, 'https://stackoverflow.com/', None),
            (status_board.three, 'https://github.com/ErrorActionPreference/',
             None),
            (status_board.two,
             'https://azure.microsoft.com/en-us/status/feed/', 'UK South'),
            (status_board.one, 'https://grantadesign.workable.com/',
             'Software Engineer'),
        ]

        while True:
            for strip, url, error_text in updates:
                update_strip_status(strip, url, error_text)
                sleep(6)

            sleep(30)
Ejemplo n.º 3
0
def main():
    sb = StatusBoard(pwm=True)
    myLed = ledcontrolClass()
    
    myLed.getStatus()
        
    sb.one.lights.green.value =  myLed.getWeatherGreen()
    sb.one.lights.red.value =  myLed.getWeatherRed()
        
    sb.two.lights.green.value =  myLed.getSunriseGreen()
    sb.two.lights.red.value =  myLed.getSunriseRed()
        
    sb.three.lights.green.value =  myLed.getSunsetGreen()
    sb.three.lights.red.value =  myLed.getSunsetRed()
Ejemplo n.º 4
0
def main():
    debug = os.environ.get('DEBUG')
    logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
    delay = int(os.environ.get('POLL_PERIOD', '60'))
    server = os.environ['JENKINS_URI']
    status = StatusBoard(pwm=True)
    job_names = [os.environ.get('JENKINS_JOB_%d' % (i + 1)) for i in range(5)]
    job_color = [None for _ in job_names]
    username = os.environ.get('JENKINS_USERNAME', None)
    password = os.environ.get('JENKINS_PASSWORD', None)

    while True:
        try:
            poll_server(Jenkins(server, username=username, password=password),
                        status, job_names, job_color)
            time.sleep(delay)

        except ConnectionError:
            logging.exception("Unable to connect")
            display_warning(delay, status)
            job_color = [None for _ in job_names]
Ejemplo n.º 5
0
def main():
    sb = StatusBoard(pwm=True)
    myLed = ledcontrolClass()

    while True:
        myLed.getStatus()

        sb.one.lights.green.value = myLed.getWeatherGreen()
        sb.one.lights.red.value = myLed.getWeatherRed()

        sb.two.lights.green.value = myLed.getSunriseGreen()
        sb.two.lights.red.value = myLed.getSunriseRed()

        sb.three.lights.green.value = myLed.getSunsetGreen()
        sb.three.lights.red.value = myLed.getSunsetRed()

        sb.four.lights.green.value = myLed.getIrrigationGreen()
        sb.four.lights.red.value = myLed.getIrrigationRed()

        sb.five.lights.green.value = myLed.getHoseGreen()
        sb.five.lights.red.value = myLed.getHoseRed()

        sleep(2)
from gpiozero import StatusBoard
from speedtest import Speedtest
from time import sleep

sb = StatusBoard()

st = Speedtest()

while True:
    st.get_best_server()

    down = st.download()
    if down > 90000000:  # 90Mb
        sb.one.lights.green.on()
    if down > 70000000:  # 70Mb
        sb.two.lights.green.on()
    if down > 50000000:  # 50Mb
        sb.three.lights.green.on()
    if down > 30000000:  # 30Mb
        sb.four.lights.green.on()
    if down > 10000000:  # 10Mb
        sb.five.lights.green.on()

    up = st.upload()
    if up > 90000000:  # 9Mb
        sb.one.lights.red.on()
    if up > 7000000:  # 7Mb
        sb.two.lights.red.on()
    if up > 5000000:  # 5Mb
        sb.three.lights.red.on()
    if up > 3000000:  # 3Mb
Ejemplo n.º 7
0
from tubestatus import Status
from gpiozero import StatusBoard
from time import sleep

tube = Status()

sb = StatusBoard('central', 'northern', 'piccadilly')

while True:
    central = tube.get_status('Central')
    sb.central.lights.off()
    if central.description == 'Good Service':
        sb.central.lights.green.on()
    elif central.description == 'Minor Delays':
        sb.central.lights.green.blink()
    elif central.description == 'Severe Delays':
        sb.central.lights.red.on()
    elif central.description == 'Part Closure':
        sb.central.lights.red.blink()
    elif central.description == 'Service Closed':
        sb.central.lights.off()

    northern = tube.get_status('Northern')
    sb.northern.lights.off()
    if northern.description == 'Good Service':
        sb.northern.lights.green.on()
    elif northern.description == 'Minor Delays':
        sb.northern.lights.green.blink()
    elif northern.description == 'Severe Delays':
        sb.northern.lights.red.on()
    elif northern.description == 'Part Closure':
Ejemplo n.º 8
0
from gpiozero import StatusBoard
from gpiozero.tools import negated, smoothed
import requests
from time import sleep

sb = StatusBoard('raspberrypi', 'codeclub', 'coderdojo')


def website_up(url):
    while True:
        try:
            r = requests.get(url)
            yield r.ok
        except:
            yield False


statuses = {
    sb.raspberrypi: website_up('https://www.raspberrypi.org/'),
    sb.codeclub: website_up('https://www.codeclub.org.uk/'),
    sb.coderdojo: website_up('https://www.coderdojo.com/'),
}

for strip, website in statuses.items():
    strip.lights.green.source = smoothed(
        website, 2, any)  # allow 1 false negative out of 2
    strip.lights.green.source_delay = 60
    strip.lights.red.source = negated(strip.lights.green.values)
    strip.lights.red.source_delay = 60

google = website_up('https://www.google.com/')
from gpiozero import StatusBoard, PingServer
from gpiozero.tools import negated, smoothed
from signal import pause

sb = StatusBoard('mum', 'dad', 'alice')

statuses = {
    PingServer('192.168.1.5'): sb.mum,
    PingServer('192.168.1.6'): sb.dad,
    PingServer('192.168.1.7'): sb.alice,
}

for server, strip in statuses.items():
    strip.lights.green.source = smoothed(
        server.values, 2, any)  # allow 1 false negative out of 2
    strip.lights.green.source_delay = 60
    strip.lights.red.source = negated(strip.lights.green.values)

pause()
Ejemplo n.º 10
0
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]


sb = StatusBoard('cambridge', 'sheffield', 'nottingham')

while True:
    if is_raining('Cambridge', 'GB'):
        sb.cambridge.lights.red.on()
        sb.cambridge.lights.green.off()
    else:
        sb.cambridge.lights.green.on()
        sb.cambridge.lights.red.off()

    if is_raining('Sheffield', 'GB'):
        sb.sheffield.lights.red.on()
        sb.sheffield.lights.green.off()
    else:
        sb.sheffield.lights.green.on()
        sb.sheffield.lights.red.off()
Ejemplo n.º 11
0
from travispy import TravisPy
from gpiozero import StatusBoard
from time import sleep


def build_passed(repo):
    t = TravisPy()
    r = t.repo(repo)
    return r.last_build_state == 'passed'


sb = StatusBoard('gpiozero', 'documentation')

while True:
    if build_passed('RPi-Distro/python-gpiozero'):
        sb.gpiozero.lights.green.on()
        sb.gpiozero.lights.red.on()
    else:
        sb.gpiozero.lights.red.on()
        sb.gpiozero.lights.green.off()

    if build_passed('raspberrypi/documentation'):
        sb.documentation.lights.green.on()
        sb.documentation.lights.red.on()
    else:
        sb.documentation.lights.red.on()
        sb.documentation.lights.green.off()

    sleep(60 * 5)  # check every 5 minutes
Ejemplo n.º 12
0
from gpiozero import StatusBoard
from yahoo_finance import Share, Currency
from time import sleep

sb = StatusBoard('google', 'device', 'shares', 'xr')
share = Share('AAPL')  # Change the ticker symbol to your chosen share here.
share_price = 150.53  # Enter the price you paid for your shares here
currency_pair = Currency('BTCUSD')  # Enter your currency pair here.
currency_price = 4087.45  #Enter the price you paid for your currency here.

while True:
    current_price = share.get_price(
    )  # Call the get_price method to get stock price
    cu_price = float(
        current_price
    )  # Declare variable cu_price to convert stock price to floating point value.
    float(share_price)  # Convert the price you paid to a floating value too.
    if cu_price >= share_price:  # If share price is more than or equal to what you paid, switch on green led on third strip.
        sb.shares.lights.green.on()
    else:  # Otherwise switch on the red led:
        sb.shares.lights.red.on()
        sb.shares.lights.green.off()
    share.refresh()

    exchange_price = currency_pair.get_rate(
    )  # Call the get_rate method to get current exchange rate.
    xr_price = float(
        exchange_price
    )  # Declare variable xr_price to convert exchange rate to floating point value.
    float(
        currency_price
from gpiozero import StatusBoard
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

sb = StatusBoard('trump', 'kim', 'may')

while True:
    if in_the_news('Donald Trump'):
        sb.trump.lights.red.on()
        sb.trump.lights.green.off()
    else:
        sb.trump.lights.green.on()
        sb.trump.lights.red.on()

    if in_the_news('Kim Jong-Un'):
        sb.kim.lights.red.on()
        sb.kim.lights.green.off()
    else:
        sb.kim.lights.green.on()
        sb.kim.lights.red.on()

    if in_the_news('Theresa May'):
        sb.may.lights.red.on()
        sb.may.lights.green.off()
    else:
        sb.may.lights.green.on()
from tubestatus import Status
from gpiozero import StatusBoard
from time import sleep

tube = Status()
lines = ['Central', 'Northern', 'Piccadilly']

sz = StatusBoard()

while True:
    for strip, line in zip(sz, lines):
        status = tube.get_status(line)
        {
            'Good Service': strip.green.on,
            'Minor Delays': strip.green.blink,
            'Severe Delays': strip.red.on,
            'Part Closure': strip.red.blink,
            'Service Closed': strip.off,
        }[status.description]()
    sleep(60)  # check every minute
from gpiozero import StatusBoard, MotionSensor
from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero.tools import negated
from signal import pause

living_room_pi = PiGPIOFactory(host='192.168.1.3')
dining_room_pi = PiGPIOFactory(host='192.168.1.4')
bedroom_pi = PiGPIOFactory(host='192.168.1.5')

sb = StatusBoard('living_room', 'dining_room', 'bedroom')  # on this pi
living_room = MotionSensor(17, pin_factory=living_room_pi)  # remote sensors
dining_room = MotionSensor(17, pin_factory=dining_room_pi)
bedroom = MotionSensor(17, pin_factory=bedroom_pi)

while True:
    if living_room.motion_detected:
        sb.living_room.lights.green.on()
        sb.living_room.lights.red.off()
    else:
        sb.living_room.lights.red.on()
        sb.living_room.lights.green.off()

    if dining_room.motion_detected:
        sb.dining_room.lights.green.on()
        sb.dining_room.lights.red.off()
    else:
        sb.dining_room.lights.red.on()
        sb.dining_room.lights.green.off()

    if bedroom.motion_detected:
        sb.bedroom.lights.green.on()
Ejemplo n.º 16
0
from gpiozero import StatusBoard, PingServer
from gpiozero.tools import negated, smoothed
from time import sleep
from signal import pause
import requests

#def website_up(url):
#    try:
#        r = requests.get(url)
#        return r.ok
#    except:
#        return False

sb = StatusBoard('DDNS', 'VPN', 'CAM', 'WEB', 'APAGADO')  # only using 4 strips

sb.on()  # all leds on
sleep(1)
sb.off()  # all leds off
sleep(1)

statuses = {
    PingServer('10.0.10.253'): sb.CAM,
    PingServer('http://bocata.ddns.net/'): sb.DDNS,
}
#if website_up('http://bocata.ddns.net/'):
#            sb.DDNS.lights.green.on()
#            sb.DDNS.lights.red.off()
#       else:
#            sb.DDNS.lights.red.on()
#            sb.DDNS.lights.green.off()
from gpiozero import StatusBoard, 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]

sb = StatusBoard()  # on this pi
sensors = [MotionSensor(17, pin_factory=r) for r in remotes]  # remote sensors

for strip, sensor in zip(sb, sensors):
    strip.lights.green.source = sensor.values
    strip.lights.green.source_delay = 5  # check every 5 seconds
	strip.lights.red.source = negated(strip.lights.green.values)

pause()
Ejemplo n.º 18
0
from gpiozero import PingServer, StatusBoard
from time import sleep

device = PingServer('192.168.1.29')
google = PingServer('google.com')

sb = StatusBoard('google', 'device')

while True:
    if google.is_active:
        sb.google.lights.green.blink()
    else:
        sb.google.lights.green.off()

    if device.is_active:
        sb.device.lights.green.on()
        sb.device.lights.red.off()
    else:
        sb.device.lights.green.off()
        sb.device.lights.red.on()
    sleep(3)