ESP32, Cara Mengakses TelegramBot Kontrol Relay / Led

Hello Sahabat Anak Kendali.

pada kesempatan kali ini saya akan menuliskan artikel tentang ESP32, Cara Mengakses TelegramBot Kontrol Relay / Led. Tutorial Sebelumnya Baca Juga : ESP32, Cara Mengakses LCD I2C 16x2

ESP32, Cara Mengakses TelegramBot Kontrol Relay / Led

sebelumnya juga saya sudah menuliskan banyak artikel mengenai Telegram Bot dengan ESP8266, sekarang kita akan mencoba meggunakan ESP32 untuk mengontrol Relay dengan Telegram keyword : Bot Telegram ESP32 ESP32 TelegramBot Belajar ESP32 Belajar ESP32 Pemula Kontrol LED ESP32 TelegramBot Universal TelegramBot baiklah, sebelum itu siapkan dulu bahan bahannya. ESP32 LED Library Universal Telelgram yang dapat di download disini!! bila diperlukan library Arduinojson.h silahkan download disini!! selanjutnya silahkan buat Program Telegram Bot seperti dibawah ini :

#include <WiFi.h> #include <WiFiClientSecure.h> #include <UniversalTelegramBot.h> // Initialize Wifi connection to the router char ssid[] = “www.anakkendali.com"; // your network SSID (name) char password[] = “www.anakkendali.com"; // your network key // Initialize Telegram BOT #define BOTtoken “518247654:AAGnJ3bwQoixeX4nDDLb-JdmA1vPsD85gRo” // your Bot Token (Get from Botfather) WiFiClientSecure client; UniversalTelegramBot bot(BOTtoken, client); int Bot_mtbs = 1000; //mean time between scan messages long Bot_lasttime; //last time messages’ scan has been done bool Start = false; const int ledPin = 15; int ledStatus = 0; void handleNewMessages(int numNewMessages) { Serial.println(“handleNewMessages”); Serial.println(String(numNewMessages)); for (int i=0; i<numNewMessages; i++) { String chat_id = String(bot.messages[i].chat_id); String text = bot.messages[i].text; String from_name = bot.messages[i].from_name; if (from_name == “”) from_name = “Guest”; if (text == “/ledon”) { digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) ledStatus = 1; bot.sendMessage(chat_id, “Led is ON”, “”); } if (text == “/ledoff”) { ledStatus = 0; digitalWrite(ledPin, LOW); // turn the LED off (LOW is the voltage level) 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 library, “ + from_name + “.n”; welcome += “This is Flash Led Bot example.nn”; welcome += “/ledon : to switch the Led ONn”; welcome += “/ledoff : to switch the Led OFFn”; welcome += “/status : Returns current status of LEDn”; bot.sendMessage(chat_id, welcome, “Markdown”); } } } void setup() { Serial.begin(115200); // Attempt to connect to Wifi network: Serial.print(“Connecting Wifi: “); Serial.println(ssid); // Set WiFi to station mode and disconnect from an AP if it was Previously // connected WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print(“.”); delay(500); } Serial.println(“”); Serial.println(“WiFi connected”); Serial.print(“IP address: “); Serial.println(WiFi.localIP()); pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output. delay(10); digitalWrite(ledPin, LOW); // initialize pin as off } 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(); } }

ESP32, Cara Mengakses TelegramBot Kontrol Relay / Led

Selanjutnya Baca Juga : ESP32, Cara Mengakses Sensor DHT11 program diatas sudah ada pada contoh library yang sudah di download di atas. mungkin cukup sekian apa yang bisa saya bagikan kali ini, semoga bermanfaat. jika ada yang ingin ditanyakan silahkan chat melalui WA atau Messenger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store