Tuesday, April 16, 2024

Getting Started with AWS IoT on OpenWrt Routers

While the internet is flooded with hello-world examples and simulations demonstrating the connection and message exchange between AWS-IoT Devices and AWS-IoT-Core using various programming languages like Python, C, C++, and Java, some of us beginners, students, or enthusiasts find true satisfaction in delving into the world of connected devices through hands-on interactions with physical components. The real excitement lies in experiencing the tangible effects firsthand, rather than merely observing basic hello-world messages on a computer screen.

Demo Video

How It Works

In this video, I introduce an engaging approach for exploring AWS-IoT connectivity and its real-world implications using affordable and readily available hardware components sourced from online stores. For this demonstration, I use an affordable (~$30) GL.iNet pocket router as an IoT End-Node.

This router runs on a custom-built OpenWRT Linux image and hosts an AWS IoT device agent service based on the aws-iot-device-sdk-cpp-v2. The WebUI of this custom Linux image allows you to easily configure and provision AWS IoT-specific settings such as:

  • Device certificates and private keys
  • AWS IoT Endpoints
  • Publish/subscribe topic trigger events
  • Custom scripts to control hardware accessories (switches, relays, LEDs, sensors)

Sunday, March 10, 2024

Pocket Router as a Portable DLNA Media Server

Turn a ~$30 GL-MT300N-V2 pocket router into a standalone DLNA media server — no internet required. Flash a custom OpenWrt firmware, plug in a USB drive with your media files, and any device on the Wi-Fi hotspot can stream via VLC or any DLNA client.

In-car infotainment setup: pocket router with USB media drive powered by 12V-to-5V adapter

In-car setup: pocket router powered by a 12 V-to-5 V adapter, paired with a USB media drive. All smart devices on the hotspot can stream via DLNA.

What you need

  • GL-MT300N-V2 pocket router (~$30)
  • USB flash drive or USB hard drive (NTFS formatted)
  • 5 V DC power source (USB charger, power bank, or 12 V-to-5 V adapter for car use)
  • VLC Player (or any DLNA client) on your smartphone or tablet

Setup steps

  1. Download the custom firmware — get gl-mt300nv2-dlnasrv.bin (~13 MB), an OpenWrt-based image with DLNA pre-configured.
  2. Flash the firmware — replace the OEM firmware on your GL-MT300N-V2 with the downloaded gl-mt300nv2-dlnasrv.bin file.
  3. Prepare your media disk — format a USB drive as NTFS and copy your media files into Audio/, Video/, and Photo/ folders.
  4. Power on — attach the media disk to the router's USB port and power the router with a 5 V source.
  5. Connect to Wi-Fi — the router broadcasts a hotspot with SSID dlnaserver and password goodlife.
  6. Open VLC — install VLC Player on your device, connect to the hotspot, and navigate to Local Network. The DLNA server (penguin icon) will appear with all your media files.

Default credentials: SSID = dlnaserver, password = goodlife. These are for initial setup only — change them immediately (see Security section below).

Step-by-step screenshots

The following image walks through the full flashing and configuration process in 16 slides:

Step-by-step setup guide for GL-MT300N-V2 DLNA server (16 slides)

Complete setup walkthrough: firmware flash, USB disk preparation, Wi-Fi connection, and VLC media browsing.

After following all 16 slides, connect your smartphone or tablet to the dlnaserver hotspot (password goodlife) and open VLC to browse media over the local network.

VLC Player showing DLNA server with media files

VLC Player on Android showing the DLNA server and available media files.

In-car infotainment use case

For those with an extensive multimedia collection, this compact DLNA server works well as an in-car infotainment system. Passengers can stream local media on their smartphones or tablets via the shared Wi-Fi hotspot — no mobile data or internet connection needed. This is especially useful during long drives through areas with poor network coverage.

The setup is simple: a pocket router powered by a 12 V-to-5 V DC adapter, paired with a USB media drive. When powered on, it creates a Wi-Fi hotspot and serves files over DLNA to all connected devices.

Security

Change the default credentials immediately. Modify the web UI login password, Wi-Fi SSID, and Wi-Fi password through the standard OpenWrt web interface at http://192.168.8.1.

Thursday, June 22, 2023

Rugged Metal Buttons with LED Rings on Raspberry Pi

How to interface rugged metal pushbuttons with LED rings to a headless Raspberry Pi — using the built-in triggerhappy daemon to invoke scripts on button press and provide LED feedback, with no display or keyboard needed.

Connection diagram — pushbuttons to Raspberry Pi GPIO

Connection diagram — two pushbuttons wired to Raspberry Pi GPIO pins.

How it works

Instead of userspace I/O libraries, this approach uses the triggerhappy daemon (built into Raspbian) to map standard key codes from /dev/input/eventX to scripts via /etc/triggerhappy/triggers.d/actions.conf.

Overview of the steps:

  1. Connect pushbuttons to Raspberry Pi GPIOs as shown in the connection diagram
  2. Prepare a Raspberry Pi OS Lite SD card using Raspberry Pi Imager
  3. SSH into the Raspberry Pi
  4. Add dtoverlay config lines to /boot/config
  5. Create push-buttons.conf under /etc/triggerhappy/triggers.d/
  6. Modify /lib/systemd/system/triggerhappy.service to run as the pi user
  7. Create action scripts configured in push-buttons.conf
  8. Reboot and press a button to see the configured action invoked

Prepare the SD card

  1. Download the Raspberry Pi Imager
  2. Open the app → CHOOSE OS → Raspberry Pi OS (Other) → Raspberry Pi OS Lite (32-bit)
  3. Insert the SD card and click CHOOSE STORAGE
  4. Press Ctrl + Shift + X to open advanced options
  5. Set hostname, enable SSH, username/password, and local time settings as shown below, then click SAVE
  6. Click WRITE to create the bootable SD card
Raspberry Pi Imager advanced options

Raspberry Pi Imager — advanced options for headless setup.

Setup and demo

  1. Connect two pushbuttons to Raspberry Pi GPIO pins as shown in the connection diagram
  2. Insert the SD card, connect the Pi to your local DHCP network, and power on
  3. SSH in: ssh pi@my-raspi-001 (use the password from the Imager advanced options)
  4. Run the following commands:
sudo apt-get install -y git esptool
git clone https://github.com/hackboxguy/pi-pushbtn-demo.git
cd pi-pushbtn-demo
sudo ./setup.sh
sudo reboot
Terminal showing setup commands

Running the setup commands on the Raspberry Pi.

Wait ~40 seconds for the Pi to reboot. Press one pushbutton — its LED ring blinks at ~2 Hz. Press the other button — its LED starts blinking and the first one stops.

Extending the demo

Instead of just blinking LEDs, the buttons can invoke real tasks. For example, to flash different firmware binaries to an ESP8266 (e.g. Wemos D1 Mini) on button press, replace the action scripts:

cp /home/pi/pi-pushbtn-demo/flash-esp-1hz.sh /home/pi/pi-pushbtn-demo/key-pressed-down.sh
cp /home/pi/pi-pushbtn-demo/flash-esp-4hz.sh /home/pi/pi-pushbtn-demo/key-pressed-up.sh

After this change, pressing a button blinks the LED ring for ~30 seconds (indicating the Wemos D1 Mini is being flashed), then stops when flashing completes. See the 1 Hz flash script and 4 Hz flash script for details.

Hardware setup — pushbuttons connected to Raspberry Pi

Complete setup — rugged metal pushbuttons connected to the Raspberry Pi.

SOURCE CODE

github.com/hackboxguy/pi-pushbtn-demo — scripts and setup instructions