-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP32-AdafruitOLED-ntfy_POST_minimal.ino
46 lines (37 loc) · 1.31 KB
/
ESP32-AdafruitOLED-ntfy_POST_minimal.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// https://wokwi.com/projects/394206176807480321
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntfyURL = "https://ntfy.sh/Esp32WokwiTest";
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.print("CONNECTED to SSID: ");
Serial.println(ssid);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(ntfyURL); // Specify request destination
http.addHeader("Content-Type", "text/plain"); // Set content type
// Your message
String message = "Message successful 😀";
int httpResponseCode = http.POST(message); // Send the POST request
if (httpResponseCode > 0) {
Serial.printf("[HTTP] POST request to ntfy.sh was successful, response code: %d\n", httpResponseCode);
String payload = http.getString();
Serial.println(payload); // Print response payload
} else {
Serial.printf("[HTTP] POST request to ntfy.sh failed, error: %s\n", http.errorToString(httpResponseCode).c_str());
}
http.end(); // Free resources
}
delay(60000); // Wait for 1 minute before sending the next message
}