Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. /*
  2. EchoBot on ESP8266
  3.  
  4. This example shows how to program a Telegram Bot
  5. that echoes your messages.
  6.  
  7. For a step-by-step tutorial visit:
  8. https://create.arduino.cc/projecthub/Arduino_Genuino/telegram-bot-library-ced4d4
  9.  
  10. Updated 13 February 2018
  11. by Tommaso Laterza
  12.  
  13. This example code is in the public domain.
  14.  
  15. */
  16.  
  17. #include "arduino_secrets.h"
  18. #include <ESP8266WiFi.h>
  19. #include <WiFiClientSecure.h>
  20. #include <TelegramBot.h>
  21.  
  22. // Initialize Wifi connection to the router
  23. const char* ssid = SECRET_SSID;
  24. const char* password = SECRET_PASS;
  25.  
  26.  
  27. // Initialize Telegram BOT
  28. const char BotToken[] = SECRET_BOT_TOKEN;
  29.  
  30. WiFiClientSecure net_ssl;
  31. TelegramBot bot (BotToken, net_ssl);
  32.  
  33. void setup() {
  34.  
  35. Serial.begin(115200);
  36. while (!Serial); // Wait for the Serial monitor to be opened
  37.  
  38. // attempt to connect to Wifi network:
  39. Serial.print("Connecting Wifi: ");
  40. WiFi.begin(ssid, password);
  41. while (WiFi.status() != WL_CONNECTED) {
  42. delay(500);
  43. Serial.print(".");
  44. }
  45. Serial.println("");
  46. Serial.println("WiFi connected");
  47.  
  48.  
  49. bot.begin();
  50.  
  51. }
  52.  
  53. void loop() {
  54. message m = bot.getUpdates(); // Read new messages
  55. if ( m.chat_id != 0 ){ // Checks if there are some updates
  56. Serial.println(m.text);
  57. bot.sendMessage(m.chat_id, m.text); // Reply to the same chat with the same text
  58. } else {
  59. Serial.println("no new message");
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement