-
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.
Example: Reply a message from an especific nick only
- Loading branch information
1 parent
0b5fd28
commit e7312e0
Showing
1 changed file
with
76 additions
and
0 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,76 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <IRCClient.h> | ||
|
||
#define ssid "" | ||
#define password "" | ||
|
||
#define IRC_SERVER "irc.rizon.net" | ||
#define IRC_PORT 6667 | ||
#define IRC_NICKNAME "MCUIRCClient" | ||
#define IRC_USER "MCUIRCClient" | ||
|
||
#define REPLY_TO "NICK" // Reply only to this nick | ||
|
||
WiFiClient wiFiClient; | ||
IRCClient client(IRC_SERVER, IRC_PORT, wiFiClient); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
delay(100); | ||
|
||
Serial.println(""); | ||
Serial.print("Connecting to "); | ||
Serial.println(ssid); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
WiFi.printDiag(Serial); | ||
|
||
client.setCallback(callback); | ||
client.setSentCallback(debugSentCallback); | ||
} | ||
|
||
void loop() { | ||
if (!client.connected()) { | ||
Serial.println("Attempting IRC connection..."); | ||
// Attempt to connect | ||
if (client.connect(IRC_NICKNAME, IRC_USER)) { | ||
Serial.println("connected"); | ||
} else { | ||
Serial.println("failed... try again in 5 seconds"); | ||
// Wait 5 seconds before retrying | ||
delay(5000); | ||
} | ||
return; | ||
} | ||
|
||
client.loop(); | ||
} | ||
|
||
void callback(IRCMessage ircMessage) { | ||
// PRIVMSG ignoring CTCP messages | ||
if (ircMessage.command == "PRIVMSG" && ircMessage.text[0] != '\001') { | ||
String message("<" + ircMessage.nick + "> " + ircMessage.text); | ||
Serial.println(message); | ||
|
||
if (ircMessage.nick == REPLY_TO) { | ||
client.sendMessage(ircMessage.nick, "Hi " + ircMessage.nick + "! I'm your IRC bot."); | ||
} | ||
|
||
return; | ||
} | ||
Serial.println(ircMessage.original); | ||
} | ||
|
||
void debugSentCallback(String data) { | ||
Serial.println(data); | ||
} |