Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrismatthieu/d5f73b097e6c00a0ac872fcb4ac665ff to your computer and use it in GitHub Desktop.
Save chrismatthieu/d5f73b097e6c00a0ac872fcb4ac665ff to your computer and use it in GitHub Desktop.
import network
from time import sleep
import machine
from picozero import LED
from picozero import Button
import requests
import utime
blue = LED(13)
button = Button(18)
sensor_pin = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_DOWN)
def yo():
blue.on()
sleep(2)
blue.off()
url = 'https://api.yo.im/yo'
myobj = {"username":"topher","api_token":"c9feacb4-8866-xxx-4eac58fb69c4"}
x = requests.post(url, json = myobj)
button.when_pressed = yo
ssid = 'CajunNet'
password = 'xxx'
def connect():
#Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while wlan.isconnected() == False:
print('Waiting for connection...')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
blue.on()
sleep(1)
blue.off()
return ip
def pir_handler(pin):
utime.sleep_ms(100)
if pin.value():
yo()
try:
ip = connect()
sensor_pin.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)
while True:
pass
except KeyboardInterrupt:
machine.reset()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment