gryphraff
Posts: 30
Joined: Fri May 03, 2013 5:12 pm

Howto: Make Pi send you IM messages via XMPP

Thu May 23, 2013 7:04 pm

I’ve been looking for a way to get devices like the Pi to send out event notifications over IM for a while. Originally, I looked at using Yahoo! Messenger, since I still have a number of contacts that use it. Since I’m not really a programmer, writing something to talk to libpurple isn’t really something I can do right now. So I settled on XMPP, more specifically, Google Talk. Not more than a week afterwards, Google once again drops federated XMPP support in favor of their walled garden. Since I already had everything set up for XMPP, changing over to a plain ‘ol XMPP chat program was pretty easy.

Originally, I tried to follow the instructions at http://solvingmytechworld.blogspot.com/ ... ry-pi.html but it doesn’t work as git isn’t installed on the Pi. The author also assumes you want to talk to Google, but that’s no longer possible either. So, instead, do this:

Code: Select all

# This all needs to be run as root.
sudo apt-get update
# Always update before installing new stuff.
sudo apt-get install perl
sudo apt-get install libxml-parser-perl libauthen-sasl-perl

# Pi may tell you about some packages that are no longer needed and can be removed with sudo apt-get autoremove. I don’t think it hurts anything to remove them (I did) but do so at your peril.

sudo apt-get install libnet-xmpp-perl

# Original author has you building the package. Git isn’t there by default, and someone has already compiled a Pi package for you

sudo apt-get install sendxmpp

# We’re done installing packages
Now, you’re going to need a couple of non-Google XMPP accounts. One to talk, and one to listen. Assuming you don’t have these yet, head over to http://www.jabber.org/ and register a couple of accounts with them, or one of the various servers they list. Alternately, you can set up your own XMPP server. Once you have your accounts, we need to set up sendxmpp so it can actually talk to you:

Code: Select all

# replace my talkaccount and mypassword with your account names and passwords. 

sudo echo "[email protected] mypassword" >> ~/.sendxmpprc
sudo chmod 700 ~/.sendxmpprc
sudo cp -v ~/.sendxmpprc /etc/sendxmpprc
No errors? Good. Due to reasons I don’t understand, you may also need to copy .sendxmpprc to /home/pi/

Almost there! To make the thing talk to you:

Code: Select all

# replace mytalkaccount and mylistenaccount with your XMPP accounts. I have no idea if the ones here are registered!

sudo echo "Hi I am Rpi" | sendxmpp -t -u [email protected] [email protected]
(Options in the command line are –t for “Use TLS encryption,” and –u for “What username to send under,” in case you wanted to know.) If all went well, you should see a message in your IM client. Of course, make sure you are able to receive messages from unlisted buddies, otherwise you won’t see a thing! Also note that if you're using an XMPP server that has an entry point different than the domain of your username, you'll need to change some settings. The original post linked above can help with that.

That’s it. I think I got everything, but if I missed anything please comment!

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Howto: Make Pi send you IM messages via XMPP

Fri May 24, 2013 4:21 am

gryphraff wrote:

Code: Select all

# replace my talkaccount and mypassword with your account names and passwords. 

sudo echo "[email protected] mypassword" >> ~/.sendxmpprc
sudo chmod 700 ~/.sendxmpprc
sudo cp -v ~/.sendxmpprc /etc/sendxmpprc
No errors? Good. Due to reasons I don’t understand, you may also need to copy .sendxmpprc to /home/pi/
As soon as you "sudo", you've executed the command as root, which means ~ is going to expand to /root/, instead of /home/pi.

If you need the file as pi, you already have clear access to create files in your own home directory, just drop the sudo from the first two lines and you should take care of it automatically.

Security conscious: Typing passwords on command line is generally a bad idea. Editing this file in vim or similar and setting the correct content would be better.

Edit: In your "send" command, the only thing the sudo affects is the "echo" command, meaning the sendxmpp command is looking for files in your own home directory (not root's). There's no need for it here, go ahead and drop it.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Howto: Make Pi send you IM messages via XMPP

Fri May 24, 2013 6:51 am

As soon as you "sudo", you've executed the command as root, which means ~ is going to expand to /root/, instead of /home/pi.
~ is expanded by bash before sudo is executed, so you should be OK.
Also, without "-i" the original environment is preserved, so ${HOME} (aka ~) will be unchanged.
try this:

Code: Select all

echo ~
sudo echo ~
sudo -i echo ~
sudo bash -c "echo ~"
sudo -i bash -c "echo ~"

gryphraff
Posts: 30
Joined: Fri May 03, 2013 5:12 pm

Re: Howto: Make Pi send you IM messages via XMPP

Fri May 24, 2013 11:38 am

I figured there was some funny stuff going on there. The original author had sudo and sudo su flying all over the place, and I wasn't sure what was needed and what wasn't. I'll change my procedure when I get some of that mythical spare time I hear about. :lol:

As for the plaintext passwords, that's the hazard of using a tool like this. I have another utility, a sendmail-variety client installed from here http://rpi.tnet.com/project/faqs/smtp that does the same thing. I don't see any easy way to hash the passwords, so they are what they are. Pi has a strong password at the gate, and a firewall to keep it out of the way, so I consider it an acceptable risk.

Return to “Advanced users”