SHARE
TWEET

Untitled

a guest Apr 24th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClientSecure.h>
  3. #include <UniversalTelegramBot.h>
  4. #include <SoftwareSerial.h>
  5. #include <ArduinoJson.h>
  6.  
  7. SoftwareSerial NodeSerial(5, 4); //RX/TX
  8.  
  9.  
  10. // Initialize Wifi connection to the router
  11. char ssid[] = "EOLO - FRITZ!Box 4020 WG";     // your network SSID (name)
  12. char password[] = "vvvvvv"; // your network key
  13.  
  14. // Initialize Telegram BOT
  15. #define BOTtoken "gggggggg"  // your Bot Token (Get from Botfather)
  16.  
  17.  
  18.  
  19. WiFiClientSecure client;
  20. UniversalTelegramBot bot(BOTtoken, client);
  21.  
  22. int Bot_mtbs = 1000; //mean time between scan messages
  23. long Bot_lasttime;   //last time messages' scan has been done
  24.  
  25. String c;
  26.  
  27.  
  28. void setup() {
  29.   pinMode(5, INPUT);
  30.   pinMode(4, OUTPUT);
  31.   Serial.begin(19200);
  32.   NodeSerial.begin(19200);
  33.  
  34.   // Set WiFi to station mode and disconnect from an AP if it was Previously
  35.   // connected
  36.   WiFi.mode(WIFI_STA);
  37.   WiFi.disconnect();
  38.   delay(100);
  39.  
  40.   // Attempt to connect to Wifi network:
  41.   Serial.print("Connecting Wifi: ");
  42.   Serial.println(ssid);
  43.   WiFi.begin(ssid, password);
  44.  
  45.   while (WiFi.status() != WL_CONNECTED) {
  46.     Serial.print(".");
  47.     delay(500);
  48.   }
  49.  
  50.   Serial.println("");
  51.   Serial.println("WiFi connected");
  52.   Serial.print("IP address: ");
  53.   Serial.println(WiFi.localIP());
  54. }
  55.  
  56. void loop() {
  57.  
  58.   if (millis() > Bot_lasttime + Bot_mtbs)  {
  59.     int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
  60. Serial.println(numNewMessages);
  61.     while(numNewMessages) {
  62.       Serial.println("got response");
  63.       for (int i=0; i<numNewMessages; i++) {
  64.                 String text = bot.messages[i].text;
  65.         Serial.println(bot.messages[i].chat_id);
  66.         Serial.println(text);
  67.        
  68.      Serial.println("inviato a mega");  
  69.      NodeSerial.print(text);
  70.  
  71.       }
  72.       numNewMessages = bot.getUpdates(bot.last_message_received + 1);
  73.     }
  74.  
  75.     Bot_lasttime = millis();
  76.   }
  77.  
  78.           if (NodeSerial.available()>0){
  79.   while(NodeSerial.available()) {
  80.       c=NodeSerial.readString();
  81.        Serial.println("ricevuto da mega");
  82.         Serial.println(c);
  83.  
  84.  bot.sendMessage("222222" ,c , "");   //
  85.   }
  86.   }
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top