import time from thing import PiThing pi_thing = PiThing() while True: pi_thing.set_ledr(True) time.sleep(0.5) pi_thing.set_ledr(False) time.sleep(0.5) pi_thing.set_ledv(False) time.sleep(0.5) pi_thing.set_ledv(True) time.sleep(0.5)
from thing import PiThing from flask import * import time import random import json from flask_socketio import SocketIO app = Flask(__name__) pi_thing = PiThing() socketio = SocketIO(app) @app.route('/') def index(): devicesStatus = pi_thing.read_devices_status() return render_template('index.html', devicesStatus=devicesStatus) @socketio.on('send_status') def send_status(message): devicesStatus = pi_thing.read_devices_status() str = { 'bulb': devicesStatus[0], 'fan': devicesStatus[1], 'ac': devicesStatus[2], 'tv': devicesStatus[3] } socketio.emit('devices_status', str) print(message)
import time from thing import PiThing #Create an instance of my pi thing pi_thing = PiThing() #get the current switch state and print it out switch = pi_thing.read_switch() print('Switch: {0}'.format(switch)) #Blink the LED forever print('Blinking LED (Ctrl-C to stop)...') while True: pi_thing.set_led(True) time.sleep(0.5) pi_thing.set_led(False) time.sleep(0.5)
from thing import PiThing import time pi_thing = PiThing() switch = pi_thing.read_switch() print("Switch :{0}".format(switch)) def switch_changed(state): if state: print("Switch is on"); else: print("Switch is off") pi_thing.on_switch_change(switch_changed) print("Blinking LED (Use Ctrl+c to Stop)...") while True: pi_thing.set_led(True) time.sleep(0.5) switch = pi_thing.read_switch() pi_thing.set_led(False) time.sleep(0.5)
import time from thing import PiThing # Create an instance of my pi thing pi_thing = PiThing() # Get the current switch state and print it out. switch = pi_thing.read_switch() print('Switch: {0}'.format(switch)) # Blink the LED forever. print('Blinking LED (Ctrl-C to stop)...') while True: pi_thing.set_led(True) time.sleep(0.5) pi_thing.set_led(False) time.sleep(0.5)
#!/usr/bin/env python import time from thing import PiThing # Instantiate a PiThing pi_thing = PiThing() # Get the current switch state switch = pi_thing.read_switch() print('Switch: {0}'.format(switch)) def switch_changed(switch_state): """function takes one argument, a boolean. Can be provided to pi_thing as a callback """ if switch_state: print('Switch is ON') else: print('Switch is OFF') def temperature_humidity_changed(temperature, humidity): """function takes two arguments Can be provided to pi_thing as a callback """ print('TemperatureDegreesC: {0:0.2F} Humidity: {1:0.2F}'.format(temperature, humidity)) # tell pi_thing to run switch_changed as a callback pi_thing.configure_switch_callback(switch_changed)
from thing import PiThing from time import sleep # Create an instance of PiThing pi_thing = PiThing() while True: pi_thing.set_led(True) sleep(2) pi_thing.set_led(False) sleep(2)
import time from thing import PiThing # Create an instance of my pi thing. pi_thing = PiThing() # Get the current switch state and print it out. switch = pi_thing.read_switch() print('Switch: {0}'.format(switch)) # Blink the LED forever. print('Blinking LED (Ctrl-C to stop)...') while True: pi_thing.set_led(True) time.sleep(0.5) pi_thing.set_led(False) time.sleep(0.5) # Get the current temp and light and print it out. light = pi_thing.get_light() temp = pi_thing.get_temperature() print ('Temp: {0:0.2F} Light: {1}'.format(temp, light))
#!/usr/bin/env python import time from thing import PiThing # Instantiate a PiThing pi_thing = PiThing() # Get the current switch state switch = pi_thing.read_switch() print('Switch: {0}'.format(switch)) def switch_changed(switch_state): """function takes one argument, a boolean. Can be provided to pi_thing as a callback """ if switch_state: print('Switch is ON') else: print('Switch is OFF') def temperature_humidity_changed(temperature, humidity): """function takes two arguments Can be provided to pi_thing as a callback """ print('TemperatureDegreesC: {0:0.2F} Humidity: {1:0.2F}'.format( temperature, humidity))
from thing import PiThing import time #Create an instance of my pi thing pi_thing = PiThing() #Get the current state of switch state and print it out switch = pi_thing.read_switch() print('Switch: {0}'.format(switch)) #Switch Relay Forever. """print("Switching Relay (Ctrl-C to stop)") while True: pi_thing.set_led(True) time.sleep(0.5) pi_thing.set_led(False) time.sleep(0.5)"""
"""main.py uses Flask web server for network communications and PiThing to read and write to raspberry pi gpio pins. """ # instantiate flask app app = Flask(__name__) # can use SECRET_KEY to increase security #app.config['SECRET_KEY'] = 'secret!' # On flask development server, "WebSocket transport not available" # must fall back to long polling # https://flask-socketio.readthedocs.io/en/latest/ socketio = SocketIO(app) # instantiate pi_thing as a global variable pi_thing = PiThing() # default route raspberry pi / @app.route("/") def index(): # get current switch value switch_value = pi_thing.read_switch() # render index.html, passing in switch_value return render_template('index.html', switch=switch_value) @socketio.on('change_led') def change_led(led_state): if led_state == 'off': pi_thing.set_led(False) elif led_state == 'on': pi_thing.set_led(True)
"""main.py uses Flask web server for network communications and PiThing to read and write to raspberry pi gpio pins. """ # instantiate flask app app = Flask(__name__) # can use SECRET_KEY to increase security #app.config['SECRET_KEY'] = 'secret!' # On flask development server, "WebSocket transport not available" # must fall back to long polling # https://flask-socketio.readthedocs.io/en/latest/ socketio = SocketIO(app) # instantiate pi_thing as a global variable pi_thing = PiThing() # default route raspberry pi / @app.route("/") def index(): # get current switch value switch_value = pi_thing.read_switch() # render index.html, passing in switch_value return render_template('index.html', switch=switch_value) @socketio.on('change_led') def change_led(led_state): if led_state == 'off': pi_thing.set_led(False)