Thursday, January 11, 2018

Access Your Raspberry Pi Remotely via XMPP Chat

How to remote-access a Raspberry Pi over the internet using an XMPP-based chat-bot — no port forwarding or dynamic DNS required. The chat-bot is written in C++ using the gloox XMPP client library, and communicates through a public Jabber server.

Setup diagram — Raspberry Pi chat-bot communicating with smartphone via XMPP

Typical setup — Raspberry Pi behind a firewall communicates with a smartphone via a public XMPP/Jabber server.

Building the chat-bot on Raspberry Pi

Tested on Raspbian Stretch Lite (2017-11-29). These steps work on any Debian-based Linux distro.

Step 1 — Log in to the Raspberry Pi shell (keyboard or SSH) and install dependencies:

sudo apt-get update
sudo apt-get install cmake git libjson-c-dev libgloox-dev openssl

Step 2 — Clone and build:

mkdir /home/pi/xmproxy
cd /home/pi/xmproxy
git clone https://github.com/hackboxguy/brbox
cd /home/pi/xmproxy/brbox/sources
cmake -H. -BOutput -DCMAKE_INSTALL_PREFIX=/home/pi/xmproxy/buildir -DAUTO_SVN_VERSION=OFF
cmake --build Output -- install    # add -j5 on quad-core Pi for faster build

Step 3 — Configure XMPP credentials and start the chat-bot:

cd /home/pi/xmproxy/buildir
echo "user: my-raspi-username@gmail.com" > xmpp-login.txt
echo "pw: super-secret-pw" >> xmpp-login.txt
export LD_LIBRARY_PATH=/home/pi/xmproxy/buildir/lib
/home/pi/xmproxy/buildir/bin/xmproxysrv --loginfile=/home/pi/xmproxy/buildir/xmpp-login.txt

Testing

Check on your Android phone's Hangouts (or any XMPP client) if my-raspi-username is online. Send help and the chat-bot will reply with the list of available commands.

Notes

For Google accounts, ensure Allow less secure apps is enabled on the Raspberry Pi's account.

The two XMPP accounts don't need to be on Google — any two Jabber accounts will work. See this guide for preparing Jabber accounts.

These steps work on any Debian-based Linux distro, not just Raspbian.

SOURCE CODE

github.com/hackboxguy/brbox — XMPP chat-bot sources and build instructions

2 comments:

Sanchit Mehra said...

Informative Article

Unknown said...

hello once installed there are programming examples I would like to create a question and answer bot with sending photos and videos ..