Advertisement
Guest User

Code pour astro_lab

a guest
Jul 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.40 KB | None | 0 0
  1.        
  2. #include <ESP8266WiFi.h>
  3. WiFiClient client;
  4. const char* ssid="NOM WIFI";
  5. const char* password = "MOT DE PASSE WIFI";
  6.  
  7. char* host = "irc.chat.twitch.tv";
  8. const int httpsPort = 6667;
  9. String Str="";
  10.  
  11. char auth[] = "TON mot de passe OAUTH délivré par twitch";
  12. bool analysed=false;
  13.  
  14. void setup() {
  15.  
  16.   pinMode(LED_BUILTIN,OUTPUT);
  17.   digitalWrite(LED_BUILTIN,LOW);
  18.  
  19.   Serial.begin(115200);
  20.   Serial.println();
  21.   Serial.print("Wifi connecting to ");
  22.   Serial.println( ssid );
  23.  
  24.   WiFi.begin(ssid,password);
  25.  
  26.   Serial.println();
  27.   Serial.print("Connecting");
  28.  
  29.   while( WiFi.status() != WL_CONNECTED ){
  30.       delay(500);
  31.       Serial.print(".");        
  32.   }
  33.  
  34.   digitalWrite( LED_BUILTIN , HIGH);
  35.   Serial.println();
  36.  
  37.   Serial.println("Wifi Connected Success!");
  38.   Serial.print("NodeMCU IP Address : ");
  39.   Serial.println(WiFi.localIP() );
  40.  
  41. if(client.connect(host, httpsPort))
  42. {
  43.  
  44. client.print("PASS ");
  45. client.print(auth);
  46. client.println("\r");
  47.  
  48. client.println("NICK ktr55bot\r");
  49.  
  50. client.println("JOIN #astro_lab\r");
  51.  
  52. client.println("PRIVMSG #astro_lab :KTRBOT Prise de service");
  53. }
  54.  
  55. }
  56.  
  57.  
  58.  
  59. void loop() {
  60.  
  61.  
  62. if (client.available()) {
  63.  
  64.    char c = client.read();
  65.    // Serial.print(c);
  66.  
  67.    
  68.    if(c=='\r')
  69.        {
  70.         Serial.println(Str);
  71.         Str="";
  72.         analysed=false;
  73.        }
  74.         else
  75.       {
  76.         Str=Str+c;        
  77.  
  78.            if(Str.indexOf("PING :tmi.twitch.tv") > 0)
  79.              {
  80.                client.println("PONG :tmi.twitch.tv");
  81.                Serial.println("pong envoyé");
  82.              }
  83.  
  84.            if(Str.indexOf(":!on") > 0)
  85.              {
  86.                digitalWrite(LED_BUILTIN,HIGH);
  87.              }
  88.              
  89.              if(Str.indexOf(":!off") > 0)
  90.              {
  91.                digitalWrite(LED_BUILTIN,LOW);
  92.              }
  93.  
  94.               if((Str.indexOf(":!ESP8266") > 0) && (analysed == false))
  95.              {
  96.  
  97.            
  98.               analysed = true;
  99.              
  100.                client.println("PRIVMSG #astro_lab : La meilleure invention de l'univers");
  101.  
  102.                }
  103.  
  104.                   if((Str.indexOf(":!astro") > 0) && (analysed == false))
  105.              {
  106.  
  107.            
  108.               analysed = true;
  109.              
  110.                client.println("PRIVMSG #astro_lab : Je sais pas quoi marquer!");
  111.                
  112.            
  113.               }
  114.      
  115.  
  116. }
  117. }
  118.   delay(1);
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement