Created
December 19, 2023 23:03
-
-
Save chrismatthieu/6847cba5c457c99f57752825f4cd1684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import network | |
from time import sleep | |
import machine | |
from picozero import LED | |
from picozero import Button | |
import requests | |
blue = LED(13) | |
button = Button(18) | |
def yo(): | |
blue.on() | |
sleep(2) | |
blue.off() | |
url = 'https://api.yo.im/yo' | |
myobj = {"username":"topher","api_token":"c9feac-xxx-fb69c4"} | |
x = requests.post(url, json = myobj) | |
button.when_pressed = yo | |
ssid = 'your wifi network name' | |
password = 'your wifi password' | |
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 | |
try: | |
ip = connect() | |
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