Thursday, January 11, 2018

Remote accessing the Raspberry pi over internet

In this guide, an xmpp based client-daemon is used as a chat-bot, this chat-bot is written in C++ and it is based on gloox-xmpp-client library. Xmpp provides an easy way of communication between two clients which are typically behind a firewall. A jabber server with public-ip over internet helps to achieve this secure communication between two xmpp clients.
Following steps explain how to compile and run the xmpp-client-daemon(chat-bot) on raspberry pi. Here is a diagram showing typical setup of remote communication between raspi and a smart phone.

How to prepare raspberry-pi to act as a chat-bot?
(following steps are tested on a raspi running 2017-11-29-raspbian-stretch-lite.img)
  1.  Login to the linux-shell-terminal of your raspi using directly connected keyboard or ssh.
  2.  sudo apt-get update
  3. sudo apt-get install cmake git libjson-c-dev libgloox-dev openssl
  4. mkdir /home/pi/xmproxy
  5. cd /home/pi/xmproxy
  6. git clone https://github.com/hackboxguy/brbox
  7. cd /home/pi/xmproxy/brbox/sources
  8. cmake -H. -BOutput -DCMAKE_INSTALL_PREFIX=/home/pi/xmproxy/buildir -DAUTO_SVN_VERSION=OFF
  9. cmake --build Output -- install (suffix -j5 incase of quad-core-raspi for faster build)
  10. cd /home/pi/xmproxy/buildir
  11. echo "user: my-raspi-usrname@gmail.com" >/home/pi/xmproxy/buildir/xmpp-login.txt;echo "pw: super-secret-pw" >>/home/pi/xmproxy/buildir/xmpp-login.txt
  12. export LD_LIBRARY_PATH=/home/pi/xmproxy/buildir/lib
  13. /home/pi/xmproxy/buildir/bin/xmproxysrv --loginfile=/home/pi/xmproxy/buildir/xmpp-login.txt

Check on your android phone's hangout if "my-raspi-usrname" is online, if so, then send "help" message and the reply would show the list of available commands.

enjoy chatting with your raspi-chat-bot!!

Note-1: For proper operation of xmpp with google account, ensure that your Raspi's account has this allow-less-secur-apps setting enabled. 

Note-2: Two xmpp accounts need not be on google, any two jabber accounts would work. Here is an explanation on preparing the jabber accounts.

Note-3: steps explained above would work on any debian based linux distro machine.
source code is open, suggestions and contributions are welcome.

Sunday, January 07, 2018

Overwrite stock A5-V11 Chinese firmware with openwrt-based a5v11-xmpp-image

This is a step-by-step guide for overwriting stock OEM chinese-image of a5-v11 with openwrt based a5v11-xmpp image.

what is a5-v11?: This is a low cost(5Euro) wifi router capable of running openwrt linux.

what is a5v11-xmpp-image?: this is a customized openwrt image which includes a c++ based xmpp-client-daemon for IoT application - look here for details.

Setup: As shown in the picture below, item-1,2 and 3 are needed and item-4,5 and 6 are optional - they are needed only when you are unable to figure out the ip address of a5-v11 using its hostname. There are otherways to know the ip of your a5-v11, ex: looking at the dhcp client list on your home-router's webpage. For any reason if you are unable to figure out the ip, you can use a usb-to-i2c converter and ssd-1306-i2c-display. Upon linux boot, a5-v11 prints its ip-addr on this i2c display.



Step-1: Download a5v11-xmpp-factory.uimg to your pc's hard-disk.

Step-2: Connect a cat-5 or cat-6 cable between a5v11 and your PC.

Step-3: Power ON a5-v11 with 5VDC and wait for ~1minute till your pc gets the ip from a5-v11(your pc shall get an ip in the range of 192.168.100.xxx)

Step-4: Enter "192.168.100.1" in your browser's URL and you shall see the following page.
If you dont see this page - stop here!!!!, your a5-v11 might have a different firmware. I have a separate blog explaining the step-by-step guide for overwriting qualcomm-based a5v-11 OEM-firmware.

Step-5: Click on language dropdown list to switch to english
Step-6: Click on Admin->Firmware-Upgrade->Choose File xmpp-a5v11-factory.uimg(which was downloaded in step-1).  And then click "upgrade" button.

Step-7: You will have to confirm by clicking "OK"
Step-8: A second confirmation is needed, click "OK"
Step-9: Firmware upgrade starts, you will see the following pages

Step-10: Wait for about 40seconds, remove the power to a5-v11, also remove cat-5/cat-6 cable which was connected between a5-v11 and PC.

 Step-11: Using cat-5/cat-6 network cable, connect a5-v11 to your home-router and ensure that your PC is also connected on your home-router's network.

Step-12: Power ON a5-v11 and wait till the red-LEDon a5-v11 stops blinking.

Step-13: Using ssh or putty.exe, login to a5-v11's shell terminal using hostname "my-a5v11" - login username/password is root/brb0x. For any reason, if you are unable to figure out the ip of a5-v11, as discussed earlier, you can connect an i2c display on usb port of this router,  and reboot to see its ip as shown here in this picture.

Step-14: after login to ssh terminal of a5-v11, change the default password to your own using "passwd" command

Step-15: Set the xmpp(jabber) server's login credentials with this command(replace example user and password with your own) - echo "user: test-slave-account@xabber.de" >/etc/xmproxy/xmpp-login.txt; echo "pw: chatbotpw">>/etc/xmproxy/xmpp-login.txt ; reboot

Step-16: Reboot a5-v11, you shall see that your device coming online on your smart phone's xabber chat client.

Next Steps: Follow my other blog to see how you can use a5v11-xmpp-chat-bot as an IoT gateway for home automation.

Saturday, January 06, 2018

Low cost - Uninterruptible power supply for broadband wifi router



There are places and situations where people are struggling with frequent power outages causing interruption in the internet access, this leads to dropped calls, dropped download sessions etc.

Typically, these power outages are of short duration as backup generator takes over the load within few minutes. A short disconnection of power causes reboot of broadband wifi routers and re-connection of internet for all the devices on the network.

To tackle this problem of short power outage, i found this interesting cable on aliexpress sold for 1Euro including shipping.
This 5v to 12v booster cable along with battery bank makes it a perfect low cost uninterruptible power supply for your broadband wifi router. Please note:  power output capacity of this bootster cable is in the range of 8Watts which should be enough for a standard broadband wifi router. (if you happen to have a router with higher than 8watt consumption, then look for highter capacity booster cable).

The black plastic housing towards the usb end contains a booster pcb(MT3068 converter) as shown here



As shown in the following picture, you can connect 5v Dc adapter to the battery bank's charging port and 5v output of batterybank powers the broadband wifi router through this booster cable.

Backup time of such a solution depends on capacity of the battery bank. In your situation if the power outage is of short duration, then you can manage with lower capacity battery bank, else you can go for a higher capacity one.