#include <dummy.
h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#define WIFI_SSID "vivo Y22"
#define WIFI_PASSWORD "theju1055"
#define BOT_TOKEN "7548137705:AAFKRbLrT2EXlNNTGfbOa3ptTP6eOUq9NmY"
const unsigned long BOT_MTBS=1000;
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
unsigned long bot_lasttime;
const int ledPin=02;
int ledStatus=0 ;
void handleNewMessages(int numNewMessages)
Serial.print("handleNewMessages");
Serial.println(numNewMessages);
for (int i=0;i< numNewMessages; i++)
String chat_id= bot.messages[i].chat_id;
String text=bot.messages[i].text;
Serial.println(text);
String from_name=bot.messages[i].from_name;
if (from_name=="")
from_name="Guest";
if(text=="/ledon")
Serial.print("LED turning on ");
digitalWrite(ledPin, HIGH);
ledStatus=1;
bot.sendMessage(chat_id, "Led is ON", "",0);
if (text=="/ledoff")
Serial.print("LED turning off ");
ledStatus=0;
digitalWrite(ledPin, LOW);
bot.sendMessage(chat_id, "Led is OFF", "");
if (text== "/status")
if (ledStatus)
bot.sendMessage(chat_id, "Led is ON", "");
else
bot.sendMessage(chat_id, "Led is OFF", "");
}
}
if (text=="/start")
String welcome="Welcome to Universal Arduino Telegram Bot IOT Project.\n";
welcome +="/ledon: to switch the Led ON\n";
welcome +="/ledoff: to switch the Led OFF\n";
welcome += "/status: Returns current status of LED\n";
bot.sendMessage(chat_id, welcome, "Markdown");
void setup()
Serial.begin(115200);
Serial.println();
pinMode(ledPin, OUTPUT);
delay(10);
Serial.print("Connecting to WiFi_SSID ");
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
while (WiFi.status() != WL_CONNECTED)
Serial.print(".");
delay(500);
Serial.print("\nWiFi connected. IP address: ");
Serial.println(WiFi.localIP());
void loop()
if (millis() - bot_lasttime > BOT_MTBS)
int numNewMessages=bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages)
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received+1);
bot_lasttime=millis();