#include <WiFi.h>
#include <HTTPClient.h>
char *ssid = "Wokwi-GUEST";
char *pass = "";
#define PushButton1 12
#define PushButton2 13
#define LINE_TOKEN "WoXtpv1LIfXk38yajzoXqg6o2Tl8RTDzxQW2Trh8sEE"
String Text_1 = "!สมอง2เซน!";
String Text_2 = "สมอง2เซน";
void setup() {
Serial.begin(115200);
pinMode(PushButton1, INPUT_PULLUP);
pinMode(PushButton2, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
WiFi.begin(ssid, pass);
Serial.print("Connecting to WiFi .");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(100);
}
Serial.println(WiFi.localIP());
}
void loop()
{
if (digitalRead(PushButton1) == 0) {
Serial.print(Text_1);
sendLineNotify(Text_1); Serial.println(" 🙄");
}
if (digitalRead(PushButton2) == 0) {
Serial.print(Text_2);
sendLineNotify(Text_2); Serial.println(" 😢");
}
}
void sendLineNotify(String message) {
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify");
http.addHeader("Authorization", "Bearer " + String(LINE_TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String encodedMessage = "message=" + urlEncode(message);
http.POST(encodedMessage);
http.end();
}
String urlEncode(String value) {
String encodedValue = "";
char c;
for (size_t i = 0; i < value.length(); i++) {
c = value.charAt(i);
if (isAlphaNumeric(c)) {
encodedValue += c;
} else {
encodedValue += String('%');
encodedValue += String(c, HEX);
}
}
return encodedValue;
}