import network
import time
from machine import Pin
import urequests
BUTTON_PIN = 22
LED_PIN = 4
def start():
print("Connecting to WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Connected!")
def sendlinenotify():
# 访问ip地址 api
data = {
"message": "1001",
}
r = urequests.post("https://notify-api.line.me/api/notify", headers={"Content-Type":"application/x-www-form-urlencoded", "Authorization":"Bearer 1H1QjRRXbfENtQihim2NCOxJqkbeQb3SNiOa1xBFX3Y"}, json=data)
# r.request(headers={"Content-Type":"application/x-www-form-urlencoded", "Authorization", "Bearer ZN70px8403mxC7nLWMve7Aqo9OnrRQ9or7uhuYNTDsh"})
# r.post("https://notify-api.line.me/api/notify", )
# # urequests.post(url, **kw)
# print(r)
# print(r.content) # 返回响应的内容
# print(r.text) # 以文本方式返回响应的内容
# print(r.content)
# print(r.json()) # 返回响应的json编码内容并转为dict类型
print(r)
r.close()
start()
led = Pin(LED_PIN, Pin.OUT)
button = Pin(BUTTON_PIN, Pin.IN)
while True:
if button.value() == 0:
led.value(1)
else:
led.value(0)
time.sleep(0.1)
sendlinenotify()