Getting FRITZ!Box upload/download rate nicely displayed in a KDE Plasma panel

It’s been a while that I’ve been setting up a private computer. For a long time I only had my old laptop, where I had not much motivation to tinker and optimize. Now that I have my new desktop computer (yay!), I’ve spent some time arranging the workspace / desktop. And of course I’m using KDE, as I have been for so many years.

The Plasma 5 system monitor is pretty cool, because it’s very configurable, and each of the graphs can be placed as Plasma widget on the desktop or in any panel. So I set up some nice graphs for SSD I/O, network throughput, CPU, memory, temperatures etc.. But then I thought: Can’t I also get some info from my Internet router, e.g. the current download rate of the whole house (as this PC is by far not the only device using the Internet connection). Or when it last reconnected, and what the external IP address is.

So I looked a bit into the TR-064 protocol and found a really nice Python module – fritzconnection by Klaus Bremer – to interface with my router (an AVM FRITZ!Box 5530 Fiber). It should also work with pretty much any other FRITZ!Box model, which is a very common Internet router throughout Germany. You can simply get it by running pip install fritzconnection.

So after a few minutes I was able to query the desired data from the router with very few lines of code, like so:

os.environ['FRITZ_USERNAME'] = 'user'
os.environ['FRITZ_PASSWORD'] = 'password'
fc = FritzStatus(address='fritz.box')
print('WAN Download: ' + fc.str_transmission_rate[1])

I found that querying it more than once every 5 seconds doesn’t make sense, because it doesn’t update the numbers more often than that. So a loop with a 5 second sleep it is.

But I also wanted to get the data into my nice panel, together with the CPU load etc… And by chance I stumbled over the Do It Yourself Bar – funny name, but it kind of fits: It’s a bar-shaped Plasma widget that you can populate via DBUS messages through any kind of script – typically Shell scripts but of course Python scripts work just as well.

So I modified my “text-only” Python script to send DBUS messages and hooked it into the DIY bar – and suddenly I have the data queried from the router in my KDE panel, with configurable colors and all!

Running a speed test – here you can see the local network adapter’s data and below the Do It Yourself Bar with the FRITZ!Box data (I highlighted it with a yellow frame in this screenshot).

Hovering over the “FRITZ!Box conn. up: …” label also shows the external IP address, and clicking on it would open the browser with the FRITZ!Box’s web interface.

Here is the current Python script and my Pull Request.

#!/usr/bin/python

# Prerequisites:
# - Have a FRITZ!Box Internet router that is reachable at the address http://fritz.box
# - Add a user + password to your FRITZ!Box (via the web interface)
# - Run `pip install fritzconnection` to get the handy Python module by Klaus Bremer
#   (see https://fritzconnection.readthedocs.io)

import os, sys, time
from fritzconnection.lib.fritzstatus import FritzStatus

os.environ['FRITZ_USERNAME'] = 'scriptuser'
os.environ['FRITZ_PASSWORD'] = 'the_password'

fc = None
while not fc:
    try:
        fc = FritzStatus(address='fritz.box')
    except:
        data = '| A | FRITZ!Box not reachable | Have you changed username and password in get-fritz-wan-stats.py? Is your network up? | |'
        os.system('/usr/bin/qdbus org.kde.plasma.doityourselfbar /id_' + sys.argv[1] + ' org.kde.plasma.doityourselfbar.pass \'' + data + '\'')
        pass
    time.sleep(5)

while fc:
    data = '| A | FRITZ!Box conn. up: ' + fc.str_uptime + ' | External IP: ' + fc.external_ip + ' | xdg-open http://fritz.box |'
    data += '| B | WAN Download: ' + fc.str_transmission_rate[1] + '/s | FRITZ!Box WAN Download | |'
    data += '| C | WAN Upload: ' + fc.str_transmission_rate[0] + '/s | FRITZ!Box WAN Upload | |'
    os.system('/usr/bin/qdbus org.kde.plasma.doityourselfbar /id_' + sys.argv[1] + ' org.kde.plasma.doityourselfbar.pass \'' + data + '\'')
    time.sleep(5)

Pretty neat. Thanks a lot to Klaus Bremer and the other fritzconnection authors and wsdfhjxc for making this possible!

Ubuntu 20.04 messes up file modification dates on exfat file systems

Somehow related to my previous post: As of currently – i.e. September 2020 – there is a weird bug in Ubuntu 20.04’s exfat support: When you mount an exfat file system (like the one on pretty much any MicroSD card that you would use in a GoPro), it will not only show all files as exactly one month into the future, but it will even change the modification date to that one month in the future. Thus, if you mount an exfat filesystem two times in a row, all files will have a modification date two months in the future. Very annoying.

Luckily there is an easy workaround: Instead of the built-in (kernel module?) exfat support, just install the packages ‘exfat-fuse’ and ‘exfat-utils’ (i.e. type sudo apt install exfat-fuse exfat-utils in the shell). Once you mount the MicroSD card again, it will be mounted using the fuse driver, which does not mess up the modification dates.

Those dates that have already been messed up though, need to be fixed. I’ve created a small script that can do that. Download it (here), chmod +x it and then run it with the file name(s) of the affected files as parameter(s). If the date has already been messed up to more than one month into the future, just run the script multiple times.

Script to merge GoPro videos on Linux / Mac OS X

I have recently acquired a GoPro Hero 7 Black. After the first more-than-a-few-seconds recording session, I found out that it splits the recording into multiple .MP4 files, each ~4 GB in size. After some quick research on the net I found out that this is called “chaptering”, and that it cannot be turned off. There were one-liners on how to merge these files with ffmpeg on Linux, for example in this article. I found those very helpful, but there was still too much manual work / typing involved for something that I would be doing pretty much every time I return home with a set of new recordings on the MicroSD card.

That’s why I sat down and wrote a little script, which automates the process a little better. No need to type out the file names of the video parts, plus the one of the resulting merged video file. Just tell the script the directory where it should store the resulting merged file(s), and it will process all videos on the MicroSD card automatically. If you want to skip some older recordings that you have not yet deleted from the MicroSD card, you can optionally give a date/time, and then the script will skip any files older than that.

So if you also want to work with GoPro-recorded videos on Linux, you might find this script useful. I’ve put it up on GitLab, feel free to modify it any way you want.

By the way, it might also work on Mac OS X. If anyone tries it out, please let me know 🙂

Update (2020-10-03): Thanks to Ralf, who tested the script on Mac OS X and found various issues! I took for granted that the basic utilities work the same as on Linux, but learned that they don’t. I’ve done some fixes now, and now it also works properly on Mac OS X 🙂 He also made me aware that my assumptions about the GoPro filename schema were wrong / incomplete. Now it should also work with H.264 recordings and even with recordings from older GoPro models that create “GOPR*.MP4” files. Hopefully I got the regexp right, didn’t do much testing, yet.

If you find any bugs, please also let me know, or even better, directly fix them and open a Merge Request on GitLab 😀

So here is the GitLab link: merge_gopro_mp4s.sh on GitLab


To simply use it, follow these instructions:

  • Download the file
  • Save it under /usr/local/bin or some other directory where you usually put scripts
  • Make it executable (chmod 755 merge_gopro_mp4s.sh)
  • Run it without parameter (or with -h, it does the same) and read the help text