Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #define WIFI_SSID "WIFI_NAME"
- #define WIFI_PASSWORD "WIFI_PASSWORD"
- #define BOT_TOKEN "BOT_TOKEN_BOT_FATHER"
- WiFiClientSecure secured_client;
- UniversalTelegramBot bot(BOT_TOKEN, secured_client);
- String chat_id = "CHAT_ID_IDBOT";
- void setup()
- {
- Serial.begin(9600);
- initWiFi_and_Time_For_Telegram();
- bot.sendMessage(chat_id, "Project Connected to Telegram Server <ONLINE>");
- }
- void loop() {
- //bot.sendMessage(chat_id, "Alert Message");
- }
- void initWiFi_and_Time_For_Telegram() {
- Serial.println();
- Serial.print("Connecting to Wifi SSID ");
- Serial.print(WIFI_SSID);
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(500);
- }
- Serial.print("\nWiFi connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.print("Retrieving time: ");
- configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
- time_t now = time(nullptr);
- while (now < 24 * 3600)
- {
- Serial.print(".");
- delay(100);
- now = time(nullptr);
- }
- Serial.println(now);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement