I was playing around a bit with XMPP (Extensible Messaging and Presence Protocol) and thought of the idea to make my servers and Raspberry Pi’s be able to talk to me without having to logging in via SSH.
Of course, this requires Raspbian or other Linux dist where you can login via SSH and install Node.js. A guide can be found here: Install nodejs and npm on Raspberry Pi.
This is very easy to do if you have node.js installed. Some smart people out there are building npm packages so you easily can install and use them without any hassle.
First of all, you want to have a XMPP server. You can install one of your own or you can connect to a existing one. After some research I chose Prosody since it looked like the fastest and most recent written one. Installation and configuration is simple so I won’t go in to that. Add a user (which will be the master of the bot net when you’re done) and try to connect with your XMPP client of choice. If you’re on OS X I recommend Adium which is fast and lightweight.
Now to the fun part!
On your Raspberry Pi’s or other Linux server, install node.js.
When installed, make a new directory (called xmpp-bot for example) and install some dependencies and simple-xmpp.
mkdir xmpp-bot && cd $_ npm install optimist sudo npm install forever -g npm install simple-xmpp mkdir conf
On a Raspberry Pi, this will take some time.
After that, make two files, app.js and helper.js and put this info in them:
[gist id=5388415 file=app.js][/gist]
[gist id=5388415 file=helper.js][/gist]
In the dir called “conf”, create a file named uptime.js and put this in inside:
[gist id=5388415 file=uptime.js][/gist]
Now, temporarily start the bot:
node app.js -u firstname.lastname@example.org -p password1 -h 'xmpp.domain.com' --port 5222 --master email@example.com
If you get an error saying ‘Cannot find module helper’, type this in bash so your NODE_PATH gets correct.
Look in your XMPP client to see if you can see the bot. If you can’t, search for it and add it to friends list. Test it by typing ‘uptime’.
Do you get a reply?
Alright, stop the bot by pressing Ctrl+c.
Start it as a daemon and let it run, forever
#to stop something started by forever, type 'forever list' and the 'forever stop X' where X is the id you got from the list. forever start app.js -u firstname.lastname@example.org -p password1 -h 'xmpp.domain.com' --port 5222 --master email@example.com
Now, add as many commands in the conf-dir as you like. Or, set up a server hosting your modules/commands and import them to your bots by typing “add uptime” and removing by “remove uptime”.
Now you have your remote controlled servers/pi’s acting like bots that obey’s their master. ;)
With your own modules you can make the server do anything.