Friday, November 18, 2022

Bridge SMS to XMPP: Receive 2FA Codes Abroad

Bridge your mobile SMS with XMPP instant messaging so you can read and send text messages from anywhere over the internet. The primary use case: receiving 2FA verification codes while travelling internationally, without roaming or asking someone at home to read them out for you.

Setup diagram — SMS flows from GSM network through Raspberry Pi to XMPP client

Setup overview — a Raspberry Pi with a USB 3G modem bridges SMS to XMPP via a public Jabber server.

The setup uses a Raspberry Pi with a Huawei E173 (or E303) USB 3G dongle and an encrypted XMPP connection to deliver SMS securely to your phone's chat app. All code is open source, and you can use any public Jabber server (or host your own with Prosody).

Preparing the SD card

  1. Download the Raspberry Pi Imager
  2. Open it and select: CHOOSE OS → Raspberry Pi OS (Other) → Raspberry Pi OS Lite (32-bit)
  3. Select your SD card via CHOOSE STORAGE
  4. Press Ctrl + Shift + X to open the advanced options
  5. Set hostname, enable SSH, username, password, and timezone as shown below, then click SAVE
  6. Click WRITE to create the bootable SD card
Raspberry Pi Imager advanced options dialog

Raspberry Pi Imager — advanced options for hostname, SSH, and credentials.

Setting up the Raspberry Pi

  1. Insert your SIM card (PIN lock must be disabled) into the Huawei E173/E303 dongle and connect it to the Raspberry Pi
  2. Keep the Pi powered on and connected to your home internet 24/7
  3. Once booted, SSH in:
ssh pi@my-raspi-001
  1. Install the XMPP remote agent:
sudo apt-get install -y git
git clone --recursive https://github.com/hackboxguy/xmpp-remote-agent.git
cd xmpp-remote-agent
./setup.sh -u raspi-sim-1@jabber.de -p my-raspi-xmpp-secret-pw
sudo reboot; exit

Replace the example XMPP username and password with your own credentials.

The setup.sh script may take 10–15 minutes on a Raspberry Pi 1.

On your phone's Xabber app (Android or iOS), log in with your XMPP account (e.g. john.doe@jabber.de). The Raspberry Pi should appear online — send help to get the list of available commands.

Reading SMS

smsupdate       # fetch SMS from SIM to cache (wait for Success response)
smstotal        # show number of cached messages
smsget 0        # read the first message

Sending SMS

smssend +919876543210 this is a test message

Deleting SMS

When the SIM memory is full, new messages stop arriving. Delete all stored messages with:

smsdeleteall

Voice dialling and USSD codes

