Skip to content

Instantly share code, notes, and snippets.

@syanyong
Last active June 18, 2023 04:29
Show Gist options
  • Save syanyong/7bf1b4a6747c9d8d7524c979c915056b to your computer and use it in GitHub Desktop.
Save syanyong/7bf1b4a6747c9d8d7524c979c915056b to your computer and use it in GitHub Desktop.
#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 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");
}
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