Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #include <WiFiUdp.h>
- #include "DHT.h"
- #define D0 16 // led onboard (reset)
- #define D1 5 //ds18b20
- #define D2 4 //dht22
- #define D3 0
- #define D4 2 // led onboard
- #define D5 14 // converte pin scheda nodeMCU in pin arduino.
- #define D6 12
- #define D7 13
- #define D8 15
- #define D9 3
- #define D10 1
- DHT dht(D2,DHT22); //pin D2, dht22
- // Initialize Wifi connection to the router
- char ssid[] = "FASTWEB-1-2B1FBD"; // your network SSID (name)
- char password[] = "30FB079296"; // your network key
- // Initialize Telegram BOT
- #define BOTtoken "316246763:AAEP7zvQTSwTHUBTo_PKFvNYteedfOPGdbc" // 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
- void setup() {
- static WiFiEventHandler e1, e2;
- Serial.begin(9600);
- dht.begin(); // dht22
- // sensors.begin(); // ds18b20
- pinMode(D4, OUTPUT);
- 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) {
- digitalWrite(D4, HIGH);
- Serial.print(".");
- delay(250);
- digitalWrite(D4, LOW);
- delay(250);
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- IPAddress ip = WiFi.localIP();
- Serial.println(ip);
- }
- void loop() {
- if (millis() > Bot_lasttime + Bot_mtbs) {
- int numNewMessages = bot.getUpdates(bot.last_message_recived + 1);
- while(numNewMessages) {
- Serial.println("got response");
- for(int i=0; i<numNewMessages; i++) {
- // bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, ""); //ripeti messaggio
- String text = bot.messages[i].text;
- Serial.println(bot.messages[i].chat_id);
- Serial.println(text);
- if(text == "/Start" || text == "/start") // se si invia "/astart" tramite telegram
- {
- delay(100);
- bot.sendMessage(bot.messages[i].chat_id + " NodeMCU connessa e attiva" , "");
- Serial.print("NodeMCU connessa e attiva");
- }
- //****
- }
- numNewMessages = bot.getUpdates(bot.last_message_received + 1);
- }
- Bot_lasttime = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement