i have program for activate relay with telegram, its work but not really work 100%, because its doesn't give me reply from as my coding do and the wifi esp had connected, thanks for the time before
#include <ESP8266WiFi.h>
#include <UniversalTelegramBot.h>
const char* ssid = "*****";
const char* password = "*****";
const char* telegramToken = "*****";
const char* chat_id = "*****";
WiFiClientSecure client;
UniversalTelegramBot bot(telegramToken, client);
const int relayPin = 5;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi!");
Serial.println("Telegram bot connected!");
pinMode(relayPin, OUTPUT);
}
void loop() {
// Mendapatkan pesan dari Telegram
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages) {
Serial.println("New message received!");
String command = bot.messages[numNewMessages - 1].text;
Serial.println("Command: " + command);
if (command == "/on") {
digitalWrite(relayPin, HIGH); // Menyalakan relay
bot.sendMessage(bot.messages[numNewMessages - 1].chat_id, "Relay turned ON!");
} else if (command == "/off") {
digitalWrite(relayPin, LOW); // Mematikan relay
bot.sendMessage(bot.messages[numNewMessages - 1].chat_id, "Relay turned OFF!");
} else {
bot.sendMessage(bot.messages[numNewMessages - 1].chat_id, "Invalid command!");
}
numNewMessages--;
}
delay(1000);
}