#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String botToken = "8423838682:AAHx5RF3rneCrVNeXdLMBMUov-u4R-GZieo";
String chatID = "284146772";
WiFiClientSecure client;
UniversalTelegramBot bot(botToken, client);
#define LED 2
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
client.setInsecure();
bot.sendMessage(chatID, "ارسل on أو off مرة ");
// ننتظر حتى تصل رسالة صحيحة
// while (true) {
// int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
// if (numNewMessages > 0) {
// String text = bot.messages[numNewMessages - 1].text;
// if (text == "on") {
// digitalWrite(LED, HIGH);
// bot.sendMessage(chatID, "تم تشغيل اللمبة");
// break;
// }
// else if (text == "off") {
// digitalWrite(LED, LOW);
// bot.sendMessage(chatID, "تم اطفاء اللمبة");
// break;
// }
// }
// delay(1000);
// }
// // توقف نهائي بعد تنفيذ الأمر
// while (true);
}
void loop() {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
if (numNewMessages > 0) {
String text = bot.messages[numNewMessages - 1].text;
String chat_id = bot.messages[numNewMessages - 1].chat_id;
if (text == "on") {
digitalWrite(LED, HIGH);
bot.sendMessage(chat_id, "تم تشغيل اللمبة");
}
else if (text == "off") {
digitalWrite(LED, LOW);
bot.sendMessage(chat_id, "تم اطفاء اللمبة");
}
}
bot.sendMessage(chatID, "اعد ارسال الحاله");
delay(1000);
}