June 13, 2025

One-liner Internet speedtest, Linux CLI, Node-Red, Home Assistant

+ Linux
We’ve been using Mobile Broadband for several years and have always been keen to measure the speed from our Internet Service Provider (ISP).

I’ve posted several variants, mostly Node-RED(NR) flows and programs that often use Python. I’m now slowly converting to Home Assistant(HA), and was glad there was an integration,  Speedtest, to do the job. But I couldn’t get it to work since HA didn’t like that the test took more than 10 seconds, 

Then I tried a Speedtest NR node, but it didn’t install because it needed Python dependencies...... (NR was installed as a HA "Add-on")

Intro 
So after some Googling i found this nice post.

Some ISPs, like Tele2, offer simple utilities to test your internet connection. The mentioned post shows a script

t=$(date +”%s”); wget http://speedtest.tele2.net/100MB.zip -O ->/dev/null ; echo -n ”MBit/s: ”; expr 8 \* 100 / $(($(date +”%s”)-$t))

which will give you your download speed.

The command works for any file, but the math is for a 100MB file. If you want other sites with test files, search for ”download 100mb.zip” on Google.

Code
Node-RED
So the using a NR "exec node" with command 

t=$(date +"%s"); wget -q http://speedtest.tele2.net/100MB.zip -O ->/config/files/100MB.zip ; echo -n ; expr 8 \* 100 / $(($(date +"%s")-$t))

i got the download speed. There are some changes to the original code
  • "wget" is using quiet mode
  • the downloaded file is stored in "/config/files/"
The stored file is then uploaded with command 

t=$(date +"%s"); curl -s -T /config/files/100MB.zip http://speedtest.tele2.net/upload.php -O /dev/null ; echo -n; expr 8 \* 100 / $(($(date +"%s")-$t))

and so I got the upload speed.


:
:

To be continued !

No comments:

Post a Comment

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !