Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClientSecure.h>
  3. #include <UniversalTelegramBot.h>
  4. #include <WiFiUdp.h>
  5. #include "DHT.h"
  6.  
  7. #define D0 16 // led onboard (reset)
  8. #define D1 5 //ds18b20
  9. #define D2 4 //dht22
  10. #define D3 0
  11. #define D4 2 // led onboard
  12. #define D5 14 // converte pin scheda nodeMCU in pin arduino.
  13. #define D6 12
  14. #define D7 13
  15. #define D8 15
  16. #define D9 3
  17. #define D10 1
  18.  
  19.  
  20. DHT dht(D2,DHT22); //pin D2, dht22
  21.  
  22. // Initialize Wifi connection to the router
  23. char ssid[] = "FASTWEB-1-2B1FBD"; // your network SSID (name)
  24. char password[] = "30FB079296"; // your network key
  25.  
  26. // Initialize Telegram BOT
  27. #define BOTtoken "316246763:AAEP7zvQTSwTHUBTo_PKFvNYteedfOPGdbc" // your Bot Token (Get from Botfather)
  28.  
  29. WiFiClientSecure client;
  30. UniversalTelegramBot bot(BOTtoken, client);
  31.  
  32. int Bot_mtbs = 1000; //mean time between scan messages
  33. long Bot_lasttime; //last time messages' scan has been done
  34.  
  35. void setup() {
  36. static WiFiEventHandler e1, e2;
  37. Serial.begin(9600);
  38. dht.begin(); // dht22
  39. // sensors.begin(); // ds18b20
  40. pinMode(D4, OUTPUT);
  41. WiFi.mode(WIFI_STA);
  42. WiFi.disconnect();
  43. delay(100);
  44.  
  45. // Attempt to connect to Wifi network:
  46. Serial.print("Connecting Wifi: ");
  47. Serial.println(ssid);
  48. WiFi.begin(ssid, password);
  49. while (WiFi.status() != WL_CONNECTED) {
  50. digitalWrite(D4, HIGH);
  51. Serial.print(".");
  52. delay(250);
  53. digitalWrite(D4, LOW);
  54. delay(250);
  55. }
  56. Serial.println("");
  57. Serial.println("WiFi connected");
  58. Serial.println("IP address: ");
  59. IPAddress ip = WiFi.localIP();
  60. Serial.println(ip);
  61. }
  62.  
  63.  
  64. void loop() {
  65. if (millis() > Bot_lasttime + Bot_mtbs) {
  66. int numNewMessages = bot.getUpdates(bot.last_message_recived + 1);
  67. while(numNewMessages) {
  68. Serial.println("got response");
  69. for(int i=0; i<numNewMessages; i++) {
  70. // bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, ""); //ripeti messaggio
  71. String text = bot.messages[i].text;
  72. Serial.println(bot.messages[i].chat_id);
  73. Serial.println(text);
  74.  
  75. if(text == "/Start" || text == "/start") // se si invia "/astart" tramite telegram
  76. {
  77. delay(100);
  78. bot.sendMessage(bot.messages[i].chat_id + " NodeMCU connessa e attiva" , "");
  79. Serial.print("NodeMCU connessa e attiva");
  80. }
  81. //****
  82. }
  83. numNewMessages = bot.getUpdates(bot.last_message_received + 1);
  84. }
  85.  
  86. Bot_lasttime = millis();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement