Showing posts with label xmpp. Show all posts
Showing posts with label xmpp. Show all posts

Sunday, December 31, 2017

Remote Accessing your home network using smart phone and 5€ Linux H/W



In my quest for finding a cheapest off-the-shelf linux h/w, I came across this 5Euro device capable of running open-source linux OS(openwrt). I was delighted to see this tiny little device(A5-V11-router) consuming just around 0.3Watts - this is a perfect piece of h/w for IoT application.

Here are some interesting facts about this little device(A5-V11-router).
1)100Mbit Ethernet port
2)IEEE802.1b/g/n wifi interface
2)An usb port for attaching peripheral device
4)360Mhz Mips CPU(Ralink RT5350)
5)32Mb SDRAM
6)4Mb flash.
7)red and blue LED for showing different status.



It was intended to be used as an internet-hotspot  in combination with usb-3g-dongle and simcard. But, for my use, i have overwritten OEM fmw with my own customized openwrt(a5v11-xmpp) image which can be downloaded from here.

Q: what is the purpose of customized a5v11-xmpp image?
Ans: in this image, I have stripped down most of the router/wifi functionality to accomodate an xmpp-chat-client-daemon(lib-gloox based) to act as a chat-bot. Xmpp makes it easy to access your home network without tweaking your home router settings(e.g:port-opening/NAT etc). You dont need to expose any ports of your home-broadband-router to the internet.

Overwrite OEM firmware of a5-v11-router with a5v11-xmpp image and keep this little piece connected to your home internet so that you can "chat" with your h/w even when you are outside of home network.


Setup Instructions:

Step-1: Xmpp master/slave account creation.
As explained here, you need to prepare two xmpp/jabber accounts on your favorite jabber-server. and let these two accounts be "friends" so that xmpp-server can pass the messages between these two accounts.

Step-2: connect CAT-5/6 cable between your pc and a5-v11-router and power ON the router.

Step -3: Overwrite Stock Firmware with openwrt based a5v11-xmpp-image
On openwrt wiki there are instructions about how to overwrite stock firmware with openwrt-firmware. For overwriting the stock firmware with a5v11-xmpp-image, you can follow a step-by-step guide as detailed here in my other blog.

Step-5: Connect a5-v11-router to your home router's network(internet).

Step-6: login  to host "my-a5v11" using ssh/putty (user: root | pw: brb0x)

Step-7: prepare login details (This step is redundant as it is already explained in step-3)
echo "user: test-slave-account@xabber.de" >/etc/xmproxy/xmpp-login.txt; echo "pw: chatbotpw">>/etc/xmproxy/xmpp-login.txt ; reboot
Note: in above command, replace test-slave-account details with your own user/pw. (also use passwd command to change the default root password(brb0x) to your own)

Step-8: prepare your smart phone with xabber app and login using  test-master-account username and password.

Step-9: you will see that your a5-v11-router is online on your smart-phone's xabber app.

Step-10: type "help" and send the message to a5-v11-router, you will get the reply with list of available commands.


Q: Ok, what now? i have this tiny little device sitting next to my home router consuming 0.3w, what next? what can i do with it? can you give some examples?

Ans: here are some commands that makes this device useful.
1)From your smart-phone(no matter where u r in the word, as long as your phone is on internet) send "publicip" chat message and you get the response from chat-bot showing public-ip of your home router, this helps you to be independent of dynamic-dns setup, you can always see public-ip using xabber app.

2)connect i2c-tiny-usb (as shown in the picture below) to generate i2c from USB port of a5-v11-router, with i2c you can control/read many pheripheral chips ex: temp/humidity sensor, power sensor, gpio relay-control(use your imagination for home automation with i2c).
send  "shellcmd i2cdetect -r -y 0" and wait for "return=Success" message, and then read the output of last triggered shell command using "shellcmdresp" to see what i2c devices were detected.
ex: use "shellcmd i2cset -f -y 1 0x3c 0x00 0xff b" to make all pins of PCF8574 high.










