#include <WiFi.h>
#include <HTTPClient.h>
const int LED_PIN = 4;
const int BUTTON_PIN = 22;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
connectWiFi(); // call
}
void loop() {
if ( digitalRead(BUTTON_PIN) == LOW ) {
digitalWrite(LED_PIN, HIGH); // 亮
sendLineNotify();
} else {
digitalWrite(LED_PIN, LOW); // 熄滅
}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void connectWiFi() {
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
}
void sendLineNotify() {
Serial.println("sendLineNotify!");
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify"); // 服務網址
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.addHeader("Authorization", "Bearer oeEdX1pAI6VM9g6022p9IRCSvYJhBSMBCX41QKACdKC");
http.POST("message=123456789");
http.end();
Serial.println("sendLineNotify Finish!!");
}