print("Hello, ESP32!")
import machine,dht,utime,time,network,urequests
br = "%0d%0a" #換行字符
def lineNotifyMessage(token, msg):
headers = {
"Authorization": "Bearer " + token,
"Content-Type" : "application/x-www-form-urlencoded"
}
urlmsg = "https://notify-api.line.me/api/notify/?message=" + msg
r = urequests.post(urlmsg, headers = headers)
print(r.text)
return r.status_code
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!")
temp = 19.3
# 修改為你要傳送的訊息內容
input_str = 'LINE Notify 來自 ESP32---'
# 轉換成 UTF-8 編碼,以便傳送中文內容
messageT = "".join([hex(i).replace("0x", "%") for i in (input_str.encode('utf-8'))])
message = br + messageT #訊息跳行後顯示
input_str = "現在溫度 : " + str(temp)
messageT = "".join([hex(i).replace("0x", "%") for i in (input_str.encode('utf-8'))])
message = message + br + messageT #訊息跳行後顯示
input_str = "賈皓宇,B10913041 "
messageT = "".join([hex(i).replace("0x", "%") for i in (input_str.encode('utf-8'))])
message = message + br + messageT #訊息跳行後顯示
# 修改為你的權杖內容
token = 'hY1BpWn0bfEOTLFKPxc7kCE5SFWa4b83Smi0hRzSvYl'
print(lineNotifyMessage(token, message))