Advertisement
safwan092

Untitled

Feb 11th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <WiFi.h>
  2. #include <UniversalTelegramBot.h>
  3.  
  4. const char* ssid = "YourWiFiSSID";
  5. const char* password = "YourWiFiPassword";
  6. const char* botToken = "YourBotToken";
  7. #define CHAT_ID "YourChatID"
  8.  
  9. WiFiClientSecure client;
  10. UniversalTelegramBot bot(botToken, client);
  11.  
  12. void handleMessage(String text) {
  13. // Parse the message to extract RGB values
  14. int r = 0, g = 0, b = 0;
  15.  
  16. // Extract the RGB values from the message
  17. sscanf(text.c_str(), "%d %d %d", &r, &g, &b);
  18.  
  19. // Print the extracted values for debugging
  20. Serial.print("Red: ");
  21. Serial.println(r);
  22. Serial.print("Green: ");
  23. Serial.println(g);
  24. Serial.print("Blue: ");
  25. Serial.println(b);
  26.  
  27. // You can further process the extracted values here
  28. }
  29.  
  30. void setup() {
  31. Serial.begin(115200);
  32.  
  33. WiFi.begin(ssid, password);
  34. while (WiFi.status() != WL_CONNECTED) {
  35. delay(1000);
  36. Serial.println("Connecting to WiFi...");
  37. }
  38. Serial.println("Connected to WiFi");
  39.  
  40. Serial.println("Starting bot...");
  41. bot.startBot();
  42.  
  43. Serial.println("Bot started");
  44. }
  45.  
  46. void loop() {
  47. // Check for new messages
  48. if (bot.getUpdates(bot.last_message_received + 1)) {
  49. for (int i = 0; i < bot.updateCount(); i++) {
  50. String chat_id = bot.messages[i].chat_id;
  51. String text = bot.messages[i].text;
  52.  
  53. // Check if the message is from the desired chat
  54. if (chat_id.equals(CHAT_ID)) {
  55. handleMessage(text);
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement