Speedtest-cli is a command line tool by Ookia which is available for Windows,Linux and Mac.
Because I use Python and Speedtest-cli is written in python I used the standard Pip install method on windows and my Raspberry Pi.
pip install speedtest-cli
Using Speedtest-cli From the Command Line
Before you try to use speedtest-cli tool in node-red then you should run it from the command line to check it works and to test out the options that you want to use.
The Gitub page also has a full list of the command line options but you can get them using the command.
The options that you might find useful are
- –json -output as JSON
- –server test against a specific server
Below is a screen shot of the command using the default options:
Below is a screen shot of the command using the –server and –json options:
The json option is very useful when you want to pass the data into a program as we do with node-red.
Running Speedtest in Node-red
To run it in node red we use the exec node which allows us to run external commands.
Here is a screenshot of the node configuration; notice how the command line options are passed to the command
The node has three outputs
- Standard Output
- Standard Error
- Return Code.
The command results are taken from output 1.
You can use output 3 to determine if the command succeeded or not. A value of 0 is good.
This is what the flow looks like. I’ve added debug node so I can show you the output.
The main function node processes the data and sends it to a monitor so you can view the results in real time and also to a SQLite database.
Notice that when the node is running the process id of the system command is shown in the node status.
The debug nodes shows the standard output which contains our data and the result code which is 0 indicating success.
The results are displayed as a graph using the chart node.
The above graph shows the download speed dropping off a cliff and was taken from my Internet monitor during a recent Internet connection problem.
The following video is a general video covering running external commands from node-red. The speed-test is at the end of the video.