Enable/Disable WIFI with rfkill
@cyperghost I am already using your script for wifi, and I tried to modify it to work with bluetooth, but I could not make it work. You know how to write cripts, so you know wich instruction to sue to write on the config.txt with a script? For example, when I activate it via RetroPie menu, it would go and edit config.txt.
cyperghost last edited by
@Shaddonai This makes simply no sense. If I write to config.txt then only a reboot does enable/disable the internal WiFi or BT device of the Raspberry. So it makes more sense to disable them permanently and use external devices.
To make the script work for BT devices instead of using
sudo rfkill block wifijust write
sudo rfkill block bluetooth. It's just a small change in two lines and then it will work for BT but I do not know why you want this?
@cyperghost I am working on a portable Raspberry Pi, that will work as a Retropie and sort of portable computer with a portable keyboard. The thing is, I thought I could play with my friends , and most of them have PS4 controlers. I know that I can wire them to the RPI with an USB cable, but due to the design I made, It is really uncomfortable, so i thought to make them all use bluetooth. After a little research, I found out that onboard bluetooth is not really good handling many cotrollers, so I went to Amazon and search for a Bluetooth dongle. Then I saw several of them were "Low Energy". That intrigated me, so I searched the consumption of these dongles, and it was pretty heavy , reducing a good amount of battery life. I only planned to use the dongle with friend, in the meantime I would only use one bluetooth controller, so the onboard was OK, and less power consumpting. I woud like to write an script to only disable theonboard bluetooth when I need, and then plug the dongle, so I can maximize the battery life.
cyperghost last edited by cyperghost
@Shaddonai AFAIK if you disable the wifi with this script then you can connect several PS-controllers with BT and all is fine.
If you want to do some inline editing then please read about
sedcommands. This tools can automate write to your
/boot/config.txtbut I don't wont to do this for you. For some reasons I can easily break your device.
An example how this tools work are here. The
^is relevant it says search string from the beginning.
if grep -q "^enable_uart=1" "/boot/config.txt"; then echo "UART is already enabled. Disabeling now!" sed -i -e "s|^enable_uart=1|#enable_uart=1|" "/boot/config.txt" fi
Thanks man, you are awesome!
Only one more question. In your script you testes the WIFI with" if [ $WLANSTAT -lt 2 ]", how can I test Bluetooth instead?
cyperghost last edited by cyperghost
@Shaddonai The variable
WLANSTATis setted with values right herre. The script checks just how many
onare visible. So you should change L6 wifi with bluetooth. But I'm really asking me of the sense. If you disable the Bluetooth stack you do not have further inputs and in the worst case you need a keyboard or a SSH connection. So be aware what you are doing here.
@cyperghost Thanks for the advice. It is not a really necessary script, but i would love to do it, because this build took me a lot of time and I want to perfect it to the most.
rivendil last edited by
Thank you so much for this! I was struggling with two Shanwan ps3 controllers and disabling wifi with your script totally solved it.
Matches last edited by
I'm was having trouble with my ps3 controllers and discovered that removing my wifi connection eliminated it. I wanted to install this switch to make this process even easier. However, after installing it it says "Your wifi adapter seems to be blocked or is not available", even though I'm currently connected to wifi and am able to access my retropie over the network. I expected to see the block option, but it shows enable instead. Selecting enable says "sudo: rfkill: command not found" and spits me back to the retropie menu. Wondering if there's something I'm missing...