Guest User

ESP8266 Mailbox Notifier

a guest
Jan 22nd, 2021
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClientSecure.h>
  3. #include <UniversalTelegramBot.h>
  4.  
  5. //edit BOTtoken, chat_id, message and wifi credentials
  6. #define BOTtoken "0123456789:AAAAAAAbbbbbcccccddddddeeeeeeffffffgggg"
  7. #define chat_id "9876543210"
  8. #define message "You have mail!"
  9. const char* ssid = "wifi-name";
  10. const char* password = "wifi-password";
  11.  
  12. WiFiClientSecure client;
  13. UniversalTelegramBot bot(BOTtoken, client);
  14.  
  15. void setup()
  16. {
  17.   client.setInsecure();
  18.   int tries=0;
  19.   WiFi.mode(WIFI_STA);
  20.   WiFi.begin(ssid, password);
  21.  
  22.     //tries for 15sec to establish a wifi connection
  23.   while (WiFi.status() != WL_CONNECTED && tries<15)
  24.   {
  25.     delay(1000);
  26.     tries++;
  27.   }
  28.  
  29.     //if there was no successful wifi connection after 15 seconds go to deep sleep
  30.   if (tries==15)
  31.   {
  32.     ESP.deepSleep(0);
  33.   }  
  34. }
  35.  
  36. void loop()
  37. {
  38.     //send message and go to deep sleep
  39.   bot.sendMessage(chat_id, message, "");
  40.   ESP.deepSleep(0);
  41. }
RAW Paste Data