Welcome, Guest
Username: Password: Remember me
NOTE: This is a "Community" forum. Please be mindful that community members are here to help as part of a community effort. We therefore appreciate your effort in keeping this forum a happy place!

If you have a specific issue (e.g. hardware, failure) and want help from our support team, please use our tech support portal (Support menu - > Contact Us).
Thanks a lot of your help in making a better community.
  • Page:
  • 1

TOPIC:

SHD script to stabilize USB WiFi 5 months 3 weeks ago #55291

  • Nervoservo
  • Nervoservo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 1
Hi all,
Several SHD owners (like me) are trying to use WiFi dongle with SHD but are experiencing stability issues. Sometimes it won't connect, while others it will drop the connection. Here is a workaround that helps SHD to establish and maintain a stable WiFi connection.
First of all, I would like to make clear that I do not have any kind of responsibility for any kind of potential damage/instability/warranty loss etc, that this guide could cause on your system. Please also be aware that this could harm your official warranty. Do everything on your own responsibility.
Further, please do not ask me for SSH credentials; I will not provide them!

What we will need:
  1. SSH credentials for your SHD and a SSH client utility (e.g. putty)
  2. Network access to the webpage of the volumio
  3. USB dongle connected to SHD
It is highly recommended that the SHD will be connected through Ethernet cable to your router while you are performing the below steps.

What this workaround is actually doing?
It prevents SHD to create a WiFi hotspot; that way we are "forcing" it to connect to the WiFi network without fallback options.
Then the script we 'll create will constantly check (on a 60 sec basis) if SHD has assignef an IP address on its Wireless interface . As soon as it detects that no IP is assigned (which might mean loss of Wifi Connection) it will restart the wireless interface to trigger it to connect on the WiFi network and it will recheck for IP assignment. If it does not find IP, it will restart again and again and so on, till it gets IP. Then, will switch to its routine , checking its wifi IP address assignment on a 60 sec basis.
Sometimes SHD would not be able to connect at all until it is rebooted. So after 10 minutes of connection attempts with no success it will reboot itself and retry.
This is not that efficient , but it is the only that worked for me with 100% success after several workarounds and approaches I tried. Any suggestions/improvements are welcome.

The workaround:
  1. Go to your SHD webpage-->Settings. Leave Wired Network to On, Wireless Networking to On, Automatic IP to On. Set Enable Hotspot to Off.
  2. Through the same page connect to your Wifi Network.
  3. Enable SSH on SHD: http://SHDlocalIPaddress/dev/
  4. Login to SHD via SSH
  5. Create a file named wifi.sh into /usr/bin directory:
    sudo nano /usr/bin/wifi.sh
  6. Into the text editor that is just opened paste the below code:
    #!/bin/bash
    while true ; do
            if ifconfig wlan0 | grep -q "inet addr:192" ; then    #Modify 192 accordingly, as per your local network configuration
                    now=$( date '+%F_%H:%M:%S' )
                    #echo "checkwifi script. Wifi connection was FINE at: $now . Sleeping for 60 seconds" >> /usr/local/bin/cronlog.txt 2>&1
                    sleep 60            #  WiFi connectivity check interval in seconds - adapt to your needs
            else
                    not_before=600            # Number of seconds without wifi connection before rebooting SHD - adapt to your needs
                    uptime=$(cut -d . -f 1 /proc/uptime)
                    if [[ "$uptime" -ge "$not_before" ]] ; then
                            sudo reboot -f
                    else
                            now=$( date '+%F_%H:%M:%S' )
                            echo "checkwifi script. no wifi connection, reconnect at: $now" >> /usr/local/bin/cronlog.txt 2>&1
                            sudo systemctl restart wireless
                            sleep 10
                    fi
            fi
    done
  7. On third line "if ifconfig wlan0 | grep -q "inet addr:192" ; then " 192 represents the first IP octet of the local network range. It will work only for networks that belong to that IP range 192.x.x.x . If you are using different IP range (e.g 172.16.0.x or 10.x.x.x), simply replace it (e.g. with 172 or 10).
  8. Press Ctrl+X and then Y and Enter
  9. Provide execute permissions to the script you just created:
    sudo chmod +x /usr/bin/wifi.sh
  10. Create a new file wificheck.service into /lib/systemd/system/ . This will be the module that will load up and execute the script:
    sudo nano /lib/systemd/system/wificheck.service
  11. Paste the below code into the file you created:
    [Unit]
    Description=wifirestart
    After=network.target
    After=local-fs-pre.target
    
    [Service]
    Type=oneshot
    User=root
    ExecStart=/bin/bash /usr/bin/wifi.sh
    
    [Install]
    WantedBy=multi-user.target
  12. Press Ctrl+X and then Y and Enter
  13. Start the module you just created and enjoy:
    sudo systemctl enable wificheck.service

Remember that if for any reason in the future you connect your SHD through Ethernet cable and remove/disable the USB WiFi dongle, you need also to disable the above script, otherwise it will reboot SHD every 10 minutes:
sudo systemctl disable wificheck.service
Above command should be also used if you want for any reason to stop/disable the above workaround & script, so it can be considered as a quick "rollback" in case that anything goes wrong.

Please Log in or Create an account to join the conversation.

Last edit: by Nervoservo.

SHD script to stabilize USB WiFi 5 months 2 weeks ago #55298

  • notman
  • notman's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 67
  • Thank you received: 30
Impressive. Not trying to knock this effort at all, but what is the convincing argument to use this script versus just using a cheap wifi extender like a TP-Link RE220 and then run an ethernet cable from there? To me the arguments for that method are stability, range, 2.4+5ghz support, being able to set the antenna a good distance away from the audio components, and freeing up the USB host port. The downside is the obvious extra $26 USD.

Please Log in or Create an account to join the conversation.

SHD script to stabilize USB WiFi 5 months 2 weeks ago #55300

  • Nervoservo
  • Nervoservo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 1
In fact it's much more quicker and almost zero effort than it seems to be from my long post! Average time ~3-4 minutes :)
As for the use of a repeater/client access point instead of USB dongle, both two solutions have advantages and disadvantages , so at the end it depends on each user's and what he prefers.
From my point of view, USB dongle is a more "handy" solution as it does not need that space and most important (to me) it does not need an extra power socket.
But of course it has major disadvantages over the repeater solution, such as the already mentioned 5GHz (not) support, or the stability.
The following user(s) said Thank You: notman

Please Log in or Create an account to join the conversation.

Last edit: by Nervoservo.

SHD script to stabilize USB WiFi 5 months 2 weeks ago #55301

  • notman
  • notman's Avatar
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 67
  • Thank you received: 30
All good points, and kudos.
The following user(s) said Thank You: Nervoservo

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: devteam