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

Monday, January 04, 2016

Remote GSM SIM Management with Raspberry Pi

Remote management of a GSM SIM card using a Raspberry Pi B+ and a Huawei E173 USB 3G modem. The RBox chat-bot connects to an XMPP/Jabber server and lets you send/receive SMS, make voice calls, and dial USSD codes — all from your phone's chat app, anywhere in the world.

Raspberry Pi B+ with Huawei E173 USB 3G modem

Raspberry Pi B+ with Huawei E173 USB 3G stick — the complete RBox GSM gateway.

Why remote SIM management?

  • Your SIM card has no roaming and you're travelling internationally
  • You're outside GSM coverage but have internet access and need SMS functionality
  • You manage multiple SIM cards and want centralized access
  • You need a self-hosted SMS gateway for sending/receiving over the internet
  • You have remote sensors that report data via SMS and want a central collection point

Ensure your SIM card is deployed at a safe and secure location to avoid possible misuse.

Items needed

  • Raspberry Pi B+
  • Micro or full-size SD card
  • Huawei E173 USB 3G stick
  • SIM card (PIN lock must be disabled)
  • 5 V / 2 A power supply
  • Two Google or Jabber accounts (one for you, one for the Raspberry Pi)
  • RBox SD card image

Setup

Setup diagram — Raspberry Pi with USB 3G modem connected to home router

Setup diagram — Huawei E173 plugged into the Raspberry Pi, which connects to the internet through a home router.

  1. Flash the RBox SD card image (see the RBox setup guide for details)
  2. Insert the PIN-unlocked SIM card into the Huawei E173 and plug it into the Raspberry Pi
  3. Connect the Raspberry Pi to your home router via Ethernet and power on with a 2 A supply
  4. On your phone's XMPP client (Xabber, Conversations, etc.), check that the Raspberry Pi account is online
  5. Send Help — the bot replies with the list of supported commands

Both XMPP accounts must be authorized as contacts before the Raspberry Pi is powered on — do this from a PC first.

When RBox boots without the USB 3G stick connected, SMS/SIM-related commands will not appear in the help list.

Reading SMS

  1. Send Smsupdate — immediate reply: InProgress : taskID=1
  2. Wait 3–5 seconds for the modem to read the SIM
  3. Reply Success : taskID=1 confirms messages are cached
  4. Send Smstotal — reply shows the count (e.g. Success : 2)
  5. Send Smsget 0 to read the first message, Smsget 1 for the second, etc.

Deleting SMS

  1. Send Smsdeleteall — immediate reply: InProgress : taskID=2
  2. Wait 3–5 seconds
  3. Reply Success : taskID=2 confirms deletion
  4. Verify with Smsupdate followed by Smstotal — if messages remain, repeat the delete

Sending SMS

  1. Send Smssend 009198xxxxxxxx hello this is a test message
  2. Immediate reply: InProgress : taskID=3
  3. Wait 3–5 seconds — reply Success : taskID=3 confirms the SMS was sent
  4. If sending fails, try omitting the international/country code prefix (0091)

Voice dialling

  1. Send Dialvoice 009198xxxxxxxx
  2. Immediate reply: InProgress : taskID=4
  3. The modem dials and rings for 20–25 seconds, then disconnects automatically
  4. Reply Success : taskID=4 confirms the call completed

Voice dialling currently places a silent call (no audio playback). Future RBox releases may support playing a recorded message for automation use cases.

USSD codes

USSD codes like *101# are useful for checking prepaid balance and other carrier queries.

  1. Send Dialussd *101# (the code varies by carrier)
  2. Immediate reply: InProgress : taskID=5
  3. Wait 3–5 seconds — reply Success : taskID=5 confirms the USSD response was received
  4. Send Readussd to read the carrier's response text

SOURCE CODE

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

Control Home Devices via XMPP Chat with Raspberry Pi

Control your home devices from anywhere using a Raspberry Pi running the RBox Linux distribution. The RBox chat-bot connects to a public XMPP/Jabber server, so you can toggle GPIO pins from your phone's chat app — no port forwarding, no dynamic DNS, no paid cloud services.

How it works

Setup diagram — Raspberry Pi at home communicating with smartphone via XMPP

Setup diagram — Raspberry Pi at home and your phone both connect to a public Jabber server. Chat messages carry GPIO commands.

Both the Raspberry Pi (running RBox) and your Android phone (running Xabber or any XMPP client) log in to a public Jabber server with their own credentials. Once the two accounts have authorized each other, they can exchange chat messages through the server.

Advantages

  • No router configuration or port forwarding needed — all incoming firewall ports can stay blocked
  • No dependency on paid cloud services — hundreds of free Jabber servers are available
  • Works from any location as long as your phone has internet access (Wi-Fi or mobile data)

Controlling GPIO

To toggle a GPIO pin, send a chat message from your XMPP client:

Gpio 2 1    # set GPIO2 high
Gpio 2 0    # set GPIO2 low

For full setup instructions (SD card preparation, XMPP account creation, first boot), see the RBox installation guide.

SOURCE CODE

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