MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Problems with WLAN connectivity - solved

    Scheduled Pinned Locked Moved General Discussion
    8 Posts 3 Posters 1.5k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rkorell @sdetweil
      last edited by

      @sdetweil :-)
      Thanks.

      In addition: If somebody is interested in the scripts and system-services definitions for own purposes - give me a ping and I will share this for sure…

      Regards,
      Ralf

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        schlomm @rkorell
        last edited by

        @rkorell Thanks for your Insights! Interesting!
        One question: How you got the idea that the issue is caused by power/energy circumstances?
        Are there any specific logs with those information?

        And yes - it would be great to get an idea of your scripts :)

        R 1 Reply Last reply Reply Quote 0
        • R Offline
          rkorell @schlomm
          last edited by

          Dear @schlomm ,
          I initially had no clue at all regarding root cause :-)
          And the finding “undervoltage” was never expected but came out off my logfiles.

          After a LOT of tinkering and playing with syptomatic “solutions” system kept to be unstable so I decided to dig in and do some logging to identify root cause.

          For this I wrote a shellscript and installed a system service which collects this data every five minutes.

          shellscript:

          sudo nano /usr/local/bin/wlan-diagnose.sh
          

          content:

          #!/bin/bash
          LOGFILE="/var/log/wlan-diagnose.log"
          DATE=$(date '+%a %d %b %H:%M:%S %Z %Y')
          WLAN_IF="wlan0"
          
          echo "===== $DATE =====" >> $LOGFILE
          
          # IP-Adresse
          echo "--- IP-Adresse ---" >> $LOGFILE
          ip addr show $WLAN_IF >> $LOGFILE 2>&1
          
          # Link-Status
          echo "--- Link Status ---" >> $LOGFILE
          iw dev $WLAN_IF link >> $LOGFILE 2>&1
          
          # Default Route
          echo "--- Routing ---" >> $LOGFILE
          ip route >> $LOGFILE 2>&1
          
          # Wpa_supplicant Status
          echo "--- wpa_supplicant ---" >> $LOGFILE
          systemctl status wpa_supplicant --no-pager >> $LOGFILE 2>&1
          
          # Letzte wpa_supplicant Logs
          echo "--- wpa_supplicant journal (letzte 20 Zeilen) ---" >> $LOGFILE
          journalctl -u wpa_supplicant -n 20 --no-pager >> $LOGFILE 2>&1
          
          # Kernel/Treiber Logs
          echo "--- dmesg wlan0 ---" >> $LOGFILE
          dmesg | tail -n 20 >> $LOGFILE 2>&1
          
          # Ping-Test
          PING_TARGET="8.8.8.8"
          ping -I $WLAN_IF -c3 -W3 $PING_TARGET >> $LOGFILE 2>&1
          
          echo "" >> $LOGFILE
          
          

          set as executable:

          sudo chmod +x /usr/local/bin/wlan-diagnose.sh
          
          

          systemd-timer for this diagnosis script:

          sudo nano /etc/systemd/system/wlan-diagnose.timer
          

          content:

          [Unit]
          Description=WLAN Diagnose alle 5 Minuten
          
          [Timer]
          OnBootSec=1min
          OnUnitActiveSec=5min
          Persistent=true
          
          [Install]
          WantedBy=timers.target
          
          

          service file:

          sudo nano /etc/systemd/system/wlan-diagnose.service
          

          content:

          [Unit]
          Description=WLAN Diagnose Service
          
          [Service]
          Type=oneshot
          ExecStart=/usr/local/bin/wlan-diagnose.sh
          
          

          activate the service:

          sudo systemctl daemon-reload
          sudo systemctl enable --now wlan-diagnose.timer
          
          

          Created logfile: /var/log/wlan-diagnose.log

          possible command for filtering for errors:

          grep -i "fail\|error\|disconnect" /var/log/wlan-diagnose.log
          
          

          in my personal case directly after starting the service the undervoltage warnings appeared in the logfile:

          Sep 24 19:23:02 MagicMirrorPi5 wpa_supplicant[702]: wlan0: CTRL-EVENT-CONNECTED - Connection to f8:bc:0e:51:50:48 completed [id=0 id_str=] Sep 24 19:23:02 MagicMirrorPi5 wpa_supplicant[702]: bgscan simple: Failed to enable signal strength monitoring --- dmesg wlan0 --- [ 385.672898] hwmon hwmon4: Voltage normalised [ 399.780700] hwmon hwmon4: Undervoltage detected! [ 401.796721] hwmon hwmon4: Voltage normalised [ 403.812728] hwmon hwmon4: Undervoltage detected! [ 405.831888] hwmon hwmon4: Voltage normalised [ 425.988994] hwmon hwmon4: Undervoltage detected! [ 428.008109] hwmon hwmon4: Voltage normalised [ 434.052979] hwmon hwmon4: Undervoltage detected! [ 438.087587] hwmon hwmon4: Voltage normalised [ 442.117090] hwmon hwmon4: Undervoltage detected! [ 444.133104] hwmon hwmon4: Voltage normalised [ 452.198182] hwmon hwmon4: Undervoltage detected! [ 454.213171] hwmon hwmon4: Voltage normalised [ 470.341318] hwmon hwmon4: Undervoltage detected! [ 478.405369] hwmon hwmon4: Voltage normalised [ 488.485467] hwmon hwmon4: Undervoltage detected! [ 490.505469] hwmon hwmon4: Voltage normalised [ 514.693689] hwmon hwmon4: Undervoltage detected! [ 516.709733] hwmon hwmon4: Voltage normalised [ 520.744884] hwmon hwmon4: Undervoltage detected! PING 8.8.8.8 (8.8.8.8) from 172.23.56.157 wlan0: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=13.2 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=33.6 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=116 time=27.5 ms --- 8.8.8.8 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 13.220/24.756/33.576/8.529 ms
          

          So I had identified my root cause with first strike.

          In the meantime (today) I had severe additional problems (also “identified” by this mentioned log) - but this was a kernel/device driver problem which I cannot solve today.
          But this leads to a modified recovery script because the version from yesterday only tried to restart the WPA_Supplicant which was not sufficient for my problem today.

          If you are interested in, this is the recovery script:

          #!/bin/bash
          # wlan-recovery.sh
          # Prüft WLAN-Verbindung und startet wpa_supplicant / Interface bei Ausfall neu
          
          LOGFILE="/var/log/wlan-recovery.log"
          WLAN_IF="wlan0"
          PING_TARGET="8.8.8.8"
          DATE=$(date '+%a %d %b %H:%M:%S %Z %Y')
          
          # 1. Power save prüfen & ggf. deaktivieren
          PS=$(iw dev $WLAN_IF get power_save)
          if [ "$PS" = "Power save: on" ]; then
              echo "$DATE: Power Save ist ON → deaktiviere" >> $LOGFILE
              iw dev $WLAN_IF set power_save off
          fi
          
          # 2. Verbindung prüfen
          ping -I $WLAN_IF -c1 -W3 $PING_TARGET > /dev/null 2>&1
          if [ $? -ne 0 ]; then
              echo "$DATE: Keine Verbindung. Versuche wpa_supplicant restart..." >> $LOGFILE
              systemctl restart wpa_supplicant
              sleep 5
          
              ping -I $WLAN_IF -c1 -W3 $PING_TARGET > /dev/null 2>&1
              if [ $? -ne 0 ]; then
                  echo "$DATE: Verbindung immer noch nicht da. Interface + Treiber toggle..." >> $LOGFILE
                  
                  # Interface herunterfahren
                  ip link set $WLAN_IF down
                  sleep 2
                  
                  # Treiber neu laden
                  modprobe -r brcmfmac
                  sleep 2
                  modprobe brcmfmac
                  sleep 2
          
                  # Interface wieder hochfahren
                  ip link set $WLAN_IF up
                  sleep 5
          
                  ping -I $WLAN_IF -c1 -W3 $PING_TARGET > /dev/null 2>&1
                  if [ $? -ne 0 ]; then
                      echo "$DATE: Wiederherstellung fehlgeschlagen." >> $LOGFILE
                  else
                      echo "$DATE: Verbindung wiederhergestellt nach Interface + Treiber reload." >> $LOGFILE
                  fi
              else
                  echo "$DATE: Verbindung wiederhergestellt nach wpa_supplicant restart." >> $LOGFILE
              fi
          else
              echo "$DATE: Verbindung ok." >> $LOGFILE
          fi
          

          Hope this helps you.
          Do not hesitate to ask for futher information …

          Warmest regards,
          Ralf

          R 1 Reply Last reply Reply Quote 1
          • R Offline
            rkorell @rkorell
            last edited by

            addition:
            the recovery script is: /usr/local/bin/wlan-recovery.sh

            set executable:

            sudo chmod +x /usr/local/bin/wlan-recovery.sh
            
            

            Systemd-Service

            sudo nano /etc/systemd/system/wlan-recovery.service
            

            content:

            [Unit]
            Description=WLAN Recovery Script
            After=network.target
            
            [Service]
            Type=oneshot
            ExecStart=/usr/local/bin/wlan-recovery.sh
            
            

            timer:

            sudo nano /etc/systemd/system/wlan-recovery.timer
            

            content:

            [Unit]
            Description=Run WLAN Recovery every 5 minutes
            
            [Timer]
            OnBootSec=1min
            OnUnitActiveSec=5min
            Persistent=true
            
            [Install]
            WantedBy=timers.target
            
            

            activate this service:

            sudo systemctl daemon-reload
            sudo systemctl enable --now wlan-recovery.timer
            
            

            logfile: /var/log/wlan-recovery.log

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              schlomm @rkorell
              last edited by

              @rkorell Thanks for all these detailed Information! I’ll setup your scripts on my MagicMirror Instances - I have 6 different ones to manage and at least one has some weird problems - maybe also relating to power issues.

              Thanks und Vielen Dank :)

              R 1 Reply Last reply Reply Quote 1
              • R Offline
                rkorell @schlomm
                last edited by

                @schlomm Sehr gern und VIEL ERFOLG!

                • melde Dich, wenn Du noch was benötigst.
                  Ralf
                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy