Developing an IRC bot with Arduino
In this post, I'm going to describe the IRC raw protocol. Next post will be about how to program an Arduino with an Ethernet shield to handle IRC.
A exploration of the IRC protocol
Let's go on IRC with telnet only! The first thing you want to do, is opening telnet (logically). Windoze 7 and Vista users will have to enable telnet by going to Control Panel ->> Programs and features ->> Turn windows features on/off ->> Make sure Telnet is checked ->> Click ok. If you can't figure out how to enable or start Telnet, download PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
- For Windows users: open a command prompt by going to Start ->> Run ->> Type in "cmd" ->> Click Go. Windows 7/Vista users can just type in "cmd" in the search thingie after pressing the round Windows button down left. Then type in "telnet". You are now ready for the next step.
- For Mac OS users: have a look at http://www.wikihow.com/Use-Telnet-on-Mac-OS-X.
- For Linux users: you should be smart enough to find the prompt and type in "telnet".
Now we're going to connect to Freenode. In your telnet window, type
open irc.freenode.net 6667
That will open a connection to irc.freenode.net on port 6667. The first command the server wants to hear is NICK. NICK takes 1 parameter: the nickname you want to use. You don't type a '/' (slash) before any command, since we are using the raw protocol. It may be a disappointment, but there's no command prefixed by a slash in IRC. mIRC and other clients want you to use /login because they else won't know if you want to say, for example, login with another password to someone or you want to login with password with another password.
The next thing our IRC server wants to hear, is the USER command. This is a little more complex than the NICK command, as it takes more parameters. The syntax is
USER <username> <mode> <unused> : <realname>
Confusing? Let me explain.
Username: put in the name you used in the NICK command
Mode: just use 8, don't worry about it, 8 will automatically set the mode
Unused: ...is unused. It's here to ensure backwards compatibility with the older RFC standard.
Realname: your real name, prefixed by a semi-colon and a space
Example:
USER codingkid 8 * : Thomas T
An example of what we've learned so far:
Now, the trick is not to get online, but to stay online. After a while, you may notice something like this:
So, why did the server close our connection? Didn't he like us? No, look at the first line in the screenshot.
PING :anthony.freenode.net
The server polls by this way for inactive clients, so there are no inactive clients just hanging around, without doing anything and consuming bandwidth and server load. It sends out a PING message. We have to respond it with, you guessed it, PONG. If I would have responded this PING with a PONG, and all the following PING too, I would still be online.
PING :anthony.freenode.net PONG :anthony.freenode.net
Now, we know how we can connect to a server, how to set our nick, how to use the USER command and how to stay alive by playing ping-pong. What's next? Oh, right, sending messages!
Before sending a in a channel, we have to join the channel. We can do that by the JOIN command.
JOIN <channel>
Example:
JOIN #arduino
When in a channel, we can chat using PRIVMSG.
PRIVMSG <channel or nick> :<msg>
We also use PRIVMSG to PM a nick (i.e. start a private chat).
Summary of the IRC protocol
Of course, I only spoke about the most important commands. You can find a full list at http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands.
>> means 'we say the following to the server', << means 'server says this to us'.
- Connecting
We connect to the IRC server with the specified adress and port. - Setting a nick
>>NICK a-nick
- Setting user information
>>USER a-nick 8 * : My Name
- Ping-pong
<<PING :irc.qsdf.com >>PONG :irc.qsdf.com
- Joining a channel
>>JOIN #arduino
<<:doublet!~doublet@<IP> JOIN :#<ROOM>
<<:<something>.<server>.net 332 doublet #<room> : <topic>
<<:<something>.<server>.net 353 doublet = #<room> : <list of people in the room seperated with spaces>
<<:<something>.<server>.net 366 doublet #<room> :End of /NAMES list.
- Saying something to a channel or nick
>>PRIVMSG <nick or channel>
You probably have noticed the numbers after *.server.com. These are going to be important to know what's next. For example, if the server says:
:<something>.<server>.net 353 doublet = #<room> : doublet a_name someone
We know the server is spitting out a list of people in the room, because we just did a JOIN. But how is our Arduino going to know what the heck the server means? Is it saying the users on the server, or the users on a channel, or is it saying we may not use this certain nick? Well, if we take the number (called 'raw numeric' by mIRC), we can know what our IRC server wants to tell.
You can find a list of all these raw numerics on http://www.mirc.net/raws/.
We are now ready to do the programming. You'll have to wait for the next post for that
How to set up the Arduino ethernet shield
I had some trouble setting up the Arduino Ethernet shield, but now it's working and I'm willing to share how you have to do it. No need to port-forward, no shared internet, no whatever, just your Arduino, an RJ45 Ethernet cable, your computer, and your router.
- Attaching your Ethernet shield to your Arduino
Probably the simplest thing. Take your shield and mount it on top of your Arduino, and then press it. Maybe a pin doesn't go well in a hole, then you'll have to bend it a little bit.

An Arduino Duemilanove (2009), a RJ-45 cable, a USB A-B connector (B end is shown) and the DRrobot Ethernet shield for Arduino - Attaching the Arduino Ethernet shield to the internet
Take a RJ-45 cable. Put one end in the shield, and the other in your router. -

Some RJ-45 cables (photo by me - those cables were laying around here)

The other end of the cable plugged in in the router

The full setup (the camera was focussing at the speaker, sorry for the blur)
- Getting the details
Open the commandprompt. For windows: Start ->> Execute : cmd or cmd.exe. For linux users: use the shortcut in the menu. For mac: the to macs I got are an iMac (2000) and a mac classic (long before I was born). So, you'll have to google...
Now you have your prompt open, start by typing 'ipconfig' on windows, or ifconfig on linux. Note the (subnet-)mask, the IP, and the router IP (gateway).

The IP-config command on Windows
---I was not able to transfer the screenshots of my Linux, sorry--- - Start coding
Open up the Arduino IDE, plug in your Arduino with your fresh Ethernet shield mounted, then go to open ->> Examples ->> Ethernet ->> Webclient. Now, fill in the router IP, the subnet, and the IP + 5. Note you have to add 5 to make sure you don't interfere with other computers in your network. If the IP of a computer in your network would be 192.168.1.22, fill in 192.168.1.27 or so. To check if that IP is taken, go to the prompt and type 'ping IP', without the 's, and replace 'IP' with the IP.
Here you can see the slightly modified Webclient example - Upload, and try... And try again...
Upload the sketch by clicking the upload button, and fire up the serial monitor (USB has to be plugged in, of course). Now, if there's an error, hit the reset button. After 5 times no succes, there's something wrong with your code... Recheck the IP and routers IP. To make sure your routers IP is correct, fill it in your browser. When a little window pops up asking for a username and password, it's your routers IP (just click the cancel button). To verify the IP of the ethernet shield works, ping it while the board is running. If it works, you should see the 'TX' and 'RX' light of the ethernet shield flashing (note: the ones of the ethernet shield; not the ones of the Arduino board).

I told you...
Anyway, much succes and fun with your new Ethernet shield!
Getting IM notifications about changes in Waves
Have you also got Google Wave? Yes? Well, have you also got so many Waves? Difficult to overlook, isn't it? So, never thought about a tool that gives you an electric shock when there's a change in a Wave? Unfortunately, such a tool has never been invented. What was invented to give you a helping hand is Wave XMPP, a bot that IM's you when there's a change in a wave.
Let's get started!
-
Add wave-xmpp@appspot.com as a XMPP contact on G-Talk or Jabber or other XMPP network.
-
Add wave-xmpp@appspot.com as a participant on a Wave.
-
Now the bot will create a blip with 2 buttons. Of course you have to chose 'Subscribe'.
-
You'll get a confirmation IM message of the bot.
-
When there is a change to a wave, the bot will tell you it!
-
You're done! Actually, this is so simple that you could simply figured out it yourself, but I like to bore you guys :p
- Coding Kid
XMPP Libraries for PHP: reviews
In this post I will give you a list of PHP XMPP library's. I will handle the following library's:
- PHP Jabber class
- Phurple
- XMPPHP
- JAXL
- Lightr
PHP Jabber class
From Blitzaffe.com - Project page - Download (36KB) - Used in Centova - Last update: 15 Octobre 2007
The PHP Jabber class is an event-driven library used to connect - of course - Jabber and other XMPP servers. I like this class, but it isn't updated for a long time (last update was at Octobre 2007...). It was based at class.jabber.php. This class is a really fine class to work, even though it is so old.
Phurple
From SourceForge.org - Project page - Download (25.3KB) - Docs - Last update: 8 August 2008
Phurple (old name: PHPurple) is based on Libpurple - a library used in C and C++. In fact Phurple ís Libpurple, but with one extra file to parse/use the C(++) to PHP.
XMPPHP
From code.google.com - Project page - Download (22.3KB) - Last update: 26 July
XMPPHP is the successor of class.jabber. This is a pretty simple class, easy to use, but there are no docs...
JAXL
From code.google.com - Project page - Download (26.3KB) - Last release: 06 February, Last revision: 11 September
To me it seems the only class of all that is usable without headaches. It has some docs and some good "real-life-examples". In the code itself there is also a bit of documentation. I haven't got very far in my experiments with it yet, but the code looks really promising. It also brought to surface XMPP's overhead problem for me. We'll see how this evolves.
Lightr
Lightr is dead. We nowhere found a working download link, even not in the caches of google and other search engines.
About me
Now everything is up and running, I will tell you about myself.
My name is Thomas (but I prefer Doublet of Coding Kid on the internet), I'm only 14 nearly 15, and I live in Belgium. I'm interested in webdevelopment and other computer 'crap', electronics, horse-back riding, lucid dreaming.... People often think that I'm a noob when I tell my age, but the thruth is that I can code very well. My native language is Dutch, but I could already speak English before I learned it at school. Btw, at school, I do Economics.
I can mutiple computer languages (basics of JAVA, basics of C, Javascript (my favourite JS framework is mootools), VBS...), but I like PHP most of all. Currently I'm working on IMany, a library for PHP like you have libpurple for C++.
New layout
Yes, just 10 minutes after the blog was online, I already had a new WP theme called 'pixel'. I like it!
Hello world!
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
I just got this very clear message, so my new blog is up and running! Yeeha!
A while ago, I decided I wanted my own site. That's no problem, I know how to make one. But the real problem was that I had already tried several times, and I now knew from experience that I never was satisfied with the result.
So, now it's up and running, and, as I expected, I'm not happy with the layout. I'll search a cool WP theme.