3)Control sonoff wifi relays having tasmota firmware. ex: In your home network, if there is a sonoff relay at ip 192.168.1.10, send the following commands to chat-bot for controlling the relay(chat-bot uses http GET commands to control sonoff relays).
                a)"sonoff 192.168.1.10 on"        - switches ON the relay.
                b)"sonoff 192.168.1.10 off"       - switches OFF the relay.
                c)"sonoff 192.168.1.10 toggle"  - toggles the relay.
                d)"sonoff 192.168.1.10"             - reads the current state of relay.
Note: Incase if  sonoff relay has a hostname, replace the ip with hostname in the example above.

4)on your network if there are linux pc's, you can trigger remote commands via sshpass of the chat-bot. Here is an example..
                a)"shellcmd sshpass -praspberry ssh -y pi@raspi-ip  sudo reboot" would reboot raspi.
                b)"shellcmd sshpass -praspberry ssh -y pi@raspi-ip  sudo poweroff" would switch off raspi.
                c)"shellcmd sshpass -praspberry ssh -y pi@raspi-ip  omxplay /tmp/video.mp4" would start playing mp4 video.

5)send etherwake command to turn on a PC which was already in WoL mode, ex:
                 a)"shellcmd etherwake 00:00:DE:AD:BE:EF" (replace the MAC id with actual one)

watch-out this blog for for more use cases...


Q: I dont trust your ready to use image, I need to know the details, where are the sources? how can i create the image myself?
Ans: Here is the link to sources and build instruction so that you can create your own trusted image.

Sunday, January 03, 2016

RBox - A Lightweight Linux system for IoT

Update(18.11.2016): Raspi image provided here works only on Raspberry pi B+ 

RBox is an acronym for RemoteBox which is a light weight linux system specifically designed to address the connectivity challenges of IoT devices on public internet. Some of the key features of Rbox are as listed below.
  1. Runs on low cost opensource h/w like Raspberry Pi B+, BeagleboneBlack and BeagleboneGreen.
  2. Less than 20Mb of update-binary image for Raspi and less than 10Mb of update-binary for beaglebone.
  3. Provides an easy way of online update to latest Rbox version from a remote location and without having to remove SDCard, It uses a dual-boot mechanism for fail-safe linux upgrade against power-outage or network-failure.
  4. Keeps your Raspi or Beaglebone always accessible via xmpp chat server on public internet.
  5. Xmpp chat messages will allow you to remotely read/write GPIO pins of Raspi or Beaglebone.
  6. Provides basic set of commands to monitor the health status of Rbox.
  7. Lets you connect Huawei E173 GSM modem to usb port of raspi or beagle, and provides basic set of sim management commands like read-sms,send-sms, delete-sms, dial-ussd-code and voice-dialling(for the moment its dialing only, no GSM-to-voip bridging).
  8. Open source project hosted on Gighub


What are the Applications of RBox?

Although RBox is in early stage of the development, there could be many use cases where it can be deployed for remote asset management. As of now, I came across following use cases where RBox can be useful.
  1. Home Automation
  2. Remotely Deployed GSM SIM Management.


How to deploy RBox on Raspberry Pi B or B+?

  1. First and foremost is to have two xmpp login accounts on publicly available jabber servers(So far RBox has been tested with jabber.de/xabber.de and ubuntu-jabber.de). Follow my previous Post on how to create master and slave xmpp accounts(ensure that master/slave accounts have authorized each other to send/receive messages).
  2. Download the initial SDCard Image from here.
  3. Unzip the downloaded xz image using 7zip or your favorite decompression tool.
  4. Write the unzipped binary image to Sdcard using Win32DiskImager
  5. After writing the image to SDCard, remove and re-insert the card on your PC. Your PC will detect a new drive as "boot" where raspi's kernel and boot images are listed.
  6. In this "boot" drive, create a new file called xmpp-login.txt and copy this text. After copy, edit this file and replace sample user and password with actual username and password of your slave-device which you created in Step-1.
  7. Remove the SDCard from PC, and insert it into Raspberry Pi, connect network cable and power it ON(ensure that your LAN has internet connectivity).
  8. On your android phone, open xabber app and login using master's username and password which you created in Step-1.
  9. If everything goes well, raspi will show up as online on your xabber client.
  10. Send a "Help" to your raspi-slave, it will reply with list of available commands.
  11. Send "Sysupdate;reboot" and wait for raspi to update to latest RBox image, after update, it will reboot and be back online again with latest RBox version. Here is the detailed information on all available commands.

