Skip to content

Instantly share code, notes, and snippets.

@bloigge
Last active March 8, 2018 07:58
Show Gist options
  • Save bloigge/b79e4d9cfc4b474b9975a8bb3b80fb64 to your computer and use it in GitHub Desktop.
Save bloigge/b79e4d9cfc4b474b9975a8bb3b80fb64 to your computer and use it in GitHub Desktop.
Internet Speedtest

This flow checks the current Internet Speed and logs the data to a json file. Can be used as evidence for your internet provider if your speed is lower as your contract says.

PreSettings:

[{"id":"5286be59.669fe","type":"cron","z":"d290794c.e099a8","name":"Cronjob (Every Hour)","crontab":"0 */1 * * *","x":200,"y":100,"wires":[["8749a854.0cee38"]]},{"id":"8749a854.0cee38","type":"exec","z":"d290794c.e099a8","command":"/home/pi/Speedtest/speedtest-cli","addpay":false,"append":"","useSpawn":"","timer":"","name":"Call Speedtest-Cli","x":445.5,"y":101.66665649414062,"wires":[["d5973ebb.39e38"],[],[]]},{"id":"d5973ebb.39e38","type":"function","z":"d290794c.e099a8","name":"Data Preparation for File","func":"var content = msg.payload.split(\"\\n\");\nmsg.payload = JSON.stringify({\n \"Testserver\": content[2].match(/\\((.*?)\\)/)[1],\n \"Hosted by\": content[4],\n \"Download Speed Mbit/s\": parseFloat(content[6].split(\" \")[1]),\n \"Upload Speed Mbit/s\": parseFloat(content[8].split(\" \")[1]),\n \"Timestamp\": new Date()\n}) + \",\";\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":100,"wires":[["b246a7b.dee2b58"]]},{"id":"b246a7b.dee2b58","type":"file","z":"d290794c.e099a8","name":"Store data (/home/pi/Speedtest/data.json)","filename":"/home/pi/Speedtest/data.json","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1080,"y":100,"wires":[]}]
@thebaldgeek
Copy link

Thanks for this flow, works great. Just one tweak required, the file speedtest-cli.py has been depreciated and is now called speedtest.py.
Once I made that change, everything worked as expected. (Caused me to stumble a bit since speedtest-cli is still on their servers, but throws a 'this file is depreciated' message rather than fully failing - this causes a JSON parse error which I thought was in the flow).

@bloigge
Copy link
Author

bloigge commented Apr 26, 2017

thank you for pointing that out. I updated the readme

@cyberlacs
Copy link

cyberlacs commented Jul 31, 2017

@bloigge

I'm trying to install Speed Test with the following NPM command on my raspberry with the Raspbian operating system

I enter as super user "sudo su"

And I try to install it with the command
root@raspberrypi: /home/pi #npm install speedtest_cli

And gives the following error

`root@raspberrypi:/home/pi# npm install speedtest_cli
npm ERR! 404 Not Found
npm ERR! 404
npm ERR! 404 'speedtest_cli' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

npm ERR! System Linux 4.4.50-v7+
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "speedtest_cli"
npm ERR! cwd /home/pi
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.21
npm ERR! code E404
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/pi/npm-debug.log
npm ERR! not ok code 0
`

I use the following command to check

root@raspberrypi:/home/pi# speed-test --help

Test your internet connection speed and ping using speedtest.net from the CLI

 Usage
   $ speed-test

 Options
   -j, --json     Output the result as JSON
   -b, --bytes    Output the result in megabytes per second (MBps)
   -v, --verbose  Output more detailed information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment