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.