Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- WiFiClient client;
- const char* ssid="NOM WIFI";
- const char* password = "MOT DE PASSE WIFI";
- char* host = "irc.chat.twitch.tv";
- const int httpsPort = 6667;
- String Str="";
- char auth[] = "TON mot de passe OAUTH délivré par twitch";
- bool analysed=false;
- void setup() {
- pinMode(LED_BUILTIN,OUTPUT);
- digitalWrite(LED_BUILTIN,LOW);
- Serial.begin(115200);
- Serial.println();
- Serial.print("Wifi connecting to ");
- Serial.println( ssid );
- WiFi.begin(ssid,password);
- Serial.println();
- Serial.print("Connecting");
- while( WiFi.status() != WL_CONNECTED ){
- delay(500);
- Serial.print(".");
- }
- digitalWrite( LED_BUILTIN , HIGH);
- Serial.println();
- Serial.println("Wifi Connected Success!");
- Serial.print("NodeMCU IP Address : ");
- Serial.println(WiFi.localIP() );
- if(client.connect(host, httpsPort))
- {
- client.print("PASS ");
- client.print(auth);
- client.println("\r");
- client.println("NICK ktr55bot\r");
- client.println("JOIN #astro_lab\r");
- client.println("PRIVMSG #astro_lab :KTRBOT Prise de service");
- }
- }
- void loop() {
- if (client.available()) {
- char c = client.read();
- // Serial.print(c);
- if(c=='\r')
- {
- Serial.println(Str);
- Str="";
- analysed=false;
- }
- else
- {
- Str=Str+c;
- if(Str.indexOf("PING :tmi.twitch.tv") > 0)
- {
- client.println("PONG :tmi.twitch.tv");
- Serial.println("pong envoyé");
- }
- if(Str.indexOf(":!on") > 0)
- {
- digitalWrite(LED_BUILTIN,HIGH);
- }
- if(Str.indexOf(":!off") > 0)
- {
- digitalWrite(LED_BUILTIN,LOW);
- }
- if((Str.indexOf(":!ESP8266") > 0) && (analysed == false))
- {
- analysed = true;
- client.println("PRIVMSG #astro_lab : La meilleure invention de l'univers");
- }
- if((Str.indexOf(":!astro") > 0) && (analysed == false))
- {
- analysed = true;
- client.println("PRIVMSG #astro_lab : Je sais pas quoi marquer!");
- }
- }
- }
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement