Removing all the twitch code so it is just simple code to connect to the internet with wifi works without issue.
I have serial confirm the IP address every 5 minutes and can confirm it is connected to my router.
Could be related to the wifi.h and IRCClient.h being used together?
Board
I'm using a Wemos Lolin32 Lite , DOIT ESP32 Dev Kit V1 generic ESP32 etc.
Arduino 1.8.12
Sketch
/*******************************************************************
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
*******************************************************************/
#include <WiFi.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 IRC_SERVER "irc.chat.twitch.tv"
#define IRC_PORT 6667
//------- Replace the following! ------
char ssid[] = "ssid"; // your network SSID (name)
char password[] = "pass"; // your network key
//The name of the channel that you want the bot to join
const String twitchChannelName = "mytwitchchannel";
//The name that you want the bot to have
#define TWITCH_BOT_NAME "mytwitchbot"
//OAuth Key for your twitch bot
// https://twitchapps.com/tmi/
#define TWITCH_OAUTH_TOKEN "oauth:xxxxxxxxxxxxxxxxxxxxxx
//------------------------------
int led = LED_BUILTIN;
String ircChannel = "";
WiFiClient wiFiClient;
IRCClient client(IRC_SERVER, IRC_PORT, wiFiClient);
// put your setup code here, to run once:
void setup() {
Serial.begin(115200);
pinMode(led, OUTPUT);
Serial.println();
// 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("Oh no, that boi connected");
delay(5000);
} 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);
for (int i = 0; i < 6; i++) {
digitalWrite(led, HIGH);
delay(50);
digitalWrite(led, LOW);
delay(25);
}
return;
}
}
This code and the things you provide have been so helpful in learning about Arduino and have helped me make a bunch of things I would never have dreamed of without the ideas and functionality of code like this !!! you ROCK!
I know this is setup for an ESP8266, however I can't seem to find anywhere else to help with the error message I am getting:
Description
Basically, this all works without issue on an ESP8266, but using the 32 I am able to connect to the twitch chat then my wifi disconnects and I get:
[I][WiFiClient.cpp:548] connected(): Unexpected: RES: 0, ERR: 119
Troubleshooting
Removing all the twitch code so it is just simple code to connect to the internet with wifi works without issue. I have serial confirm the IP address every 5 minutes and can confirm it is connected to my router. Could be related to the wifi.h and IRCClient.h being used together?
Board
I'm using a Wemos Lolin32 Lite , DOIT ESP32 Dev Kit V1 generic ESP32 etc. Arduino 1.8.12
Sketch
Debug message:
Lastly
This code and the things you provide have been so helpful in learning about Arduino and have helped me make a bunch of things I would never have dreamed of without the ideas and functionality of code like this !!! you ROCK!