Ring a GSM phone (caller ID shows as SIM-1's number, no audio — ringing only):

dialvoice +919876543210

Check prepaid balance or send other USSD codes:

dialussd *100#     # send USSD code (wait for Success response)
readussd           # read the carrier's response

How it works internally

Two services run on the Raspberry Pi:

  • bboxsmsrv — based on libgammu, handles SMS read/write/delete via the USB 3G modem
  • xmproxysrv — based on libgloox, acts as a headless XMPP client that logs into the Jabber server and maintains an always-on connection

When a 2FA SMS arrives, it is stored in the SIM memory by the 3G modem. On your phone's Xabber app, you send smsupdate → xmproxysrv parses the command and asks bboxsmsrv to fetch messages from the SIM → once complete, a Success response is sent back → you then read the messages with smsget.

For sending, the flow reverses: your chat message travels through the XMPP server to xmproxysrv, which hands it to bboxsmsrv, which sends the SMS via the 3G modem — delivering an SMS to any phone number without roaming charges.

SOURCE CODE

github.com/hackboxguy/xmpp-remote-agent — setup scripts and configuration

github.com/hackboxguy/brbox — bboxsmsrv and xmproxysrv sources

Sunday, October 09, 2022

$30 Pocket Router as an AWS IoT Edge Device

How to flash a ~$30 GL.iNet MT300N-V2 pocket router with a custom OpenWrt image that includes the AWS IoT Device SDK and an aws-iot-pubsub-demo application — turning it into an AWS IoT Edge device that can feed local sensor data to the cloud.

GL.iNet MT300N-V2 pocket router as AWS IoT Edge device

GL.iNet MT300N-V2 pocket router — ready to become an AWS IoT Edge device.

Quick overview

Three steps to turn your pocket router into an AWS IoT Edge device:

  1. Flash the OEM firmware with the custom gl-mt300nv2-awsiot-demo.bin
  2. Upload your AWS-generated device certificate and private key via the web UI
  3. Reboot and watch Hello World messages published to your AWS IoT Core

Flashing the firmware

Step 1 — Connect your PC to the pocket router via Ethernet and power it on. Wait for the LED to stop blinking.

Setup diagram — PC connected to pocket router

Setup: PC connected to the pocket router via Ethernet cable.

Step 2 — Open http://192.168.8.1/cgi-bin/luci/admin/system/flashops in your browser (or follow GL.iNet's onboarding process).

Step 3 — Find the firmware upgrade menu and flash with gl-mt300nv2-awsiot-demo.bin.

Important: Disable "Keep settings" — you want to start with default settings.

Step 4 — Wait about 2 minutes until the LEDs stop blinking.

Step 5 — Disconnect and reconnect the Ethernet cable on your PC so it gets a new IP in the 192.168.20.x range.

Step 6 — Navigate to http://192.168.20.1 — you should see the new web UI:

Custom firmware web UI

Custom firmware web UI after successful flash.

AWS IoT configuration

Step 7 — Upload your device certificate and private key files through the web UI:

Certificate and key upload page

Upload your AWS-generated device certificate and private key.

Step 8 — Go to AWS-IoT → Service Settings, enter your endpoint, and click Save & Apply.

Before clicking Save & Apply, ensure your security policies on console.aws.amazon.com are set up correctly (see Step 10 below).

AWS IoT service settings page

Service Settings — enter your AWS IoT endpoint here.

Step 9 — Check the Service Log. If everything is configured correctly, you should see a "connection success" message:

Service log showing connection success

Service Log — "connection success" confirms the router is connected to AWS IoT Core.

Step 10 — On console.aws.amazon.com, ensure your security policies are set correctly:

AWS IoT security policies

AWS IoT security policies — required permissions for the device.

Testing publish and subscribe

Step 11 — On console.aws.amazon.com, subscribe to topic test/topic to see Hello World messages published from your pocket router. By default, the demo publishes 10 messages at 5-second intervals. To publish continuously, increase the Publish Count in the Service Settings page.

AWS IoT Core showing Hello World messages

AWS IoT Core — Hello World messages arriving from the pocket router.

Step 12 — To test the subscribe action, publish a JSON message to topic test/topic_led from the AWS console to control the router's LED:

{"powerstate" : "on"}
{"powerstate" : "off"}
Publishing LED control messages from AWS console

Publishing LED control commands from the AWS IoT console.

Other use cases

The pocket router can act as a gateway between AWS IoT Core and local Wi-Fi or USB-connected devices:

Use case diagram — pocket router as IoT gateway

Possible use cases — the pocket router bridges local devices to AWS IoT Core.

SOURCE CODE

github.com/hackboxguy/openwrt-wrapper — build instructions and sources

gl-mt300nv2-awsiot-demo.bin — pre-built firmware image

Sunday, October 02, 2022

Measuring PREEMPT_RT Latency with an Oscilloscope

A ready-to-use bootable SD card image for BeagleBone Black/Green with a fully preemptible Linux kernel (PREEMPT_RT) — includes a gpio-test program that mirrors an input signal to a GPIO output pin for measuring scheduler latency with an oscilloscope.

Oscilloscope showing input and output waveforms with scheduler latency

Oscilloscope view — yellow is the input signal, blue is the GPIO output. The phase difference indicates scheduler latency.

Thanks to Maxime Chevallier of Bootlin for providing the gpio-test demo utility during PREEMPT_RT training.

Setup diagram

Setup diagram — signal generator, BeagleBone, and oscilloscope

Setup diagram — signal generator feeds the BeagleBone, oscilloscope measures input vs output.

Items needed

Instructions

  1. Prepare the setup as shown in the diagram (set signal generator to 100 Hz, 50% duty cycle)
  2. Download sdcard-beaglebone-preemptrt-demo.img.xz (~25 MB)
  3. Write the image to a micro SD card using Balena Etcher
  4. Insert the SD card into the BeagleBone and power on
  5. After boot, the oscilloscope shows two square waves with a phase difference — yellow (input) and blue (output from BeagleBone)
  6. The phase difference indicates the latency introduced by the scheduler while running the preemptrt-gpiotest program

On startup, /etc/init.d/S99PreemptrtGpioTester invokes:

chrt -r 99 /usr/sbin/preemptrt-gpiotest gpiochip0 28 gpiochip0 17 h p

This starts the gpio-test utility at real-time priority 99.

Measuring latency under load

The gpio-test program mirrors a GPIO input to an output — the phase difference between the two signals shows how fast the scheduler delivers context to your application. Jitter on the output signal (measured in oscilloscope persist mode) indicates the best and worst case scheduler latency under different load conditions (network traffic, interrupts, etc.).

Oscilloscope persist mode showing best and worst case latency

Persist mode — showing best and worst case scheduler latency under load.

For further details on PREEMPT_RT, see Bootlin's PREEMPT_RT training material.

Building from source

Detailed build instructions are available in the git repository. Cross-compile instructions for modifying and running a customized gpio-test utility are also available.

SOURCE CODE

github.com/hackboxguy/preemptrt-gpiotest — GPIO latency test program

github.com/hackboxguy/br-wrapper — Buildroot config and build instructions

sdcard-beaglebone-preemptrt-demo.img.xz — pre-built SD card image (~25 MB)

Saturday, September 24, 2022

AWS IoT on Raspberry Pi with 25 MB Buildroot Linux

Six simple steps to get an AWS IoT Device SDK demo running on a Raspberry Pi 4 — using a lightweight custom Linux image built with Buildroot (just under 25 MB).

Quick start

  1. Download sdcard-pi4-aws-iot-demo.img.xz (~25 MB)
  2. Write the image to an SD card using Balena Etcher
  3. Unplug and re-plug the SD card so the boot partition appears on your PC
  4. Open aws-iot-pubsub-agent.conf and set your AWS IoT endpoint
  5. Copy your AWS-generated device certificate (xyz-certificate.pem) and private key (xyz-private.pem.key) to the boot partition
  6. Insert the SD card into the Raspberry Pi 4, power on — the aws-iot-pubsub-agent will start publishing messages to your AWS IoT Core

The following image shows steps 4, 5, and 6 in detail:

SD card configuration — endpoint, certificates, and boot

Steps 4–6: configure endpoint, copy certificates, and boot the Pi.

AWS cloud preparation

Before booting the Pi, set up the following on console.aws.amazon.com:

  1. Create an AWS IoT account (payment details required even for the free tier)
  2. Navigate to IoT Core
  3. Go to Manage → All Devices → Things → Create Thing
  4. Download the device certificate and private key (copy these to the SD card boot partition as described in step 5 above)
  5. Go to Settings and note your Endpoint (needed for step 4 above)
  6. Go to Security → Policies and create a policy with 4 entries as shown below:
AWS IoT security policy configuration

AWS IoT security policy — required permissions for the device.

Building the image from source

Two commands to build the SD card image (detailed instructions in the git repository):

make -C buildroot BR2_EXTERNAL=../ BR2_DL_DIR=../../br-dl O=../../br-output raspberrypi4_aws_iot_defconfig
make -C buildroot BR2_EXTERNAL=../ BR2_DL_DIR=../../br-dl O=../../br-output

Buildroot customizations

Key changes in the Raspberry Pi 4 Buildroot config for this AWS demo image:

  1. Enabled Dropbear SSH for remote debugging without monitor/keyboard
  2. Added Buildroot package for aws-iot-device-sdk-cpp-v2
  3. Added Buildroot package for aws-iot-pubsub-agent
  4. Enabled chrony for time sync (required for TLS handshake)
  5. Enabled SDK dependencies (host-cmake, libcurl, openssl, util-linux)
  6. Included AmazonRootCA1.pem in /etc/
  7. Added aws-iot-pubsub-agent.conf to rootfs for the agent startup script
  8. Added /etc/init.d/S03MountBoot to mount the boot partition at /mnt/certs (contains certificates, key, and config)
  9. Included startup script for aws-iot-pubsub-agent

After booting

  1. Connect the Raspberry Pi 4 to a DHCP network with internet access
  2. Find the Pi on your network using hostname buildroot or its assigned IP
  3. Log in via SSH: ssh root@192.168.x.y (password: brb0x)
  4. Check the publish log: cat /tmp/aws-iot-pubsub-agent.log
  5. To modify the aws-iot-pubsub-agent code, see how to cross-compile and run on target

If everything is configured correctly (SD card and AWS security policies), Hello World! messages will appear on your AWS IoT Core console:

AWS IoT Core showing Hello World messages from Raspberry Pi

AWS IoT Core — Hello World messages arriving from the Raspberry Pi 4.

SOURCE CODE

github.com/hackboxguy/br-wrapper — build instructions and Buildroot config

sdcard-pi4-aws-iot-demo.img.xz — pre-built SD card image (~25 MB)