ESP8266 – send push notification via ntfy

Short example how you can send a push notification via ntfy from an ESP8266. I am using client.setInsecure(); – this is not recommended. If you have a better solution, let me know. I am using this for my doorbell, the ESP8266 resets when you ring the bell.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// Set WiFi credentials
#define WIFI_SSID "Name"
#define WIFI_PASS "Password"

// set static IP
IPAddress staticIP(192, 168, 2, 4);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192, 168, 2, 1);

void setup()
{
//Begin WiFi
WiFi.config(staticIP, gateway, subnet, dns);
WiFi.begin(WIFI_SSID, WIFI_PASS);

// Connecting to WiFi...
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
}

//send message
BearSSL::WiFiClientSecure client;
client.setInsecure();
HTTPClient http;
http.begin(client, "https://username:[email protected]/my-topic");
http.addHeader("Title", "Doorbell");
http.addHeader("Tags", "bell");
int httpCode = http.POST("Es hat geklingelt!");
String payload = http.getString();
http.end();

//enter deepsleep
ESP.deepSleep(0);
delay(100);
}

void loop() {
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *