ESP8266 twitch chat bot trouble

Hi! i'm using a template I found on github to try and see if i can control a relay with twitch chat. After putting in all required fields including the required information the esp8266 was able to connect to the chat and type out a response! however thats about all it can do, the servo wouldnt function no matter what. I checked if my hardware was the issue but quickly loading up an on off code for the relay showed it works fine. heres the template im using:

 /*******************************************************************
    Connect to Twtich Chat with a Bot
   Created with code from TheOtherLoneStar (https://www.twitch.tv/theotherlonestar)
   Hackaday IO: https://hackaday.io/otherlonestar
   By Brian Lough (https://www.twitch.tv/brianlough)
   YouTube: https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
Created with code from noycebru www.twitch.tv/noycebru
 *******************************************************************/
 
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <IRCClient.h>

//define your default values here, if there are different values in config.json, they are overwritten.
#define secret_ssid "my ssid" 
#define IRC_SERVER   "irc.chat.twitch.tv"
#define IRC_PORT     6667
 
//------- Replace the following! ------
char ssid[] = "";       // your network SSID (name)
char password[] = "";  // your network key
 
//The name of the channel that you want the bot to join
const String twitchChannelName = "Streamname"; //this is case sensitive!
 
//The name that you want the bot to have
#define TWITCH_BOT_NAME "Bot_Name"
 
//OAuth Key for your twitch bot
// https://twitchapps.com/tmi/
#define TWITCH_OAUTH_TOKEN "oauth:"
 
 
//------------------------------
 
 
int relay = 5; //led lights this turns the digital relay on and off. this is the pin the digital relay is connected to
String ircChannel = "";
 
WiFiClient WiFiClient;
IRCClient client(IRC_SERVER, IRC_PORT, WiFiClient);
 
// put your setup code here, to run once:
void setup() {
  
  pinMode(relay, OUTPUT);
  delay(2000);
  Serial.begin(9600);
  Serial.println();
 
  // Set WiFi to station mode and disconnect from an AP if it was Previously
  // connected
  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) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
 
  ircChannel = "#" + twitchChannelName;
 
  client.setCallback(callback);
}
 
void loop() {
 
  // Try to connect to chat. If it loses connection try again
  if (!client.connected()) {
    Serial.println("Attempting to connect to " + ircChannel );
    // Attempt to connect
    // Second param is not needed by Twtich
    if (client.connect(TWITCH_BOT_NAME, "", TWITCH_OAUTH_TOKEN)) {
      client.sendRaw("JOIN " + ircChannel);
      Serial.println("connected and ready to rock");
      sendTwitchMessage("Ready to go Boss!");
    } else {
      Serial.println("failed... try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
    return;
  }
  client.loop();
}
 
void sendTwitchMessage(String message) {
  client.sendMessage(ircChannel, message);
}
 
 
void callback(IRCMessage ircMessage) {
  //Serial.println("In CallBack");
 
  if (ircMessage.command == "PRIVMSG" && ircMessage.text[0] != '\001') {
    //Serial.println("Passed private message.");
   
    ircMessage.nick.toUpperCase();
 
    String message("<" + ircMessage.nick + "> " + ircMessage.text);
 
    //prints chat to serial
    Serial.println(message);

//this is where you would replace these elements to match your streaming configureation. 
if (ircMessage.text.indexOf("subscribed") > -1 && ircMessage.nick == "STREAMELEMENTS")
      {
     
      digitalWrite(relay, HIGH);
      delay(10000);
      digitalWrite(relay, LOW);
      delay(25);
   
    }

    if (ircMessage.text.indexOf("streaming") > -1 && ircMessage.nick == "STREAMELEMENTS")
      {
     
      digitalWrite(relay, HIGH);
      delay(10000);
      digitalWrite(relay, LOW);
      delay(25);
   
    }

    if (ircMessage.text.indexOf("test") > -1 && ircMessage.nick == "STREAMNAME")
      {
      digitalWrite(relay, HIGH);
      delay(10000);
      digitalWrite(relay, LOW);
      delay(25);
      }
 
    return;
  }
}

once the ESP loads it sends the message (Under the streamers name and not its own) to the chat and thats it really, I cant get it to read the chat at all.
So yeah im kind of stumped. I'm not very good with this stuff so if you need pictures or additional information let me know.

Sure, give us everything you have.

Not sure what you mean lol

The last sentence you wrote...

ooohhh sorry im a little flustered with this project rn i cant even remember what I wrote lol , well the board is a node esp8266 cp2102 and the relay is a one channel (I think thats the right word?) I tried changing the ircMessage.text.indexOf to a bunch of different stuff and the ircMessage.nick as well but still no response. if im reading it right it says the chat should be printing in the serial monitor but nothing shows but I might be reading it wrong.

Please post your complete sketch, and a complete wiring diagram.

You got it! without posting my personal info the sketch above is the complete sketch. Im new to fritzing but here is the best wiring schematic I could make! Also I really appreciate you responding back

Well, the sketch uses pin 5 for the relay, and your board uses pin D1.

Yeah I was a little confused on that too. but the pinout for this board is layed out like this

oh also I should note that for my wiring layout the board i used wasnt the exact model but i found the actual model here.

Okay, just for completeness can I see the relay test sketch?

For sure!

int relay = 5;
void setup() {
  // put your setup code here, to run once:
pinMode(relay,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(relay,HIGH);
  delay(1000);
  digitalWrite(relay,LOW);
  delay(1000);
}

really simple I just used it to make sure it wasnt a hardware issue. just tried it right now just to make sure and it works fine.

Okay, I see you have debug prints, especially this:

    //prints chat to serial
    Serial.println(message);

//this is where you would replace these elements to match your streaming configureation. 
if (ircMessage.text.indexOf("subscribed") > -1 && ircMessage.nick == "STREAMELEMENTS")

What was printed?

See thats the part thats throwing me off is that nothing is printing past the connecting to chat debug.
heres the serial monitor when its all loaded, I removed my name , wifi name and ip address but they are all correct.

and here it is connecting and showing that its there (Still going under my username) and connected but when test is said it does nothing

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.