Foreword

No, I’m not Chinese. Or Asian, or fan of 9GAG (although I get there sometimes for a fresh portion of laughs). The name of the blog was chosen to be yunofun because all good names seemed to be taken on WordPress. This blog wants to be a technical one, and I’ll share some things in my field of interest (usually networking). So why not have some fun with tehnical stuff? 🙂

Yet Another Internet Radio version 2 with installer script

I added some small improvements to the web radio.

The biggest improvement, though, is the addition of the installer script for the web radio. I thought that a step by step guide could be difficult to follow and I think this is the best idea.

Prerequisites

  • read the disclaimer 🙂
  • functional extroot filesystem. If you choose to use my Easy Extroot project, version 2 of Easy Extroot  includes the script in /etc/init.d/radio
  • it does not depend on the router – any router running Openwrt with extroot is good (to install the files and prerequisites). Of course, if you want it to sing, USB audio hardware should be installed 🙂

The script installs the dependencies and downloads the needed files from the Github. Backup your existing files in /www directory (existing files will be overwritten)! 

Also, the radio script is included by default in Easy Extroot v2, both BB and CC.

Files

radio

install

Radio script

#!/bin/sh

echo
echo -e "\e[1;95m Welcome to Yet Another Internet Radio installer
 -----------------------------------------------
\e[0;37m"

echo -n "Checking if audio hardware is installed..."

#check if audio hardware is installed. Works only in CC (in BB a restart is needed after installing audio packages)
if ! `cat /etc/banner | grep -q BARRIER`; then
 if ! `ls /dev | grep -q -e audio -e dsp -e mixer`; then 
 is_audio=0
 echo
 echo -en "\e[1;95mSoundcard was not detected.\e[0;37m"
 read -p $'\n'"The installer can still copy the required files and install needed packages, but the radio will not work unless audio hardware is installed."$'\n'"Do you want to continue (y/n)?" choice
 case "$choice" in 
  y|Y ) 
   ;;
  n|N ) return 1;;
  * ) 
   echo "invalid choice, assume no"; return 1
   ;;
 esac
 else is_audio=1;
 fi
 echo  Done!
else echo " BarrierBreaker detected, skipping this step."
fi

echo -en "\e[1;95mThis installation will overwrite existing files in the /www directory and subfolders.\e[0;37m"
read -p "Are you sure you want to continue (y/n)?" choice
case "$choice" in 
  y|Y ) 
   ;;
  n|N ) return 1;;
  * ) 
   echo "invalid choice, assume no"; return 1
   ;;
esac

if `wget -sq http://www.google.ro/index.html`;then is_online=1; else is_online=0; fi
if [ $is_online == 0 ]; then
 echo -en "\e[1;95mThis box is not connected to the Internet. \e[0;37m"
 echo "Script will now quit"$'\n'"Connect your browser to http://<ipofthisbox> or modify manually the config files in /etc/config to connect to the Internet."
 return 1
fi

echo -n "Updating packages..."
opkg update > /dev/null 2>&1
if [ ! $? == 0 ]; then echo $'\n'"There was a problem executing opkg update. Script will now exit.";return 1;else echo ' Done!';fi

num=`df | grep rootfs | awk '{print $4}'`
if [ "$num" -gt "50000" ]; then is_extroot=1;else is_extroot=0;fi

if [ ! $is_extroot == 1 ]; then 
 echo -en "\e[1;95mThis box does not have a working extroot filesystem. \e[0;37m"
 echo "Script will now quit."
 return 1
fi

if `cat /etc/banner | grep -q CHAOS`; then
 echo -n "OpenWrt CHAOS CALMER release detected, installing prerequisites..."
 opkg install curl kmod-usb-audio kmod-sound-core alsa-utils gstreamer1 gstreamer1-utils gstreamer1-plugins-base gst1-plugins-good gst1-libav > /dev/null 2>&1
else
 echo -n "BARRIER BREAKER or earlier release detected, installing prerequisites..."
 opkg install curl kmod-usb-audio kmod-sound-core alsa-utils gstreamer gstreamer-utils gst-plugins-base gst-plugins-good gst-plugins-ugly gst-mod-faad gst-mod-souphttpsrc > /dev/null 2>&1
fi
if [ ! $? == 0 ]; then echo "There was a problem installing the prerequisites. Script will now exit.";return 1;else echo " Done!";fi

echo -n "Downloading web interface of the radio from Github..."
curl -ksf https://raw.githubusercontent.com/c2sandu/webradio/master/radio.tar.gz -o /tmp/radio.tar.gz
if [ ! $? == 0 ]; then echo "There was a problem downloading the archive from Github. Script will now exit.";return 1;
else
 echo " Done!";
 echo -n "Decompressing web interface to /www..."
 tar zxvf /tmp/radio.tar.gz -C /www > /dev/null 2>&1
 if [ ! $? == 0 ]; then echo $'\n'"There was a problem decompressing the archive. Script will now exit.";return 1;else echo ' Done!';fi
fi

if [ "$is_audio" == "1" ]; then 
 read -p "Do you want to start the web radio now (y/n)?" choice
 case "$choice" in 
  y|Y ) 
   if `cat /etc/banner | grep -q CHAOS`; then
    killall gst-launch-1.0 > /dev/null 2>&1
    index=`cat /www/index`
    url=`awk "NR == $index" /www/radio | cut -f2 -d"|"`
    gst-launch-1.0 -t playbin uri=$url | awk /title:/ | tee /tmp/title > /dev/null 2>&1 &
   else
    killall gst-launch-0.10 > /dev/null 2>&1
    index=`cat /www/index`
    url=`awk "NR == $index" /www/radio | cut -f2 -d"|"`
    gst-launch -t playbin uri=$url | awk /title:/ | tee /tmp/title > /dev/null 2>&1 &
   fi
   ;;
  n|N ) ;;
  * ) echo "invalid choice, assume no";;
 esac
fi

if ! `cat /etc/rc.local | grep -q gst-launch`; then 
 read -p "Do you want to start the web radio automatically at router startup (y/n)?" choice
 case "$choice" in 
  y|Y ) 
    sed -i  '/exit 0/d' /etc/rc.local
    echo 'index=`cat /www/index`' >> /etc/rc.local
    echo 'name=`awk "NR == $index" /www/radio | cut -f1 -d"|"`' >> /etc/rc.local
    echo 'url=`awk "NR == $index" /www/radio | cut -f2 -d"|"`' >> /etc/rc.local
    echo 'alsactl -f /etc/alsa0.state nrestore' >> /etc/rc.local
    echo 'gst-launch-1.0 -t playbin uri=$url | awk /title:/ | tee /tmp/title &' >> /etc/rc.local
    #echo '/etc/init.d/restart_radio &' >> /etc/rc.local
    echo 'exit 0' >> /etc/rc.local
   ;;
  n|N ) ;;
  * ) echo "Invalid choice, assuming negative answer";;
 esac
fi

read -p "Do you want to restart the web radio if streaming stops for some reasons (temporary network problems, problems with the stream, etc)?"$'\n'"Use this option only if this box is dedicated for Internet radio. (y/n)?" choice
case "$choice" in 
  y|Y ) 
cat <<EOM > /etc/init.d/restart_radio
#!/bin/sh

while true ;
do 
if ps | grep gst-launch | grep -v grep > /dev/null
then
    echo "Running"
