-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from witnessmenow/master
Added PASS Support so we can use it with Twitch chat
- Loading branch information
Showing
8 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vscode/arduino.json | ||
.vscode/c_cpp_properties.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
125 changes: 125 additions & 0 deletions
125
examples/ESP8266/TwtichSendReceive/TwtichSendReceive.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/******************************************************************* | ||
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 <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 IRC_SERVER "irc.chat.twitch.tv" | ||
#define IRC_PORT 6667 | ||
|
||
//------- Replace the following! ------ | ||
char ssid[] = "ssid"; // your network SSID (name) | ||
char password[] = "password"; // your network key | ||
|
||
//The name of the channel that you want the bot to join | ||
const String twitchChannelName = "EXAMPLE_CHANNEL_NAME"; | ||
|
||
//The name that you want the bot to have | ||
#define TWITCH_BOT_NAME "exampleName" | ||
|
||
//OAuth Key for your twitch bot | ||
// https://twitchapps.com/tmi/ | ||
#define TWITCH_OAUTH_TOKEN "oauth:124678uhgfhfghgfjgfjfgjgfhhgfh" | ||
|
||
|
||
//------------------------------ | ||
|
||
|
||
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() { | ||
|
||
pinMode(led, OUTPUT); | ||
|
||
Serial.begin(115200); | ||
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); | ||
|
||
for (int i = 0; i < 6; i++) { | ||
digitalWrite(led, HIGH); | ||
delay(50); | ||
digitalWrite(led, LOW); | ||
delay(25); | ||
} | ||
|
||
|
||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
name=ArduinoIRC | ||
version=0.1.0 | ||
version=0.2.0 | ||
author=Fredi Machado | ||
maintainer=Fredi Machado <[email protected]> | ||
sentence=Easy library to make an Arduino IRC Bot. | ||
sentence=Easy library to make an Arduino IRC Bot (Also supports Twitch chat). | ||
paragraph=This library allows your project to connect to an IRC server. | ||
category=Communication | ||
url=https://github.com/fredimachado/ArduinoIRC | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters