Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <UniversalTelegramBot.h>
- const char* ssid = "YourWiFiSSID";
- const char* password = "YourWiFiPassword";
- const char* botToken = "YourBotToken";
- #define CHAT_ID "YourChatID"
- WiFiClientSecure client;
- UniversalTelegramBot bot(botToken, client);
- void handleMessage(String text) {
- // Parse the message to extract RGB values
- int r = 0, g = 0, b = 0;
- // Extract the RGB values from the message
- sscanf(text.c_str(), "%d %d %d", &r, &g, &b);
- // Print the extracted values for debugging
- Serial.print("Red: ");
- Serial.println(r);
- Serial.print("Green: ");
- Serial.println(g);
- Serial.print("Blue: ");
- Serial.println(b);
- // You can further process the extracted values here
- }
- 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("Starting bot...");
- bot.startBot();
- Serial.println("Bot started");
- }
- void loop() {
- // Check for new messages
- if (bot.getUpdates(bot.last_message_received + 1)) {
- for (int i = 0; i < bot.updateCount(); i++) {
- String chat_id = bot.messages[i].chat_id;
- String text = bot.messages[i].text;
- // Check if the message is from the desired chat
- if (chat_id.equals(CHAT_ID)) {
- handleMessage(text);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement