Sunday, March 10, 2024

Transforming Your GL-MT300N-V2 Pocket Router into a DLNA Multimedia Server









In this guide, we'll walk you through a straightforward process to convert your GL-MT300N-V2 pocket router into a DLNA server, allowing it to function as a versatile media server.

  1. Download openwrt based Custom Firmware:
  2. Flash the Custom Firmware:
    • Replace the OEM firmware on your GL-MT300N-V2 pocket router with the custom gl-mt300nv2-dlnasrv.bin file
  3. Prepare Your Media Disk:
    • Format a USB Pendrive or USB disk as NTFS formatted disk(and copy all your media files to this disk under Audio/Video/Photo folders)
  4. Power-On:
    • Attach the media disk to the USB port of the pocket router
    • Power ON the pocket router with a +5V DC power source
  5. Wifi Connection:
    • After boot-up, the pocket router will appear as a Wi-Fi hotspot with the SSID/Key: dlnaserver/goodlife
  6. Install VLC Player:
    • Install VLC Player on your smartphone or tablet
  7. Connect to the DLNA Server:
    • Connect your smartphone or tablet to the pocket router's Wi-Fi hotspot (dlnaserver/goodlife).
  8. Access and Play Media Files:
    • Open VLC Player on your smartphone or tablet and navigate to the Local Network section.
    • Look for the dlna-server(with an image of penguin), where you can browse and play all your media files seamlessly(on multiple devices).
For those with an extensive multimedia collection, consider integrating this compact DLNA Server into your car's infotainment system. Passengers can seamlessly access a wealth of local media files on their smartphones or tablets via a shared Wi-Fi access point, ensuring uninterrupted entertainment even during long drives through areas with inconsistent network coverage. The image above illustrates our setup: a pocket router, powered by a +12v to +5v DC power adapter, paired with a USB media drive. When activated, this configuration transforms into a Wi-Fi hotspot, facilitating file sharing through DLNA service for all your smart devices.

Following sequence of images show you the exact steps to get your $30 GL-MT300N-V2 device up and running in few minutes.

After following all the 16 slides,  last step is to connect your smartphone(or tablet) to a wifi hotspot named dlnaserver(password is goodlife) and invoke vlc-media-player app to search for multimedia files over local network.


To enhance the security of this setup,
it is strongly advised to modify the default webUI login password, Wi-Fi SSID and Wi-Fi password. The procedure for changing these settings is accessible through the standard web interface of the OpenWRT Firmware.

In conclusion, it's worth noting that all the software customization and changes featured in this blog are open source and accessible on my GitHub repository. Feel free to modify or enhance them further by following the provided build instructions. Let me know in the comments section, in case if you have feedback, questions or suggestions. Happy hacking!!

Thursday, June 22, 2023

Interfacing Rugged-Metal-push-button with Raspberry-Pi




Recently I was in need of attaching push-buttons to Raspberry-pi(In Headless server mode) for invoking certain actions/scripts and to get the feedback of those invoked actions/scripts over the LED. Rugged-Metal-Pushbutton-with-LED-Ring was a perfect match for my requirement where I could interact with Raspberry sw without having to connect an hdmi-display and a keyboard.

There are many ways to connect Push-buttons to Raspberry pi using userspace I/O libraries, but to keep the sw effort minimal, I decided to use built-in triggerhappy-daemon of raspbian-linux-distro, where standard key-codes from /dev/input/eventX can be configured to invoke scripts/commands through e.g /etc/triggerhappy/triggers.d/actions.conf file.

In short, here are few steps involved in getting Push-buttons to work with Raspberry-Pi

  1. Connect pushbuttons to Raspberry-Pi gpio's as shown above in the connection diagram
  2. Prepare Raspberry-pi-OS-Lite sdcard using raspberry-pi-imager and boot the board
  3. ssh to raspberry pi's shell terminal,
  4. Add dtoverlay config lines to /boot/config as shown above
  5. create push-buttons.conf file under /etc/triggerhappy/triggers.d/
  6. modify /lib/systemd/system/triggerhappy.service file to run the triggerhappy as pi user
  7. create action-scripts which were configured in push-buttons.conf
  8. reboot the board and press a push-button to see the configured action being invoked
For beginners and  DIY enthusiast, here are the exact steps explaining a working demo setup where two push-buttons are used for switch ON/OFF of built-in ACT LED on Raspberry-Pi board.

