Friday, April 19, 2024

DIY In-Car Infotainment using affordable COTS Hardware


Ever considered creating your own in-car entertainment system, akin to those found on airplanes? Envision a setup with individual touch displays for each passenger, ensuring an uninterrupted multimedia experience even when driving through areas lacking internet connectivity. Imagine a system that seamlessly accommodates both individual and communal content playback. What if such a system were not only affordable but also straightforward to build, utilizing open-source software and readily available off-the-shelf hardware?

In my GitHub repo, I'll guide you through a step-by-step process to construct such a system at an affordable cost, ranging from $180 to $200 per passenger touch screen. The key components of this setup includes a Power over Ethernet (PoE) switch, a pocket router serving as a DLNA/DHCP server, and multiple Raspberry Pi 4 boards paired with touch displays—adjustable based on the desired number of passenger screens.

By utilizing a Kodi player on RaspberryPi-4 coupled with a full HD touch screen and powered through a single Ethernet cable, we streamline cabling complexities in a car. This eliminates the need for a central multi-head controller, as the heavy lifting, such as multimedia decoding and rendering, is handled by individual Raspberry Pi 4 endpoints on a network. This distributed system is effortlessly scalable, requiring only the replacement of the PoE switch with more ports and the addition of more Raspberry Pi 4 touch displays. You can find the details here on my github repo: https://github.com/hackboxguy/multiscreen-media

Tuesday, April 16, 2024

Fun with AWS-IoT


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, However, 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. For them, the real excitement lies in experiencing the tangible effects firsthand, rather than merely observing basic hello-world messages on a computer screen.

In this video, I'll introduce you to 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'll be utilizing 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/private-keys/Endpoints. Additionally, through the WebUI, you can tailor various trigger events for specific publish/subscribe topics and execute diverse actions using custom scripts to control a range of hardware accessories including switches, relays, LEDs, sensors, and more.

For further details and access to the project, please visit my GitHub repository at: https://github.com/hackboxguy/aws-iot-demo

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.