Friday, September 16, 2016

Battery-Powered IoT Device with Pi Zero and 3G

A compact, battery-powered IoT device built from a Raspberry Pi Zero, a Huawei E173 USB 3G modem, and a prepaid SIM card. RBox — a lightweight Buildroot-based Linux distribution (~25 MB) — boots from the SD card, connects to the internet over 3G, and runs an XMPP chat-bot so you can monitor and control the device from your phone's chat app.

Compact Pi Zero IoT setup — top view

Compact stacked setup — Pi Zero, USB 3G modem, and 5200 mAh battery pack.

Pi Zero IoT setup — side view
Pi Zero IoT setup — rear view
Pi Zero IoT setup — detail view

What happens at boot

  1. usb_modeswitch switches the 3G modem from mass-storage mode to modem mode
  2. umts-keeper + sakis3g establish and maintain the 3G internet connection
  3. The XMPP chat-bot daemon (built on gloox, a C++ XMPP library) logs in to a Jabber server
  4. You can now communicate with the Pi Zero from your Android Xabber app (or any XMPP client)

Features

  • Total cost under ~50 EUR (Pi Zero + SD card + 3G stick + SIM + battery)
  • Read-only root filesystem — power cuts do not corrupt the SD card
  • Over-the-air Linux image upgrade via XMPP chat message (~25 MB per upgrade)
  • No cloud service, port forwarding, or dynamic DNS required — just two Jabber accounts
  • Send/receive SMS and dial USSD codes via chat messages
  • Control GPIO pins with get/set commands
  • Execute shell commands remotely via chat
  • Multiple XMPP accounts can control the same device simultaneously

Use cases

  • SMS gateway — deploy at home with a local prepaid SIM, access SMS from anywhere via Jabber
  • Weather station — deploy in a 3G coverage area with solar panel and sensors
  • Fleet management — place in vehicles with a GPS sensor, track from a central PC
  • Wildlife monitoring — deploy with a camera in a GSM-covered area
  • Digital signage — control display content remotely via chat
  • Anti-theft tracker — for cars, boats, caravans — sends GPS coordinates when movement is detected
  • Home automation — monitor temperature/humidity, control relays via GPIO

FAQ

How much 3G data does this use?
With no chat traffic, only XMPP heartbeat packets are sent — typically a few hundred kilobytes per day.

How long does the battery last?
A fully charged 5200 mAh battery keeps the setup running for 8–10 hours. Use a higher-capacity battery for longer runtime.

Can I deploy this off-grid?
Yes, with a larger battery and solar panel. Ensure the location has 3G coverage.

What happens if power fails during an OTA update?
RBox writes the new image to the non-active partition, then flips the boot flag and reboots. A power failure during the write leaves the active partition untouched.

Why the stacked form factor?
A compact rectangular brick is easier to enclose in a 3D-printed case than dangling cables.

Comparison — old setup with dangling cables vs compact stacked setup

Old setup (left) vs compact stacked setup (right).

How much does this cost to run?
Total hardware cost is under 50 EUR. A 100 MB / 30-day prepaid data plan (e.g. ~2 EUR/month with Congstar in Germany) is sufficient for basic I/O control and command traffic.

Items needed

  • Raspberry Pi Zero v1.3
  • Huawei E173 USB 3G modem
  • 8 GB SD card
  • Battery pack (5200 mAh or larger)
  • Four pogo pins
  • General-purpose PCB
  • PCB-mountable USB male and female connectors

SD card setup

  1. Create two XMPP accounts on a public Jabber server (tested with jabber.de, xabber.de, ubuntu-jabber.de) and authorize them to chat with each other
  2. Download the RBox SD card image
  3. Decompress with 7-Zip or your preferred tool
  4. Write the image to the SD card using Win32DiskImager or similar
  5. Remove and re-insert the SD card — a boot drive appears
  6. Create xmpp-login.txt on the boot drive using this template — replace the sample credentials with your device's XMPP username and password (update APN details for your carrier)
  7. Insert the SD card into the Pi Zero and power on — wait 2–3 minutes for the 3G modem LED to glow solid blue
  8. On your phone, open Xabber and log in with the master XMPP account
  9. The Pi Zero should appear online — send Help to see the list of available commands
  10. Send Sysupdate;reboot to update to the latest RBox image — see the full command reference
  11. For graceful shutdown, send poweroff and wait for the 3G modem LED to turn off

SOURCE CODE

github.com/hackboxguy/brbox — RBox sources and build instructions

Pi Zero build instructions — generate the binary image from source