Prepare the SDCard Image
  1. Download Raspberry-Image Application
  2. Open the Raspberry Pi Imager application ==> CHOOSE OS ==> Raspberry pi OS(Other) ==> Raspberry Pi OS Lite(32-bit)
  3. Insert the sdcard on your PC and select the sdcard by clicking "CHOOSE STORAGE" button on Raspberry pi Imager Application
  4. press "CTRL + Shift + X" to open the advanced options
  5. In Advanced options, set your hostname/enable-ssh/username/pw/local-time-settings as shown in the picture below and click SAVE button
  6. When done, click on the WRITE button to start creating the bootable sdcard for raspberry pi.

Next Steps:
  1. Connect two push-buttons to raspberry-pi Gpio pins as shown the diagram at the top of this blog
  2. Insert the sdcard, connect raspberry-pi to your local-dhcp-network and power ON the 5V to Raspberry-Pi
  3. login to raspberry pi's shell terminal using "ssh pi@my-raspi-001" when asked, use password which you specified in advanced menu of raspberry-pi-imager
  4. Once you are logged into raspberry-pi shell terminal, run the following 5 commands on the ssh teminal
    • 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


Wait for the raspberry pi to reboot(~40seconds) and press one of the push-buttons, and notice LED ring on this push button would start blinking at around 2Hz, Pressing the other push-button would start blinking its LED and at the same time LED ring on other push-button would stop blinking.


Instead of just blinking the LED's, this demo can be extended to do some real tasks upon button press. Just by overwriting two files(as shown below), button press can invoke flashing of different firmware binaries on esp8266-board(e.g wemos-d1-mini).  Just run the following two commands to replace blinking action to esp8266 firmware flashing:
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
with this change, After pushing the button, you will notice that the led-ring around the push-button starts blinking for about 30seconds(to indicate that wemos-d1-mini is being flashed) and then the blinking stops and results into different blink program being flashed to wemos-d1-mini.

Take a look at this and this script to see what exactly gets invoked upon button press. Sources/Scripts used in this demo are available here at github-repo


Friday, November 18, 2022

Bridging Mobile-Sms with XMPP-Instant-Messaging


When on a international travel - have you ever come across a situation where you could not receive an sms sent by your bank or any other online service for 2FA(user-verification-code)? Did you miss to enable international-roaming? or was there any limitation on using your local sim card abroad?

One of the work-arounds for such a situation is to leave your phone at home-network and ask a trusted person to read-out the 2FA verification code for you over the phone - Ever wondered how many times you had to disturb someone off hours for reading out the verification code? how's about having an online machine to do this for you 24/7?

I know it sounds like a bad idea to to bypass 2FA security mechanism by connecting your sim-card to internet, but this is the real problem many of us might be facing and continue to rely on someone in a remote location to read out the 2FA verification code during the international travel.

Using encrypted Xmpp or mqtt connection, it is possible to deliver an sms over the internet in a secure way to a remote location. Here is an example where xmpp instant messaging agent is used on raspberry-pi with Huawei-E173 3g USB dongle.

All the code presented here in this setup is opensource and you are free to decide any of the xmpp servers available on the internet(or you could deploy your own xmpp server using opensource projects like prosody). In this example I have created two accounts on jabber.de and prepared them to send/receive messages to each other(just login using both accounts on xabber-android-app and send friend requests between both accounts and accept the requests - messages can be sent/received between these two accounts now)

How to prepare sdcard for raspberry pi?

  1. Download Raspberry Pi Imager application
  2. Open the Raspberry Pi Imager application ==> CHOOSE OS ==> Raspberry pi OS(Other) ==> Raspberry Pi OS Lite(32-bit)
  3. Insert the sdcard on your PC and select the sdcard by clicking "CHOOSE STORAGE" button on Raspberry pi Imager Application
  4. press "CTRL + Shift + X" to open the advanced options
  5. In advanced options, set your hostname/enable-ssh/username/pw/local-time-settings as shown in the picture below and click SAVE button.
  6. When done, click on the WRITE button to start creating the bootable sdcard for raspberry pi.

Next Steps:
  1. Insert your local SIM card(ensure that it is not pin locked) in Huawei-E173(or Huawei-E303) usb-dongle and connect it to Raspberry-PI and keep the Raspberry-Pi powered ON and connected to your home internet 24/7.
  2. Once the Raspberry-pi has done booting, login using ssh or putty.exe "ssh pi@my-raspi-001" (you should know your hostname and login pw which was set during image creation)
  3. On Linux shell terminal of raspberry pi, run following commands,
  • 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
Please note, in the setup.sh command above, replace example xmpp username/pw with your custom created username and pw (setup.sh command may take 10 to 15 minutes on Raspberry-pi-1 to complete the installation).

On your android(or ios) xabber app, login using your account(e.g john.doe@jabber.de) and you will see raspberry pi being online - send "help" message and you will get an auto reply with all available commands.

How to Read SMS?
From your xabber xmpp app, send following commands to raspberry-pi-xmpp-client
  • smsupdate  (wait for return=Success : result=taskID=x )
  • smstotal (shall return the number of sms read to the local cache)
  • smsget 0 (will show the 1st sms from the local cache)

How to Send SMS?
From your xabber xmpp app, send following commands to raspberry-pi-xmpp-client

  • smssend +919876543210 this is a test message

How to Delete SMS?
Depending on the sim card size, when it is full, you will have to delete old messages to make room for new ones else you would stop receiving the new messages, following is the command to delete all messages from your SIM-card memory
  • smsdeleteall

Functional details: How does an SMS-Read flow work?
  • When you initiate an online transactions(e.g banking), as a 2FA mechanism, banking server (1)would send a security code to your registered mobile phone number(as shown in the 1st picture above, sms would flow from component 1==>2==>3==>5)
  • 5th component in the picture above is a 3g-gsm-modem which stores incoming sms messages in the sim memory
  • 6th component which is a Linux machine is running a service called bboxsmsrv which is based on libgammu - a mobile phone access library.
  • 6th component as a Linux machine is also running a service called xmproxysrv based on libgloox library and acts as a "headless xmpp client service", this client service logs into xmpp server(9) using provided username/password(e.g raspi-sim-1@jabber.de) and continues to send heartbeats to xmpp-server(9) to show its online status.
  • Xabber app on component 13 is also an xmpp client, but it has an UI where user can "chat" with friends just like whatsapp/telegram/sygnal/etc. Xabber-xmpp-client-app when connected to xmpp-server(9), will continue to show its online status through heart-beat packets.
  • when xmpp-clients (component 13 and 6) initiates a connection to xmpp-server(9), this server would pass on the roster data(contacts) to both xmpp-clients - this way xmpp clients know their "friends" and their online status and are able to send/receive message between them
  • when user sends "smsupdate" message from 13 to 6(through 9), xmproxysrv on 6, will parse this messages and asks bboxsmssrv to fetch all available sms from simcard memory through USB interface of the 3g-gsm-modem.
  • bboxsmsrv - after reading all sms messages, sends and event to xmproxysrv to notify the completion of last request, and then xmproxysrv woud forward this notification(return=Success : result=taskID=x) to xabber-xmpp-client-app(13)
  • In the next step, 13 would send "smstotal" to 6(through 9) and 6(with help of bboxsmsrv) would count number of sms messages in the cache and returns the total-sms-message-count back to 13.
  • 13 would send "smsget 0" to 6(through 9) for fetching the 1st message from bboxsmsrv's cache.

Functional details: How does an SMS-Send flow work?
Lets say, you want to send an sms to an international phone(component-4 as shown in the 1st picture) from component 13 or 15(both 13 and 15 are xmpp client apps with human interface) - e.g : when 13 sends a message(smssend +919876543210 this is test) - this message would flow as.. 13==>12==>10==>9==>8==>7==>6==>5==>3==>4, this means, 13(from a different country) was able to deliver an sms to 4 without paying any premium roaming charges.


Can Xmpp-xabber-app(13) ring a gsm-phone(4)?
Yes, using "dialvoice +919876543210" from 13, gsm-phone(4) would start ringing with called id of SIM-1 on component-5, other than just ringing a number, there is no functionality for dialvoice command.


Can Xmpp-Xabber-app(13) be able to send usdd-code to the provider(3) for reading the balance amount(incase if SIM-1 on 5 is a prepaid plan)?
Yes, using "dialussd" and "readussd" it is possible to send ussd-code and readback the response, here is an example to read prepaid balance of fonic-lidl sim card.
  • dialussd *100# (wait till response is received i.e: return=Success : result=taskID=x)
  • readussd (would show the balance amount received on this SIM-1)


Sunday, October 09, 2022

Re-purpose your $30 Pocket-Router as an AWS-IoT-Edge-Device

 


This blog is about upgrading default firmware of GL.iNet-MT300N-V2 pocket router with a custom built  Openwrt-Linux Image which includes a AWS-IoT-Device-SDK and aws-iot-pubsub-demo application.

