Last active
June 18, 2023 04:56
-
-
Save syanyong/244cd74b766bb4ca98d9c42a1f01d1dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFi.h> | |
#include <HTTPClient.h> | |
#define SERVER_NAME "https://notify-api.line.me/api/notify" | |
#define TOKEN "" | |
WiFiClient client; | |
HTTPClient http; | |
void sendLineNotify (const char * msg) { | |
String payload = "message=" + String (msg); | |
int httpResponseCode = http.POST(payload); | |
if (httpResponseCode > 0) { | |
String response = http.getString(); | |
Serial.println(httpResponseCode); | |
Serial.println(response); | |
} else { | |
Serial.print("Error sending msg. HTTP response code: "); | |
Serial.println(httpResponseCode); | |
} | |
} | |
void sendLineSticker (const char * msg, int pkgId, int stickerId) { | |
String payload = "message=" + String (msg) + "&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 msg. HTTP response code: "); | |
Serial.println(httpResponseCode); | |
} | |
} | |
void sendLineImageURL (const char * msg, const char* imageUrl) { | |
String payload = "message=" + String (msg) + "&imageThumbnail=" + imageUrl + "&imageFullsize=" + imageUrl; | |
int httpResponseCode = http.POST(payload); | |
if (httpResponseCode > 0) { | |
String response = http.getString(); | |
Serial.println(httpResponseCode); | |
Serial.println(response); | |
} else { | |
Serial.print("Error sending msg. HTTP response code: "); | |
Serial.println(httpResponseCode); | |
} | |
} | |
void setup() { | |
// Serial connection | |
Serial.begin(9600); | |
Serial.print("Connecting to WiFi"); | |
// Wifi connection | |
WiFi.begin("Wokwi-GUEST", "", 6); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(100); | |
Serial.print("."); | |
} | |
Serial.println(" Connected!"); | |
// HTTP Request | |
http.begin(SERVER_NAME); | |
http.addHeader("Authorization", "Bearer " + String(TOKEN)); | |
http.addHeader("Content-type", "application/x-www-form-urlencoded"); | |
sendLineNotify("Hello world"); | |
sendLineSticker("Sticker", 3, 240); | |
sendLineImageURL("TEST_IMG", "https://home.krai.io/wp-content/uploads/2019/08/cropped-logo_raikmitl-200x84.png"); | |
} | |
void loop() { | |
delay(100); // TODO: Build something amazing! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment