#include <WiFi.h>
#include <HTTPClient.h>
#define SSID "Wokwi-GUEST"
#define SERVER_NAME "https://notify-api.line.me/api/notify"
#define TOKEN "xrbYaEXExZTKLqdaeKK6eRLJahRYH5Aa5rblZ8MNMaJ"
void sendLineNotify(const char* message) {
HTTPClient http;
http.begin(SERVER_NAME);
http.addHeader("Authorization", "Bearer " + String(TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String payload = "message=" + String(message);
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
}
else {
Serial.print("Error occured while sending message. HTTP response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void sendLineSticker(const char* message, int pkgId, int stickerId) {
HTTPClient http;
http.begin(SERVER_NAME);
http.addHeader("Authorization", "Bearer " + String(TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String payload = "message=" + String(message) + "&stickerPackageId=" + String(pkgId) + "&stickerId=" + String(stickerId);
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
}
else {
Serial.print("Error sending message. HTTP response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void sendLineImageURL(const char* message, const char* imageUrl)
{
HTTPClient http;
http.begin(SERVER_NAME);
http.addHeader("Authorization", "Bearer " + String(TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String payload = "message="+String(message)+"&imageThumbnail"+String(imageUrl)+"&imageFullsize"+String(imageUrl);
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error sending message. HTTP response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void setup() {
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin(SSID, "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("Connected!");
sendLineNotify("High Temperature 🌡️ = 80.00");
//sendLineSticker("Sticker Test",1,1);
//sendLineImageURL(".","https://gameplaymania.com/wp-content/uploads/thumbs/custom/A/among-us-thumbnail-gameplaymania.jpg");
}
void loop() {
}