With this demo image, you can turn your low cost Gl.iNet-MT300N-V2 pocket router into an AWS-IoT-Edge device which can feed local sensor data to the AWS-Cloud and it opens up many interesting use cases for developing various IoT applications.

As an average user, here are 3 easy steps which can turn your low cost pocket router into an AWS-IoT -Edge-Device,
  1. Overwrite OEM firmware with custom gl-mt300nv2-awsiot-demo.bin
  2. Using webUI, upload AWS-Cloud generated Device-certificate/Private-Key and set the Endpoint.
  3. Reboot the device and watch Hello-World messages being published to your Aws-IoT-Core.

Step-1: Prepare the Setup as shown in this picture below and Power-ON(wait for LED to stop blinking)



Step-2: On your Browser PC, open URL: http://192.168.8.1/cgi-bin/luci/admin/system/flashops (or you may be guided through a different onboarding process of GL.iNet's webUI)

Step-3: Find the sw upgrade menu on the webUI and upgrade the OEM sw with gl-mt300nv2-awsiot-demo.bin (make sure to disable "keep-settings" menu - we want to start with default settings)

Step-4: Wait for about 2minutes(till LED's on pocket router stops blinking)

Step-5: On you PC, Remove the network cable and re-plug so that your PC gets new IP starting with 192.168.20.x

Step-6: On your Browser PC, change the ULR to http://192.168.20.1 and you shall see the following:


Sunday, October 02, 2022

Linux-PREEMPT_RT Scheduler latency measurement with Oscilloscope


For those exploring Realtime capabilities of Linux using Preempt-RT patch, Here is a bootable sdcard-image for Beaglebone-Black(or Green) with fully preemptible kernel. This image includes all required libraries/utils/binaries and kernel-debug-capabilities required for evaluating Linux-Preempt-RT behavior. As a bonus, this image includes a gpio-test-program that mirrors an input signal to a gpio-output pin for measuring the scheduler latency using an Oscilloscope(Thanks to Maxime Chevallier of Bootlin for providing this demo-utility during PREEMPT_RT Training).

Setup Diagram: 


Required Items:

  1. Beaglebone-Black or Green
  2. +5V adapter
  3. micro-sdcard(1Gb or higher)
  4. Programmable-signal-generator-board
  5. 2-Channel-Oscilloscope
  6. Jumper-wires
Instructions:
  1. Prepare the setup as shown above(As a starter, set signal generator frequency to 100Hz with 50% duty)
  2. Download sdcard-beaglebone-preemptrt-demo.img.xz (image size is just under 25MB)
  3. Write sdcard-beaglebone-preemptrt-demo.img.xz to micro-sdcard using Balena-Etcher-Application.
  4. Remove the micro-sdcard from your PC and insert in Beaglebone and power ON the +5V
  5. After Linux boot, you will be able to see two square waves with a small phase difference between them(yellow waveform is the input to beaglebone and blue waveform is output from the beaglebone).
  6. Phase difference between yellow and blue signal indicates the latency introduced by scheduler while scheduling preemptrt-gpiotest program
  7.  On startup, /etc/init.d/S99PreemptrtGpioTester invokes "chrt -r 99 /usr/sbin/preemptrt-gpiotest gpiochip0 28 gpiochip0 17 h p" - which means starting preemptrt-gpiotest utility with priority 99. 

What is the purpose of this image?
For a quick evaluation of Linux-PREEMPT_RT behavior(or as a training material) one case use this readymade image to avoid long build process from sources using buildroot.
Using this image, you can study and tune your application to have deterministic timing behavior of the Linux scheduler at different load conditions. preemptrt-gpiotest program included in this image, mirrors a gpio-input to an output and the phase difference between these two signals gives an idea on how fast scheduler is able to give the required context to your application and the jitter(when measured with persist mode of the scope) on the output signal indicates the best and worst case scenario of the scheduler latency. Following picture shows best and worst case latency of the scheduler when subjected to different load on the hw(e.g network-traffic/interrupts/etc). For further details on this topic, check here to access Bootlin's PREEMPT_RT training material.




How can I build this bootable Linux-Image for beaglebone from sources?
Detailed build instructions are available here on my git-repository.

How do I modify and run my customized preemptrt-gpio utility on this beaglebone's target Linux?
Cross-compile instructions are available here on my git-repository.







Saturday, September 24, 2022

Raspi-4 Lightweight Custom Linux with AWS IoT Device SDK demo

This blog explains 6 simple steps to have a running AWS-IoT-Device-Sdk Demo in few minutes.

  1. Download sdcard-pi4-aws-iot-demo.img.xz (image size is just under 25MB)
  2. Write sdcard-pi4-aws-iot-demo.img.xz to sdcard using Balena-Etcher-Application
  3. After writing the sdcard image, un-plug/re-plug the sdcard to see the boot partition on your windows PC(e.g D or E drive)
  4. Open aws-iot-pubsub-agent.conf using text editor and set your endpoint(see picture below).
  5. Copy aws-console generated iot certificates to boot partition of the sdcard(e.g xyz-certificate.pem and xyz-private.pem.key)
  6. Insert the sdcard in rpi-4 hw and power-ON, after boot, aws-iot-pubsub-agent binary would start publishing the custom message to your AWS-IoT-Core.

Following image shows the steps 4/5/6 in detail,















Friday, July 03, 2020

Pimoticz : Vendor neutral Zigbee gateway with Raspi

Tldr: Instructions for preparing Raspi as zigbee gateway in 3 simple steps(git-clone/cd-to-dir/run-setup.sh;reboot)

These days its easy to find Zigbee based home automation devices at very low cost but all those Zigbee devices are targeted to be used with manufacturer provided gateway. This means, users are limited to a few set of zigbee devices supported by the manufacturer's gateway.

Using Commercial-Off-The-Shelf(COTS) hardware, there is a possibility to create your own "vendor neutral automation gateway" which opens up an interesting possibility of supporting more than 800 zigbee devices, but this involves an advanced knowledge of setting up Raspberry-Pi with various hw/sw components.

As an advanced user or DIY enthusiast, here is a list of components one would use to build a Zigbee gateway,

  1. Raspberry-Pi
  2. CC2531-USB-zigbee-Adapter(with koenkk firmware, can be purchased on amazon for ~$12)
  3. Raspberry-Pi OS(32bit)
  4. nodejs (ver 12 or higher)
  5. zigbee2mqtt
  6. mosquitto mqtt broker
  7. Domoticz
  8. zigbee2mqtt-plugin for Domoticz.

As an average user or a beginner to home-automation, its a challenging task to setup all these components to work together on a Raspberry-Pi.

Here is my attempt to simplify this setup using an automated installer script that takes care of installing all the dependencies and needed configuration. In about 5 minutes you should be ready to pair your first Zigbee device with Domoticz.

Items needed.

  1. Raspberry-Pi
  2. Micro sd-card
  3. 5v-power-adapter
  4. CC2531 based USB to zigbee adapter(important!!! to avoid programming setupbuy pre-programmed USb adapter with koenkk-firmware:CC2531_DEFAULT_20190608.zip or higher version)


Raspi-OS Installation steps:
NOTE: CC2531-usb-adapter/keyboard/mouse/monitor/internet-connection are needed during the initial setup only):

  1. Prepare the sd-card using Raspberry-Pi-Imager and install Raspberry-Pi-OS-32BIT(I assume this step is pretty straight forward, there are tons of guides explaining this).
  2. Insert the Raspberry-Pi-OS sd-card, connect key-board/mouse/monitor and internet to your Raspi and and turn on the 5Vdc power.
  3. On first boot, raspi-os will guide you through a setup wizard where you will be asked to setup few details like..
    • Language and key-board-lay-out(important to have a correct local time on your raspi for domoticz to work correctly).
    • Set new password for your "pi" Linux user.
    • check box asking if a black border is visible on the monitor(not important as your raspi will be running in headless mode after comoticz installation).
    • Wifi setup(ignore if you have already connected raspi using LAN wire).
    • Update sw(skip incase if you dont want to wait for all the upgrades to happen).
    • Reboot raspi to allow all the settings to take effect.

Pimoticz Installation steps:

  1. on raspberry PI, open a shell-terminal(using remote ssh login, or directly on Raspi)
  2. git clone https://github.com/hackboxguy/pimoticz.git
  3. cd /home/pi/pimoticz
  4. sudo ./setup.sh -h my-pimoticz (-h hostname is optional).
  5. wait for setup to finish (takes about ~5-6minutes)
  6. sudo reboot



After reboot, start the chrome browser on you raspi(or remote pc) and open http://127.0.0.1:8080 or http://my-pimoticz:8080 (here you will see domoticz webUI showing detected zigbee Coordinator-CC2531-USB-Zigbee-Adapter).