Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oleh-zaporozhets/c88c03dcdd188265d4b4abd1328ba2f0 to your computer and use it in GitHub Desktop.
Save oleh-zaporozhets/c88c03dcdd188265d4b4abd1328ba2f0 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define WIFI_NAME ""
#define WIFI_PASSWORD ""
#define HOST ""
#define PATH "/webhooks/electricity/"
#define PORT 443
#define CHAT_ID ""
#define TIMER_DELAY 60000
unsigned long timestamp = 0;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println("Connecting to WiFi...");
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("WiFi connected with ip: ");
Serial.println(WiFi.localIP());
}
void loop() {
if ((millis() - timestamp) > TIMER_DELAY) {
if (WiFi.status() == WL_CONNECTED) {
BearSSL::WiFiClientSecure client;
client.setInsecure();
HTTPClient http;
String path = PATH;
path += CHAT_ID;
if (http.begin(client, HOST, PORT, path)) {
http.GET();
http.end();
} else {
Serial.println("Failed to connect to server.");
}
}
timestamp = millis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment