Friday, September 16, 2016

RBox - Raspberry pi Zero + USB 3G internet + XMPP = awesome IoT device

RBox - its a lightweight linux distribution built with buildroot. Current update binary size of RBox is around 25MB.

Here is my compact IoT setup based on Pi Zero + 3G usb Modem +prepaid SIM card+ 5200mAH battery pack.






What does this setup do?
SDCard in this Pi-Zero boots RBox linux image, during linux bootup following activities happen.

  1. usb_modeswitch switches the usb 3G modem to act as modem instead of default memory stick behaviour.
  2. umts-keeper along with sakis3g script would establish internet connection and keeps the connection alive.
  3. gloox, c++ library based daemon starts and logs in to a jabber server using preset xmpp login username and password. this xmpp daemon acts as a chat-bot.
  4. using android xabber app, communicate and control your pi-zero-IoT setup using chat messages.


What is so special about this setup?

  1. very low cost setup < 50Euro(PI_zero + sdcard + 3g_stick+sim_card+battery_pack)
  2. linux image is mounted as read-only, power cut doesnt harm the sdcard data.
  3. OTA linux image upgrade - full linux image upgrade over-the-air can be triggered by sending xmpp chat message.
  4. No need to have special cloud based service or opening-up-the port on internet with special dyndns registration. you just need two xmpp(jabber) or gmail accounts. one for pi-zero, second one for your mobile phone.
  5. possible to dial ussd codes via xmpp chat message for knowing the balance amount of prepaid sim card.
  6. possible to send/receive sms from your 3g-stick using xmpp chat messages.
  7. acts as a sms-gateway with xmpp based remote access for sms sending and receiving.
  8. possible to control pi-zero gpio's by sending get/set-gpio chat messages.
  9. possible to execute shell commands on pi-zero by sending  chat messages.

What are the typical application's of this setup?
  1. sms gateway - deploy this setup in your home country having local prepaid sim card, access your sms from anywhere in the world by sending jabber chat messages.
  2. weather station - deploy this setup within the 3g coverage area of your sim provider, along with solar panel and weather sensors, monitor the parameters by sending xmpp/jabber chat messages.
  3. fleet management - place this setup in your taxi/truck along with gps sensor, keep track of all your vehicles from a centralized control PC.
  4. wildlife monitoring - place this setup(along with camera) in 3G/Gsm covered forest area, monitor the activity of animals and take a picture and upload it on a cloud server.
  5. Remote asset management(e.g digital signage) - deploy this setup along with digital-signage display, control the content of your signage display by sending xmpp chat messages.
  6. Anti theft device - for cars, boats, mobile homes and caravans. let this device send you gps co-ordinates as chat messages when the pi-zero starts moving.
  7. Home automation - keep track of your holiday home, monitor temperature/humidity and control the relay's via gpio for switching on/off various devices.
  8. many more..


FAQ:
1) how much 3g data is consumed with this setup?
Ans: if there is no chat-message traffic to this setup, there is just xmpp-heart-beat packet sent to the jabber server(in my case typical usage per day is around few hundred kilo bytes).

2)how long does the battery backup last?
Ans: i have 5200mAH battery, fully charged battery kept my setup alive for about 8 to 10hours(you can have higher capacity battery for increased backup time).

3)Can i deploy this setup in a off the grid remote location?
Ans: ensure that you have higher capacity battery along with large solar panel(especially during winter with very low sun light  condition, you might need extra juice to keep setup running). Also Ensure that your setup is in 3G coverage area.

4)Is this project open source? where can i find the sources? how can i build the binary image myself?
Ans: yes, source code is hosted at this github location. Instructions for creating the binary image is given in the github location.

5)If i do, Over-The-Air linux image update, will this consume lot of my 3g-Data? 
Ans: yes, compared to normal xmpp traffic, linux image Over-The-Air update consume about 25MB data per upgrade, but then, how frequently would you be upgrading linux image? if you keep on adding new features, you might want to do frequent upgrades.

