Hi,
I've been digging a lot in the forum, and I found in the newer RecalBox version there will be support for more than one Wi-Fi interface in the configuration menu, but in the current version (4.1) there is only support to configure only one. I have another 5GHz Wi-Fi device, with support in RecalBox, but I was not able to find a way to configure it, actually, booting RecalBox with the external attached interface, I realized there was no posibility of making work the internal Raspi Pi 3 Model B Wi-Fi device (both external and internal Wi-Fi stopped working). Hence I started to investigate and finally I could make the devices work together for 2.4Ghz and 5Ghz networks. Here is how I made it.
Assumptions:
- You have a Raspi 3 Model B, or at least one with an internal Wi-Fi device.
- You have one external Wi-Fi device that supports 5GHz networks and it has support under RecalBox kernel modules (i.e: http://amzn.eu/59x1U1k).
- You have a 5Ghz network available to connect to.
- You want to connect your 5Ghz device to a 5Ghz network to have more bandwith for (i.e) watching movies with KODI or copy files to your RecalBox with more speed than the internal 100Mb Ethernet or 2GHz Wi-Fi device.
- You will be able to include the network name of your 5GHz network Network configuration Menu within RecalBox (Menu --> Network Configuration --> Wifi SSID).
- All the modifications, are hand made and most probably those could be better programmed than they are, but I can assure it works as it is.
- You have minimum Unix knowledge to connect over ssh and/or edit files (vi) inside RecalBox.
Well, let's start.
I recommend to connect over the Ethernet cable IP until you have tested that the modifications fit your needs and it works (for me at least it does).
In RecalBox, there is a script that handles all this stuff (wifi, networks, CPU speed, etc) which takes care about the Wi-Fi configuration stop/start, but it doesn't consider the idea (it will in the next Recalbox version) that you have more than one network interfaces (Raspi3 comes with an internal 2GHz network device). If you have another external device this script will break the Wi-Fi configuration as it looks up for wlan devices, but, as the system has two (the internal one and your external Wi-Fi device), it will run sed and join both device names (wlan0 and wlan1) and that will break the configuration as the resultant name (wlan01) doesn't exist in the system.
Doesn't matter how many times you will modify the wpa_supplicant.conf file, or the network configuration files, all are overwritten within this script each time it is called, hence I realized that the only way was modifying the script file from inside.
If you want to modify anything in this script, you will realize the file is in ReadOnly mode as well as many other /etc or system files. The first thing you must do is changing the RO option for the / folder.
To do so run as root:
mount -o remount,rw /
then, make a copy (always backup everything you want to modify!!) of the script you are going to modify (/recalbox/scripts/recalbox-config.sh) with:
cp /recalbox/scripts/recalbox-config.sh /recalbox/scripts/recalbox-config.sh.bkp
Then edit the script called /recalbox/scripts/recalbox-config.sh
and go to the line 318. It shows this line:
if [[ "$command" == "wifi" ]]; then
and perform the modifications as follows:
in the line 326, replace:
wlan="wlan`ifconfig -a | sed -n \"s/wlan\(.\).*/\1/p\"`"
with:
for i in `ifconfig -a |grep -i wlan| awk '{print $1}'`;
do
wlan=$i;
Then in the line 333, include the following:
(you can remove this line or comment it) instead of:
sed -i "s/wlan[0-9]\+/$wlan/g" /var/network/interfaces # directly modify the file and not the link because sed create a temporary file in the same directory
include:
if [[ ! `grep -i $wlan /var/network/interfaces` ]] ;then echo -e "\nauto $wlan\niface $wlan inet dhcp\nwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf\n" >> /var/network/interfaces ; fi
in the line 364, after:
/sbin/ifup $wlan >> $log
the script exists with
exit $?
so this if has been included to avoid the script exiting after trying to configure the first wlan device (that will fail as it cannot detect the 5GHz network), and also in case the Wlan0 is able to connect to a 2GHz network, to do not continue trying with wlan1 (it avoids double IP in the same network):
if [[ "$?" == "0" ]]; then
exit $?
fi
Note: remember closing the for bucle with done before the line 368 that looks like:
fi
if [[ "$command" == "hcitoolscan" ]]; then
so it should looks like:
done
fi
if [[ "$command" == "hcitoolscan" ]]; then
you can use this snip of the script and then replace from line 318 to line 368
if [[ "$command" == "wifi" ]]; then
if [[ ! -f "$wpafile" ]];then
echo "`logtime` : $wpafile do not exists" >> $log
exit 1
fi
ssid="$3"
psk="$4"
for i in `ifconfig -a |grep -i wlan| awk '{print $1}'`;
do
#wlan="wlan`ifconfig -a | sed -n \"s/wlan\(.\).*/\1/p\"`"
wlan=$i;
if [[ "$?" != "0" || "$wlan" == "wlan" ]] ;then
echo "`logtime` : no wlan interface found" >> $log
exit 1
else
echo "`logtime` : $wlan be used as wifi interface" >> $log
fi
#sed -i "s/wlan[0-9]\+/$wlan/g" /var/network/interfaces # directly modify the file and not the link because sed create a temporary file in the same directory
if [[ ! `grep -i $wlan /var/network/interfaces` ]] ;then echo -e "\nauto $wlan\niface $wlan inet dhcp\nwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf\n" >> /var/network/interfaces ; fi
if [[ "$mode" == "enable" ]]; then
echo "`logtime` : enabling wifi" >> $log
cat $wpafile | grep network >> $log
if [ "$?" != "0" ]; then
echo "`logtime` : creating network entry in $wpafile" >> $log
echo -e "network={\n\tssid=\"\"\n\tpsk=\"\"\n}" >> $wpafile
fi
sed -i "s/ssid=\".*\"/ssid=\"`echo $ssid | sed -e 's/[\/&]/\\\\&/g'`\"/g" $wpafile
sed -i "s/psk=\".*\"/psk=\"`echo $psk | sed -e 's/[\/&]/\\\\&/g'`\"/g" $wpafile
mode="forcestart"
fi
if [[ "$mode" == "disable" ]]; then
sed -i "s/ssid=\".*\"/ssid=\"\"/g" $wpafile
sed -i "s/psk=\".*\"/psk=\"\"/g" $wpafile
for i in `ifconfig -a |grep -i wlan| awk '{print $1}'`;
do
ifdown $i;
done
exit $?
fi
if [[ "$mode" =~ "start" ]]; then
if [[ "$mode" != "forcestart" ]]; then
settingsWlan="`$systemsetting -command load -key wifi.enabled`"
if [ "$settingsWlan" != "1" ];then
exit 1
fi
fi
echo "`logtime` : starting wifi" >> $log
killall wpa_supplicant >> $log
/sbin/ifdown $wlan >> $log
rb_wpa_supplicant "$wlan" &
waitWifi $wlan 20
/sbin/ifup $wlan >> $log
if [[ "$?" == "0" ]]; then
exit $?
fi
ifconfig $wlan | grep "inet addr" >> $log
fi
done
fi
you can test it with:
/bin/bash -x /recalbox/scripts/recalbox-config.sh wifi enable "your 5GHz SSID" "your psk password"
The menu in RecalBox will take bit longer (there is a 20 sleep inside it) as first it will try to connect over the wlan0 device (internal one) and then, it will try to login using the wlan1 (5Ghz device).
Remember to mount / as RO again.
mount -o remount,ro /
Note: It will show as not connected in recalbox menu however, you will see the IP address (I didn't have more time to investigate why it states not connected).