else
 index=\`cat /www/index\`
 name=\`awk "NR == \$index" /www/radio | cut -f1 -d"|"\`
 url=\`awk "NR == \$index" /www/radio | cut -f2 -d"|"\`
 alsactl -f /etc/alsa0.state nrestore
 gst-launch-1.0 -t playbin uri=\$url | awk /title:/ | tee /tmp/title &
 logger "Radio restarted by restart_radio"
fi
sleep 20;
done
EOM
   if `cat /etc/banner | grep -q BARRIER`; then
	sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /etc/init.d/restart_radio
   fi
   chmod +x /etc/init.d/restart_radio; /etc/init.d/restart_radio > /dev/null 2>&1 &
   sed -i  '/exit 0/d' /etc/rc.local
   if ! `cat /etc/rc.local | grep -q restart_radio`; then 
    echo '/etc/init.d/restart_radio &' >> /etc/rc.local
   fi
   echo 'exit 0' >> /etc/rc.local
   ;;
  n|N ) 
    rm /etc/init.d/restart_radio > /dev/null 2>&1; killall restart_radio > /dev/null 2>&1 
    ;;
  * ) 
    echo "invalid choice, assume no"
    rm /etc/init.d/restart_radio > /dev/null 2>&1; killall restart_radio > /dev/null 2>&1 
    ;;
esac

if `cat /etc/banner | grep -q BARRIER`; then
 sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /www/cgi-bin/first.cgi
 sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /www/cgi-bin/last.cgi
 sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /www/cgi-bin/next.cgi
 sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /www/cgi-bin/previous.cgi
 sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /www/cgi-bin/goto.cgi
 sed -i 's/gst-launch-1.0/gst-launch-0.10/g' /etc/rc.local
fi

echo -en "\e[1;95mDone! \e[0;37m"
echo -n "You can now access the web interface of the radio at "
echo -e "\e[1;95mhttp://<ipofthisbox>/radio.html\e[0;37m"
if `cat /etc/banner | grep -q BARRIER`; then
 echo "A reboot is needed for the audio hardware to work (Barrier Breaker)."
fi

Have fun :)

Easy Extroot version 2 (Barrier Breaker) for Hame MPR-A1 clones

Version 2 of Easy Extroot (Barrier Breaker) for Hame MPR-A1 clones is here. It is supposed to be more user friendly and also solves some bugs.

By default, it also includes the installer for Yet Another Web Radio (/etc/init.d/radio), so in a few minutes you can have the smallest web radio. I was surprised that, even with an unpowered USB hub, it performs very well.

radio3

This is an extroot-centric firmware image, so you can start whatever you want with this cheap and capable enough router.

Just copy the image to the router in /tmp, write it with mtd -r write /tmp/extroot-MPRA1-BB_v2-openwrt-ramips-rt305x-mpr-a1-squashfs-sysupgrade.bin then, after reboot, run /etc/init.d/extroot.

Make sure you have an address in the class 172.20.2.100/16 (e.g. you can have on your PC 172.20.2.101, the MPR-A1 router will be 172.20.2.100).

Enjoy!

Easy ExtRoot for TP-Link MR3020 router – ChaosCalmer version

Easy ExtRoot is now available also for ChaosCalmer. See here the BarrierBreaker version.

This version includes some of the improvements requested by users.

Also, because files included by default in the ChaosCalmer distribution are larger than BarrierBreaker’s equivalents, some “artifacts” are needed (some packages have to be removed, then installed after ExtRoot is functional).

You will need a dedicated USB memory stick! Go buy one (or search in that pile of old ones)!

Changes in this version (just for you to decide):

  • Aside from the mandatory ext4 partition, a FAT32 partition is created, which can be used directly in a PC with Windows OS to transfer files, which will be available in the browser (feature requested by users – well, at least one)
  • Web interface for installing all needed packages, browsing files on the FAT32 partition and connecting to the Internet. This interface acts like an installer for the needed packages and also deals with connecting the box to the Internet wirelessly. Of course, you can do it manually if you want full control over the process
  • Internet access via router’s WAN connection for the wireless clients connecting the Extroot access point (i.e. router does routing and NAT for wireless clients)

Step-by-step instructions

In brief, we will write a new openwrt firmware to the router, then run the extroot script to partition the USB drive and prepare the extroot file system (this is the standard Easy ExtRoot procedure). After we have a functional extroot filesystem, we will connect to the Internet and install all the extra packages we need from the web interface. Pretty simple!

  1. Read the disclaimer. Some routers and/or USB memory sticks may be hurt in the process. Note that all the steps assume that your USB memory stick is dedicated for this project – i.e. ALL THE PARTITIONS (and all the data inside them) ARE DESTROYED in the process and then recreated.
  2. Download the .bin image from the GitHub
  3. Write the image to the router without connecting the USB memory stick (yet)
  4. Connect to the router after reboot (root password is d0c55555). Note that your PC should have an IP address in the class 172.20.2.0/24, except 172.20.2.100 (e.g., add 172.20.2.101 to the list of IP addresses on your wired network card)

initial

5. Connect the memory stick. Again, USE A DEDICATED USB memory stick – YOU WILL LOSE ALL THE DATA IN IT, guaranteed. After connecting it, check that the router sees it (optional step)

ls

6. Launch the script  /etc/init.d/extroot. Ignore the (red) errors generated by fdisk. If everything went well, the script should finish like this:

done

7. Reboot. Wait patiently until you can connect to the router again:

ext_chck

8. The fist step is done – you have a fully functional extroot filesystem! Congratulations! 🙂

9. If you prefer to do it manually, go here. Otherwise, stick with me some more.

10. From the computer (connected to the router with the wired network interface) open a browser and connect to http://172.20.2.100

index311. Connect to the Internet from the Wireless connection Manager by selecting the wireless network you want to connect to. The first time you attempt to access this page (or any page requiring a cgi script) you are asked about credentials. Default credentials are: admin/adm1n

not_connconn_mgr2

12. Go back to the homepage and then check the dependencies. This steps checks if some packages are installed: firewall, dnsmasq, dosfsck, uhttpd-mod-tls, px5g and installs them if needed. Note that the box should be connected to the Internet in order to be able to install the packages. After about 30seconds it should end successfully.

pkg_not_instcongrats

Thats about it. At this point you should have:

  • router connected to the Internet
  • fully functional Extroot file system
  • SSID Extroot visible to wireless clients (default password is  ‘secretkey’). Wireless clients have Internet access.
  • Clients are also able to browse files on the FAT32 partition from the browser. I use an icon to access the files easily from the smartphone (see below). You can copy files directly from the computer to the USB memory (partition is seen by Windows)

iconfiles2

Manual configuration

If you want to do it manually (without the web interface), here’s what you need to do:

  • after rebooting and checking that extroot file system is in place, you should connect to the Internet by modifying your config files in /etc/config/wireless and /etc/config/network
  • install the following packages: firewall, dnsmasq, dosfsck, uhttpd-mod-tls, px5g – opkg update; opkg install firewall dnsmasq dosfsck uhttpd-mod-tls px5g

That’s it! Good luck!

New toy!

I have a new addition to my pile of Openwrt compatible routers: a Hame MPR-A1 clone!

I bought mine from here. For less than 9$ it is really a bargain (cheaper router ever), so I’m planning to buy another couple of them, just in case (I hope my wife doesn’t read this page).

Mine has 4MB of flash and 32MB of RAM. Be aware that there are other clones based on RT5350 chipset from Ralink. Depending on your luck, you could find clones with 8MB of flash (better than mine) or with 16MB of RAM (worse, but still Openwrt compatible). However, keep in mind that the wireless signal is really weak!

Hame MPR-A1 clone (with a USB memory stick inserted for extroot):

photo 1

The back of the router:

photo 2

Some useful links:

http://wiki.openwrt.org/toh/hame/mpr-a1

https://github.com/JiapengLi/OpenWrt-RT5350

https://github.com/Squonk42/OpenWrt-RT5350?source=cc

http://downloads.openwrt.org/snapshots/trunk/ramips/generic/openwrt-ramips-rt305x-mpr-a1-squashfs-sysupgrade.bin

To flash Openwrt, I used JiapengLi’s very good tutorial at Github. For some unknown reason, the “universal” method (tftp32) did not work for me, but the method using the Chinese executable (which basically has the tftp server included) worked. You might have to temporarily disable firewall for this to work (keep the antivirus active at all times, though).

You will have to change the IP address of your network card to 192.168.1.55 and start a capture of network traffic for finding out what is the name of the firmware file the router asks for to the tftp server (in my case it was different than the name in the tutorial). Rename the firmware file downloaded from Openwrt site to that name, without extension (in my case it was 021200011946, see below).

wireshark

My plans are to generate images for some of my projects for this router, too. Of course, this router would be the most useful with DocServer, Extroot and as a meshnode for SWISS.

Wireless capabilities of RT5350F wireless driver are:

root@ExtRoot:~# iw phy
Wiphy phy0
max # scan SSIDs: 4
max scan IEs length: 2257 bytes
Retry short limit: 7
Retry long limit: 4
Coverage class: 0 (up to 0m)
Available Antennas: TX 0 RX 0
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
Band 1:
Capabilities: 0x172
HT20/HT40
Static SM Power Save
RX Greenfield
RX HT20 SGI
RX HT40 SGI
RX STBC 1-stream
Max AMSDU length: 3839 bytes
No DSSS/CCK HT40
Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
Minimum RX AMPDU time spacing: 2 usec (0x04)
HT RX MCS rate indexes supported: 0-7, 32
TX unequal modulation not supported
HT TX Max spatial streams: 1
HT TX MCS rate indexes supported may differ
Frequencies:
* 2412 MHz [1] (20.0 dBm)
* 2417 MHz [2] (20.0 dBm)
* 2422 MHz [3] (20.0 dBm)
* 2427 MHz [4] (20.0 dBm)
* 2432 MHz [5] (20.0 dBm)
* 2437 MHz [6] (20.0 dBm)
* 2442 MHz [7] (20.0 dBm)
* 2447 MHz [8] (20.0 dBm)
* 2452 MHz [9] (20.0 dBm)
* 2457 MHz [10] (20.0 dBm)
* 2462 MHz [11] (20.0 dBm)
* 2467 MHz [12] (20.0 dBm) (no IR)
* 2472 MHz [13] (20.0 dBm) (no IR)
* 2484 MHz [14] (20.0 dBm) (no IR)
valid interface combinations:
* #{ managed, AP, mesh point } <= 8,
total <= 8, #channels <= 1
HT Capability overrides:
* MCS: ff ff ff ff ff ff ff ff ff ff
* maximum A-MSDU length
* supported channel width
* short GI for 40 MHz
* max A-MPDU length exponent
* min MPDU start spacing
root@ExtRoot:~#

Have fun!

Disclaimer

Although files and firmware images provided are tested, I cannot guarantee that all files and information from this blog are 100% accurate.

Improperly executed firmware upgrade or faulty firmware images can render your router useless. Use it at your own risk! I cannot be held responsible for damages you may do to your devices by following information or using files from this blog.

Note that changing the default firmware may void your device’s warranty. However, in most cases default firmware can be restored to the device.

On the bright side, please note that there are ways to fix a broken (bricked) device due to writing improper firmware to the device. Many times, routers were bricked and revived in the process of building these projects.