6)What happens if battery or power to pi-zero goes off during Over-The-Air linux image upgrade? will this brick my remotely deployed pi zero?
Ans:Rbox upgrade mechanism reduced the chances of bricking. During the upgrade process, non-active partition is programmed with new image. After the image is written to non-active partition, boot flag is flipped and pi reboots with updated partition.

7)I see that you have stacked up pi-zero/3g-stick/battery, why did u do that? wouldn't this be simpler to use pi-zero-included mini-usb-to-usb-converter?
Ans: yes, initially i did this, this is how my old and new setup looks, i like the compact setup instead of dangling wires, moreover rectangular brick shaped setup is easy for designing a 3D printed case.


8) I see that you are distributing ready to use bootable-binary-disk-image, but what if i want to build the image by myself from sources?
Ans: Here are details for generating binary from sources.

9) what about two or more xmpp accounts controlling this pi-zero-IoT setup? will this work?
Ans: Yes, Raspi0 acts as an xmpp-chat-bot, like typical xmmp-chat-scenario between humans, raspi can have multiple "friends" authorized to send/receive messages. e.g: you and your wife having separate xmpp/jabber accounts can trigger house-door-opening after kids arrival from school. Similarly, raspi can send asynchronous chat message to multiple subscribers on an I/O event(e.g when kids ring the door bell).

10)How much does this setup cost? what are the running costs?
Ans: Total cost including all components and prepaid simcard shall not be more than 50Euros.   Having a prepaid sim with around 100MB/30days data plan would be sufficient to keep the setup alive with basic I/O control and command traffic. Here in Germany, congstar charges 2Euros for a data plan of 100MB/30days. You need to decide for yourself based on your data-usage and provider's data plan.

11) I want to re-create the exact setup of your's, what parts do i need and what are the steps for creating sd card?
Ans: Items needed

  1. Raspberry pi zero v1.3
  2. Huawei E173 usb-3g-modem
  3. 8gb sdcard
  4. battery-pack
  5. four pogo pins
  6. general purpose pcb
  7. pcb mountable usb male and female connectors
SDCard Image creation:

  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(please note that your providers APN details may differ).
  7. Remove the SDCard from PC, and insert it into pi zero, wait for about 2-3 minutes for 3G Modem's LED to glow solid blue.
  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-zero will show up as online on your xabber client.
  10. Send a "Help" to your raspi-zero, 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.
  12. for gracious shutdown, send "poweroff" chat message and wait for 3g Modem's blue led to go off.



7 comments:

Donji said...

Will this work with MQTT and if it did, how do you think it would perform differently from your XMPP setup.
I want to make a portable smart locker with a 3G connection, solar panel, and a small E-ink display, but I want the battery to last for at least 8 hours, 3 days if possible with the solar panel.

I don't know a lot about computers, so forgive me if this is a stupid question.

ADAV said...

So far, i havent looked at MQTT. It should be possible to replace the XMPP daemon of Rbox with MQTT daemon, but i am not sure if this would have any impact on raspi-zero power consumption.

In my setup, linux on raspi is not tweaked for low power idle mode - linux continues to run all the time. So i cant comment how MQTT would help in reducing the power consumption.

Saim said...

Great post

assignment help service said...

it is offered by any official producer of such gadgets or you have made it on your own. how can i get one of these? if in case i need it ?

International Conference said...

very useful device for keep data saved.because due to many reasons data are not saved.so, we can use these type of devices

Online coursework said...

Help with Search Engine Optimization? I'm attempting to get my blog to rank for some focused on catchphrases yet I'm not seeing great outcomes. In the event that you are aware of any please share. Much obliged

http://www.needdissertation.co.uk/Nursing-dissertation/ said...

It is possible to boot your custom linux as read-only to avoid sd-data corruption because of power cuts. This allows your raspi zero and custom linux act as an embedded device which can sustain the power cuts.