#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* token = "6517070522:AAEt7-AwNaaEEtpPyBoHU9yHjGJ-djQK-_I";
const long chatId = 1653376012; // Ganti dengan Chat ID Anda
const int led = 2;
WiFiClientSecure client;
UniversalTelegramBot bot(token, client);
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");
}
void loop() {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages) {
for (int i = 0; i < numNewMessages; i++) {
String chat_id = bot.messages[i].chat_id;
if (chat_id.equals(String(chatId))) {
String text = bot.messages[i].text;
if (text == "/on") {
digitalWrite(led, HIGH);
}
else if (text == "/off") {
digitalWrite(led, LOW);
}
}
}
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
}