Please note that RBox is in its initial development phase, so far i am a lone contributor to this project, hopefully it will get better as more contributors join. Let me know in comments section if you are facing any problems.

In the coming days, I would be posting information on "How to deploy RBox for Beagleboneblack/green".


Xmpp Account Creation

Update: If you happen have two google accounts, just make these to accounts known to each other by authorizing the contact and use one account for yourself and second account for your chat-bot(in google's security settings of the second account, set "Allow less secure apps: ON").


This guide will help you to create an xmpp master and slave accounts on public xmpp server (tested servers: xabber.de/jabber.de/ubuntu-jabber.de)

Why xmpp master/slave account creation:
Xmpp has been widely used as a chat-client between humans, The technique explained here uses Xmpp protocol for remotely accessing and controlling the embedded devices over the public internet. Xmpp was chosen because of its wide adaption, security and ease of connectivity reasons.

Typical client-server communication over the public internet requires special setup as server's firewall needs to expose its port and the same has to be accessible via domain name which requires special dynamic-dns registration process. This is the typical use case for home routers or 3g-data-connected-phones which are provided with non-static public ip by the provider. Solutions discussed here is an attempt to overcome these connectivity challenges by using existing xmpp public chat server infrastructure for IoT stuff.

In this scenario, Master account is for a person who wants to control his/her slave-device from a smart-phone or PC(e.g, xabber android app or psi pc client), whereas slave-device, typically a remotely deployed Linux machine(raspberry pi, beaglebone,etc...) acts as a chat bot using slave-xmpp-account. As long as Master and Slave devices are connected to internet, they can communicate to each other irrespective of their deployed location on earth.

Ok lets get started!!

1)Install Psi xmpp client on your windows machine
2)Start Psi, General==>Account Setup
























3)click on Add















4)As shown in the picture below, follow 1 and 2

5)Enter public server as xabber.de and click on Next























6)After pressing "Next" it might take a while.. and then next box pops up
7)Field-1 shows username(in your case, choose a different username of choice)
8)Enter your own password as shown in Field-2
9)Open the Captcha link of Field-3 in a browser and the number shown by browser should be entered in Field-4
10)click "Next"






















11)If everything goes well, then you will see following dialog box, Click on "Ok"


12)A new box pops up as shown below, just click "Save"






























13)Next box pops up as shown below, just click "OK"








14)As shown below Go back to Psi main window, right-click on "master" entry ==> Status==>Online
























15)Next window pops up as shown below(Enter, fullname/Nickname as shown in Field-1, and click "close")


















16)Account creation for Master is done, now logout by right-clicking on "Master" entry ==>Status==>Offline (as shown below)


17)Repeat steps 1 to 15 for Slave account creation, pay attention at Step-4 and use string "Slave" and at step 7 and 8 use different username and password for slave. In step 15, use "Slave" as Full Name and Nickname.

18)Once the master and slave accounts are created, click on General==>AccountSetup and click on both the check-boxes of Master and Slave Accounts and Click Close button as shown below.















19)right click on "Slave" ==>Status ==>Online (wait for grey colored star to change its color to yellow, have patience, it might take some time), repeat the same for "Master", if everything goes well, you should see following box where both the master and slave stars are turned into yellow indicating as online.
























20)After creation of master and slave accounts, its now time to pair them to allow sending and receiving messages to each other. Its an authorization process defined by the xmpp standard to block unsolicited messages being sent without prior agreement between the chat clients.

21)before proceeding with next section, it is important to ensure that master and slave chat clients are able to send/receive messages(try some hi/hello messages between with master/slave clients to see if message can be sent/received at both ends)

22)what next? proceed to my next blog about Rbox - A Lightweight Linux system for IoT.