Friday, January 23, 2015
Part II.b. Some technical hints regarding the hardware (cont.)As I said, for sending remote control codes from Arduino to router I used the serial transmission via USB.
In order to do that I use another Arduino Pro Mini (I have a 5V one) with a FTDI basic breakout board (I have a 3,3V one).
- Fortunately the pair FTDI 3,3V - Arduino Pro Mini 5V works flawlessly.
|FTDI board 3,3V||Arduino Pro Mini 5V|
|And voila' the lovely pair|
- Note:You may load also the sketch from computer into Arduino Pro Mini 5V with the 3,3V FTDI BASIC breakout board. I notice also that the 5V version of Arduino Pro Mini is cheaper than the 3.3 V version.
- Now follows one of the most delicate part of our project: to fix an external antenna (pigtail) to our little MR 3020 router. You need that because when you put the cover on the SSR case you lose the WiFi signal. Another way could be to cut the lid of the SSR case and to insert the router from above.
- Attaching a pigtail to 3020 router is described here: How to connect a pitgail to a MR 3020 router
I've sacrificed an old MSI router with an external antenna. To open the case of the MR 3020 router is relatively easy. See the instructions here:Opening the case of a MR 3020 router.
- My final result could be observed in the pictures below. You could also notice in the left side of the antenna the speaker's potentiometer.
Thursday, January 22, 2015
Part III - THE SOFTWARE
- Briefly the main steps to be followed are:
- Install OpenWrt
- Configure the network settings
- Extend the router memory by configuring an USB pendrive (even 4 GB pendrive is OK)
- Install serial communication drivers
- Install sound related drivers/applications. I use madplay, because is frugal, i.e. consume few resources.
- Put in place the custom made application
- Test the result, using the web interface
- Note: All the needed software is provided in this blog
- The steps 1,2 and 4 are fully described in my youtube tutorial, but there are also other places on the internet to find it described.
Those steps are enough to have a cheap WiFi radio and, as a bonus, a WiFi signal extender.
- So, in order to install OpenWrt you need the image to be flashed. You may download one from here
- On your computer, in Terminal or Putty type: telnet 192.168.1.1. Will be appear to you the OpenWrt screen: .
Then type passwd and put a password. Type exit to close the telnet connection. Now you may be able to connect with your beloved router with SSH. On your PC terminal type ssh firstname.lastname@example.org and lo and behold, you're connected via SSH.
- There are 3 files in OpenWrt that must be replaced or modified: /etc/config/network (do not forget to note the MAC Address prior to replace it), /etc/config/wireless and /etc/config/firewall.
- First of all you must prepare an USB pendisk by having on it 3 partitions: one EXT4 (1-2GB for the operating system), one FAT (for streaming radio station) and one Linux SWAP (approx: 100 MB). There are a bunch of tutorials on how to do that.
- Power off the router, put the USB pendrive in it, put also the USB sound card and power on the router(use the USB hub to connect all the stuff).
- On the router prompt type the following commands: opkg update, opkg install kmod-usb-storage, opkg install kmod-fs-ext4 block-mount, opkg install fdisk. Then type fdisk -l to see the EXT4 partition name. Could be sda1, or sda3.
- Now type: mkdir -p /mnt/sda1 or sda3 (see the previous command fdisk -l output.
mount /dev/sda1 /mnt/sda1, then type mkdir -p /tmp/cproot, mount --bind / /tmp/cproot
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda1 -xf -, umount /tmp/cproot, umount /mnt/sda1
Now edit the fstab file, as follows: vi /etc/config/fstab and modify it as is shown in the picture below:
- Save and exit the fstab file (ESC wq) and type reboot in order to reboot your little router.
When the router is back to business log in with SSH and type df command. You must see something like that:
Incidentally you may encounter an error that contained the following: whole_root-disabled. If it happened, type: cp /.extroot.md5sum /tmp/whole_root-disabled/etc/extroot.md5sum.
- As you maybe seen from the last picture, I have also a partition named "USB". It is the FAT partition that I've made for the streaming files.
To make one, type: opkg update, opkg install kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1
mkdir -p /mnt/usb, mount -t vfat /dev/sda1 /mnt/usb. Basically I've created a folder in /mnt/usb where will be stored the streaming files.
- Few considerations about serial communication: We need the serial communication for connecting Arduino to USB.
From my experience, OpenWrt see an Arduino UNO as /ttyACM0 and Arduino Pro Mini, connected through FTDI BASIC outbreak board as /ttyUSB0.
Pay attention then, when you test your Arduino-router communication, to rename the commands you give accordingly (i.e. ttyACM0, or ttyUSB0).
- Now, there are three types of TTL to USB devices, FDTI BASIC outbreak board been one of them; another one is a cheap and bulky one based on PL2303 chip and the third one is a little more expensive, but smaller one, based on CP2102 chip.
You must verify of what type is yours, in order to know what applications must be installed on OpenWrt.
- Now, you need to type: opkg update, opkg install kmod-usb-acm needed when you test the application with your Arduino UNO
- opkg install kmod-usb-serial-ftdi
- opkg install kmod-usb-serial-pl2303
- opkg install kmod-usb-serial-cp210x
And now, depending your USB to serial breakout board (FTDI BASIC, PL2303 or CP2102), you'll install one of the following:
You may need even opkg install coreutils-stty.
It is helpful to change the baud rate, but I've noticed that ttyACM0 and ttyUSB0 are working on 9600 bps. Anyway, if you need to change the baud rate, just type: stty -F /dev/ttyACM0 9600 clocal cread cs8 -cstopb -parenb . The command is self explanatory.
Now, to test the communication between Arduino and router, link the two devices via USB cable, upload a simple sketch into Arduino and
catch the message on router side.
I've made a simple sketch based on SoftwareSerialExample
Now, on router type: cat /dev/ttyACM0 or cat /dev/ttyUSB0, depending on your board (Arduino UNO, or Pro Mini).
If the message appear, you're on track. Well done!
Remember, you need only one way communication through serial: from Arduino to MR3020 router, in order to transmit IR codes from remote control. NoteThere are also a serial connection on router main board; it is the UART connection ttyATH0. See the picture below. But in order to access that serial console you need to rebuild the flash image for OpenWrt. That's beyond the goal of my tutorial.
Wednesday, January 21, 2015
Part III - THE SOFTWARE - cont
Now, as I said, we'll use madplay for playing audio streaming from radio stations, because is less resource consumming than mpd.
On my initial stages I've installed mpd & mpc, but I give up. The sound was horrible (because it forced the limits of the router I guess). I spent almost half a day at the time, but of no use.
It was easier for me to make a web interface for madplay than to configure mpd to act properly on my router.
- opkg update
- opkg install kmod-usb-audio
- opkg install madplay
- opkg install streamripper
- opkg install wget
For the recording feature, I've installed streamripper application, a very good one.
The commands are:
- Power off the router, connect the USB sound card to the speakers, power on the router and test madplay.
wget -O - http://126.96.36.199:9010/ | madplay -
Pay attention that is wget -O, not wget -0 (zero)
Now you must be able to hear the sound of music in your speakers.
- To obtain the best results of our WiFi Radio, we need some custom made applications
- opkg update
- opkg install php5
- opkg install curl
- opkg install php5-mod-curl
- opkg install php5-fastcgi
- opkg install php5-mod-json
There are some on the router side and a couple of others one the Arduino side, as follows:
|ON THE ROUTER SIDE|
|Name of the application||Path||Description|
|a.The web interface files|
|play.cgi||/www/cgi-bin/nmsradio/||the main web interface for controlling our WIFi radio. A short presentation could be seen on youtube|
|changechannel.sh||/www/cgi-bin/nmsradio/||changing the radio stations through the command received from play.cgi|
|alarm.cgi||/www/cgi-bin/nmsradio/||web interface for setting the alarms|
|setalarm.sh||/www/cgi-bin/nmsradio/||setting the alarms according to the parameters received from alarm.cgi|
|record.sh||/www/cgi-bin/nmsradio/||stream the content of the current playing radio station on a location on USB disk|
|b.The Arduino interface files|
|interfata.sh||/www/cgi-bin/nmsradio/||It's similar to play.cgi, only it interpret the IR codes received from Arduino|
|radioIR||/etc/init.d/||Start at boot the interfata.sh file|
|ceasArduino.sh||/root/scripts/||Send to Arduino, via Ethernet, the current time (it runs in crontab every minute)|
|metals.php||/www/php/||Send the silver quotation to Arduino. It's called from interfata.sh when a dedicated remote control button is pressed|
|valuta.php and cursValutar.php||/www/php/||Send some currency quotation from Romanian National Bank to Arduino. It's called from interfata.sh when dedicated remote control buttons are pressed|
|c.The common files|
|radio||/etc/config/||Store the variables used by applications (ex. current station, current volume, etc.)|
|posturi||/etc/config/||Store the radio station list. It could be modified in order to put or delete stations.|
Note:All the files with the .cgi or .sh extensions must be executables. In order to do that you must type:chmod +x /pathToFile/filename.ext. Where filename.ext is the name of the file (ex. play.cgi). Also radioIR file must be executable.
If you want to use php files you need to install php to your router:
- Depend on your remote control, the codes may vary. Modify it accordingly.
- The IP address of my router is 192.168.0.67
- The IP address of Arduino Pro Mini is 192.168.0.15
|ON THE ARDUINO SIDE|
|Name of the application||Description|
|a.Arduino Pro Mini with ENC28J60 Ethernet Module|
|EthernetReceiveData.ino||Display on the 4 digits 7 elements LED the 4 numbers received from router|
|b.Arduino Pro Mini with USB to serial breakout board|
|IRSendingCodes.ino||Send to the router the remote control codes when a button is pressed|
For your convenience, you may download all the files from HERE
Part IV - PUT EVERYTHING IN PLACE
- We've arrived at the finish line, i.e. to put everything together in the donor case of Salvaged Satellite Receiver (SSR).
The steps are:
Briefly, our inventory consist of:
- Salvaged Satellite Receiver
- Power supply of the SSR
- Front panel of the SSR
- MR3020 router with external antenna
- Arduino Pro Mini + ENC28J60 Ethernet Module+ Ethernet cable (the one provided with the router)
- Arduino Pro Mini + USB to serial breakout board
- USB hub with enough ports for all the stuff
- USB pendrive of minimum 4 GB
- Salvaged remote control
- USB powered speakers
- USB cables
My setup is presented in the picture below:
I know, it look a little messy, but forgive me, that's my first prototype. Maybe the second will be a good looking one.
The final result instead look very stylish ( I think).
- The youtube video clip that I made show the final tests.
ENJOY YOUR STATE-OF-THE-ART WIFI RADIO !.