October 01, 2022

Internet speed measure II

New to Node-Red(NR) ? Maybe start with a simple application You direct can benefit from.

This application is measuring Your Internet connection at chosen intervals using speedtest.net and showing the result in a graph. If the speed is under a set value it will send You an e-mail.

Show the measured Internet speed in Apples Home app ?

Intro
Check this post for testing your local networks speed

For some years ago I wrote a post in the same matter but this version is improved by a command from Speedtest.net(SN).

There are several scripts available, using SN as target for the speed measurement, but when SN do a change in the interface you probably will get an error. Using SN:s own command, which automatically will be updated when you update the RPi OS, will solve that problem.

Installing
Speedtest
Here is some info about the command. If running a Raspberry(other OS here) start with executing the install script

curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash

It will take some time since it's doing an OS update. Then run 

sudo apt install speedtest-cli

to check the installation just execute the command "speedtest" and you will get the speed on your Internet connection.

Get help for the command using "speedtest --help"

NodeRed
If You haven't installed NR yet here is some short notes how to. If you want to send an email at a low detected internet speed add node "node-red-node-email".

Flow setup
The picture shows all the logic that is needed.

Download the flow "ISP_Speedtest_2022-10.json "from Github". Just click on the file name, then click on  "Raw" and copy the code.

In NR, open according to the picture, "Menu => Import => Clipboard" and paste the code.


So open "Menu => Manage palette => Palette => Install" and paste "node-red-node-emailand in the list click on "Install"

Click on Deploy in the upper right corner. This have to be done after any change in the code You do.

If You don't see any sidebar, check box in "Menu => View => Show sidebar". In the sidebar You can get additional information.

Now the flow is up and running and every 5 minutes the speed test is checking You Internet speed.

If You want to force the speed test just click once on the grey area, to the left of the arrow, on the "timestamp" node and You will se a text "Requesting" just below the speedtest node.

Click on "Debug" in sidebar area and the debug info is shown.

Probably You will see a "Error Mail command....", so double click on the Mail node and set it up.

Click on "Dashbord" in the sidebar area and then another click on the arrow to the right of "Site" which will take You to the GUI Dashboard corresponding to the picture first in this post.

Flow explanation
Every NR flow must have a trigger/inject that starts the flow. In this case the "inject" node, named "timestampdo the job. Double click on the node and You will see that every 5 minutes it sends a timestamp to the "Run speedtest" node. This node executes "speedtest --csv --secure" which output is formated as "csv".

The "CSV to Java object" node converts the comma separated text using the info in the "Columns" input field. The columns are retrieved executing "speedtest --csv-header"

The next node a function node, always contains Java Script(JS) code, named "Get speed Down/Up", picks up the measures from the input message. It is then divided to 2 outputs, since we want to show both values in the same graph.

If You activate the debug node, connected to the "Get speed Down/Up" output, clicking on the right side, the message will appear in the sidebar, debug message.

The next node, "Broadband Speed" which is a "chart" node, handles the output to a graph.

The function node, named "If speed below X Mbps => send mail" prepares the message for the mail node. If the speed is below x the message will be built, otherwise nothing is sent from the node.

In the "Mail" node properties is set for sending the mail. 

I like the function nodes because they can do a lot of job in the same node and you have to learn Javascript 😉.  But I could have done the same flow with just standard nodes

Remarks
Data sent/received
If you are paying for the downloaded data please note that every time you run a test you will send/receive around 70 + 70 Mbyte data !!

The picture
Please note that the graph, shown in the picture above, have big variation in speed due to that it's a mobile broadband.

Error
When using 

speedtest --csv

I got the error 

Cannot retrieve speedtest configuration
ERROR: HTTP Error 403: Forbidden


But when using 

speedtest --csv --secure

I didn't get any error ????

Additional info
The speedtest command could also output JSON data which will give you additional information. Check with 

speedtest  --json --secure

2 comments:

  1. Hey. Any idea what could cause an "error 255" at the node "Run speedtest"? I've been unable to find an answer for this. If it helps, I've been working on Ubuntu 20.04 LTS on VirtualBox. Everything in this guide has been working good so far, but I can't get pass this problem. Thx!

    ReplyDelete
    Replies
    1. Hi ! If you just use the command "speedtest" in a terminal/ssh session what happens ?

      Delete

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