Subversion Repositories rld.domoticz

Rev

Rev 79 | Blame | Compare with Previous | Last modification | View Log | Download

# Ookla Speedtest CLI integration

Have been using the speedtest-cli integration 
for some years, but yesterday swapped to the "speedtest" CLI provided by
 Ookla. The original speedtest-cli worked well, except for the 
latency/ping measurements. The Ookla speedtest does measure the ping 
correctly, so therefore a step forward.  

Please note that you can't have them both installed at same time ![;-)](https://domoticz.com/forum/images/smilies/icon_e_wink.gif "Wink")  

Maybe this info saves some other people a bit of time to get this running.  

1) create dummy sensors  

2) store scripts somewhere (e.g. ~/domoticz/scripts)  
   see below for content  

3) modify IDXs in script with IDXs of your virtual sensors 

4) remove speedtest-cli (if installed)  
   sudo apt-get remove speedtest-cli  

5) install speedtest from Ookla,  
   see [Speedtest CLI - Internet connection measurement for developers](https://www.speedtest.net/apps/cli) (see Ubuntu/Debian)  
   check it works  

6) install jq  
   sudo apt-get install jq)  

7) verify the script works  
   check the port on which domoticz runs ![;-)](https://domoticz.com/forum/images/smilies/icon_e_wink.gif "Wink")  

8) create a crontab entry to schedule it.  
   #speedtest  
   5,20,35,50 * * * * ~/domoticz/scripts/ooklaspeed.sh > /dev/null 2>&1  

![Speedtest.jpg](./afbeelding/Speedtest.jpg)

Speedtest.jpg (99.89 KiB) Viewed 2110 times

![speedtest trend.jpg](./afbeelding/speedtest%20trend.jpg)

speedtest trend.jpg (121.03 KiB) Viewed 2110 times

------------script content----------------------

```bash
#!/bin/bash
# make sure jq is installed
# sudo apt-get install jq

# define domoticz connection
host=192.168.2.107
port=8080

# define ids for domoticz sensors for host
idxpng=3
idxul=2
idxdl=1
idxjit# define location for file
file=/home/marcel/domoticz/ookla.json

# execute the speedtest and store result.
# speedtest --accept-gdpr -f json-pretty > $file
speedtest --accept-gdpr -f json-pretty --server-id=5252 > $file

downraw=$(jq -r '.download.bandwidth' $file)
download=$(printf %.2f\\n "$((downraw * 8))e-6")

upraw=$(jq -r '.upload.bandwidth' $file)
upload=$(printf %.2f\\n "$((upraw * 8))e-6")

png=$(jq -r '.ping.latency' $file)

jit=$(jq -r '.ping.jitter' $file)

# output if you run it manually
echo "download = $download Mbps"
echo "upload =  $upload Mbps"
echo "ping =  $png ms"
echo "jitter = $jit ms"

# upload result to Domiticz
curl "http://$host:$port/json.htm?username=cGk=&password=TWFyZ3IhZXRANzA=&type=command¶m=udevice&idx=$idxdl&svalue=$downl$
curl "http://$host:$port/json.htm?username=cGk=&password=TWFyZ3IhZXRANzA=&type=command¶m=udevice&idx=$idxul&svalue=$uploa$
curl "http://$host:$port/json.htm?username=cGk=&password=TWFyZ3IhZXRANzA=&type=command¶m=udevice&idx=$idxpng&svalue=$png"$
curl "http://$host:$port/json.htm?username=cGk=&password=TWFyZ3IhZXRANzA=&type=command¶m=udevice&idx=$idxjit&svalue=$jit"$

```

## Install Oookla speed test

```bash
sudo apt-get install gnupg1 apt-transport-https dirmngr
export INSTALL_KEY=379CE192D401AB61
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $INSTALL_KEY
echo "deb https://ookla.bintray.com/debian generic main" | sudo tee  /etc/apt/sources.list.d/speedtest.list
sudo apt-get update
```

Other non-official binaries will conflict with Speedtest CLI
Example how to remove using apt-get
sudo apt-get remove speedtest-cli

```
sudo apt-get install speedtest
```