Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #include <SoftwareSerial.h>
- #include <ArduinoJson.h>
- SoftwareSerial NodeSerial(5, 4); //RX/TX
- // Initialize Wifi connection to the router
- char ssid[] = "EOLO - FRITZ!Box 4020 WG"; // your network SSID (name)
- char password[] = "vvvvvv"; // your network key
- // Initialize Telegram BOT
- #define BOTtoken "gggggggg" // 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
- String c;
- void setup() {
- pinMode(5, INPUT);
- pinMode(4, OUTPUT);
- Serial.begin(19200);
- NodeSerial.begin(19200);
- // Set WiFi to station mode and disconnect from an AP if it was Previously
- // connected
- WiFi.mode(WIFI_STA);
- WiFi.disconnect();
- delay(100);
- // Attempt to connect to Wifi network:
- Serial.print("Connecting Wifi: ");
- Serial.println(ssid);
- 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());
- }
- void loop() {
- if (millis() > Bot_lasttime + Bot_mtbs) {
- int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
- Serial.println(numNewMessages);
- while(numNewMessages) {
- Serial.println("got response");
- for (int i=0; i<numNewMessages; i++) {
- String text = bot.messages[i].text;
- Serial.println(bot.messages[i].chat_id);
- Serial.println(text);
- Serial.println("inviato a mega");
- NodeSerial.print(text);
- }
- numNewMessages = bot.getUpdates(bot.last_message_received + 1);
- }
- Bot_lasttime = millis();
- }
- if (NodeSerial.available()>0){
- while(NodeSerial.available()) {
- c=NodeSerial.readString();
- Serial.println("ricevuto da mega");
- Serial.println(c);
- bot.sendMessage("222222" ,c , ""); //
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement