Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. #include <TelegramBot.h>
  2. #include <WiFiSSLClient.h>
  3. #include <WiFi101.h>
  4. #include <SPI.h>
  5.  
  6. String id = "xxxxxxxx";
  7. char ssid[] = "Vodafone-34374xxx";
  8. char pass[] = "uevyxxxxxxxxxxx";
  9.  
  10. const char BotToken[] = "409478169:xxxxxxxE7SfmUjp2F2_Cr4-SvFxuo";
  11. const char BotName[] = "Apriti Sesamo";
  12. const char BotUsername[] = "@xxxx_bot";
  13. WiFiSSLClient client;
  14. TelegramBot bot(BotToken, client);
  15.   int portone=3;
  16.   int porta=4;
  17. void setup() {
  18.   // put your setup code here, to run once:
  19.   pinMode(7, OUTPUT);
  20.   pinMode(portone, OUTPUT);
  21.   pinMode(porta, OUTPUT);
  22.   digitalWrite(portone, HIGH);
  23.   digitalWrite(porta, HIGH);
  24.   Serial.begin(115200);
  25.   Serial.print("Connecting");
  26.   while(WiFi.begin(ssid, pass) == WL_CONNECTED){
  27.     Serial.print(".");
  28.     delay(250);
  29.   }
  30.   Serial.print("\n\nConnesso");
  31.   bot.begin();
  32. }
  33.  
  34. void loop() {
  35.   // put your main code here, to run repeatedly:
  36.   start:
  37.   message m = bot.getUpdates();
  38.  
  39.   if(m.text.equals("/start")){
  40.   bot.sendMessage(m.chat_id, "Ciao, per aprire le porte digitare \"/apri\"");
  41.   m.text="";
  42.   goto start;
  43.   }
  44.   if(m.text.equals("/apri")){
  45.       if(m.chat_id==id||m.chat_id=="19xxxxxx"){
  46.         digitalWrite(portone, LOW);
  47.         delay(50);
  48.         digitalWrite(portone, HIGH);
  49.         bot.sendMessage(m.chat_id, "Portone aperto");
  50.         digitalWrite(porta, LOW);
  51.         delay(50);
  52.         digitalWrite(porta, HIGH);
  53.         bot.sendMessage(m.chat_id, "Porta aperta");
  54.         m.text="";
  55.         goto start;
  56.     }
  57.     else{
  58.       bot.sendMessage(m.chat_id, "Non sei autorizzato ad aprire le porte");
  59.       m.text="";
  60.       goto start;
  61.      
  62.     }
  63.   }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement