Page 4 of 13
Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 03 November 2016 18:41
by guantolento
thanks safi78, but, if i take the same test with the wired lan on rpi, and disable the adapter usb/wireless, what's happened ? i think the download must increase, or not ?
Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 03 November 2016 18:47
by safi78
That's probably true, if the RPI shares it's general throughput with the USB-stuff, I'd say yes. If it doesn't have to share, it has more for the ethernet-stuff.
But hey, why run it on your pi if that's unreliable? Run it on a machine that can handle your 10/1Mbps for good test results?

It's easy to change the API/URL-stuff in the script, so 'where' you run it doesn't really matter
Put linux on your coffee-maker or fridge, run the test from there if these are equipped with better hardware?

Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 03 November 2016 18:55
by guantolento
yes of course, but i don't understand if your result in the screenshot on the top of the post arrived from rpi or another machine. if arrived from rpi, why you have so much download speed ?????
Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 03 November 2016 18:59
by safi78
The results of the screenshots are from an 8-core MacMini, 16Gb RAM and an SSD running Debian Linux (not that it's relevant). I left the RPI-hardware for Domoticz a long time ago because:
- It's slow (in every way: througput, SSH, running apt-get update annoyed the hell outta me, even switching stuff in my home improved drastically with better hardware).
It's unreliable (power failures / disk corruption);
It's unreliable (power needs to be in some kind of Goldy-Locks-zone if you add more stuff);
It's unreliable (it was broken more then it was running the way I wanted);
It doesn't have enough ports for all the stuff I want;
I don't want to run my home on unreliable stuff.

Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 03 November 2016 19:10
by safi78
I do have a Pi though
I use it for the USB P1 Smartmeter (which will influence my test) and running domoticz (idem) and running this test (ditto)
I believe it's 2nd gen, model B:
shitty results with Pi:
Code: Select all
Ping: 44.949 ms
Download: 26.80 Mbits/s
Upload: 4.76 Mbits/s
proper results with MacMini:
Code: Select all
Ping: 24.766 ms
Download: 50.63 Mbit/s
Upload: 4.49 Mbit/s
So ping is ~2x better, same as download. Upload is within the probably 25Mbps it can handle, so about the same.
Interesting read about Mbps's, Pi and models:
http://www.jeffgeerling.com/blogs/jeff- ... networking
Re: monitor internet connection with virtual sensors
Posted: Friday 11 November 2016 20:49
by lukev
mikeoo wrote:
I then installed (speedtest-cli) on my Synology NAS DS214+ and run the script from the NAS with 1Gb network connection but ping keeps high.
How in the world did you do that? Can't find it anywhere.....

Re: monitor internet connection with virtual sensors
Posted: Saturday 12 November 2016 12:25
by jumbotroll
lukev wrote:mikeoo wrote:
I then installed (speedtest-cli) on my Synology NAS DS214+ and run the script from the NAS with 1Gb network connection but ping keeps high.
How in the world did you do that? Can't find it anywhere.....

Install Python spk first and then log in to your NAS with Telnet or SSH and type: sudo pip install speedtest-cli
Re: monitor internet connection with virtual sensors
Posted: Saturday 12 November 2016 16:47
by lukev
jumbotroll wrote:
Install Python spk first and then log in to your NAS with Telnet or SSH and type: sudo pip install speedtest-cli
I did install python 2.7.11-15 (from Synocommunity) and sudo also (via ipkGui), but it's not working:
Code: Select all
root@DiskStation:~# sudo pip install speedtest-cli
sudo: pip: command not found
Any thoughts?
Re: monitor internet connection with virtual sensors
Posted: Saturday 12 November 2016 16:59
by jumbotroll
lukev wrote:jumbotroll wrote:
Install Python spk first and then log in to your NAS with Telnet or SSH and type: sudo pip install speedtest-cli
I did install python 2.7.11-15 (from Synocommunity) and sudo also (via ipkGui), but it's not working:
Code: Select all
root@DiskStation:~# sudo pip install speedtest-cli
sudo: pip: command not found
Any thoughts?
Ok, you must first install pip.
Try to type: sudo easy_install pip
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 12 November 2016 17:03
by lukev
Code: Select all
root@DiskStation:~# sudo easy_install pip
sudo: easy_install: command not found
root@DiskStation:~#
Code: Select all
root@DiskStation:~# sudo
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
user name|#uid] file ...
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 12 November 2016 17:05
by jumbotroll
lukev wrote:Code: Select all
root@DiskStation:~# sudo easy_install pip
sudo: easy_install: command not found
root@DiskStation:~#

I don't remember what I did

but I also installed python version 3.4 from synocommunity.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 12 November 2016 17:09
by lukev
Also tried this one:
https://github.com/sivel/speedtest-cli
But then again... didn't work...
Code: Select all
root@DiskStation:~# python speedtest-cli/setup.py install
running install
Traceback (most recent call last):
File "speedtest-cli/setup.py", line 91, in <module>
'Programming Language :: Python :: 3.4',
File "/opt/lib/python2.5/distutils/core.py", line 151, in setup
dist.run_commands()
File "/opt/lib/python2.5/distutils/dist.py", line 974, in run_commands
self.run_command(cmd)
File "/opt/lib/python2.5/distutils/dist.py", line 994, in run_command
cmd_obj.run()
File "/opt/lib/python2.5/site-packages/setuptools/command/install.py", line 76, in run
self.do_egg_install()
File "/opt/lib/python2.5/site-packages/setuptools/command/install.py", line 85, in do_egg_install
easy_install = self.distribution.get_command_class('easy_install')
File "/opt/lib/python2.5/site-packages/setuptools/dist.py", line 395, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "/opt/lib/python2.5/site-packages/pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/opt/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 12, in <module>
import sys, os.path, zipimport, shutil, tempfile, zipfile, re, stat, random
File "/opt/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/opt/lib/python2.5/random.py", line 58, in <module>
SG_MAGICCONST = 1.0 + _log(4.5)
OverflowError: math range error
root@DiskStation:~#
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 12 November 2016 17:16
by jumbotroll
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 12 November 2016 17:57
by lukev
Thanks Jumbotroll, but that also is a no-go.... The link to get-pip.py is old. It refers to a new link, which... of course ... doesn't work.
But I have managed to install it an other way, but still get a Overflow error... I think I will call it a day for now...
Code: Select all
root@DiskStation:/volume1/@appstore/domoticz/var/scripts# python speedtest.py
Traceback (most recent call last):
File "speedtest.py", line 51, in <module>
from urllib2 import urlopen, Request, HTTPError, URLError
File "/opt/lib/python2.5/urllib2.py", line 92, in <module>
import httplib
File "/opt/lib/python2.5/httplib.py", line 70, in <module>
import mimetools
File "/opt/lib/python2.5/mimetools.py", line 6, in <module>
import tempfile
File "/opt/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/opt/lib/python2.5/random.py", line 58, in <module>
SG_MAGICCONST = 1.0 + _log(4.5)
OverflowError: math range error
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 13 November 2016 10:17
by mikeoo
@lukev
What i did
I did not install anything extra. But i could be the in the past i already install some package.
1. Create a folder on the NAS /volume2/@appstore/speedtest and put speedtest-cli in it. Any other folder would be fine also.
2. Create in the same folder
st2domo.sh and put the code in it. The code you find a bit lower.
Adjust the lines with
Setup to your situation and change the IDX to the right ones for you and choose a Speedtest server near you.
Run in Putty:
/volume2/@appstore/speedtest/speedtest-cli --list i take the upper one.
3, Both files give permission
0755
4.
chmod +x st2domo.sh and I also did this for the
speedtest-cli file.
code st2domo.sh
Code: Select all
#!/bin/bash
#setup
host=ip-adres
port=8080
username=username
password=password
pingidx=990
downloadidx=991
uploadidx=992
# speedtest server number
serverst=2042
# no need to edit
/volume2/@appstore/speedtest/speedtest-cli --simple --server $serverst > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload = $upload Mbps"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$uploadidx&svalue=$upload"
Edit the cronjob on the Synology (/var/crontab)
Put in this file (i run it every 30 min)
Code: Select all
*/30 * * * * root sh /volume2/@appstore/speedtest/st2domo.sh
Restart the Cronjob. For DSM 5 you can use.
Code: Select all
/usr/syno/sbin/synoservicectl --restart crond
Or restart your NAS
For testing you can run the script in Putty (Synology)
sh /volume2/@appstore/speedtest/st2domo.sh
Done.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 13 November 2016 13:53
by safi78
Nice.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 13 November 2016 14:18
by lukev
Thanks for all your help, but the Speedtest script is just overflowing for some strange reason. I think it has something to do with my setup
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 14 November 2016 7:29
by mikeoo
lukev wrote:Thanks for all your help, but the Speedtest script is just overflowing for some strange reason. I think it has something to do with my setup
You could try my speedtest-cli file i use on the Synology. Maybe the problem is with the file itself.
https://www.wetransfer.com/downloads/b3 ... 654/5737ae
link is working until 21/11/2016
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 14 November 2016 12:36
by lukev
Thanks, gonna try tonight!!
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 14 November 2016 12:46
by emme
I've made few changes to the original script to have the possibility to run the test several times per day more, have the possibility to run "ondemand"
Here's my new script which works quite good!!
It's all based on user variables (I don't really like virtual switches) and it works like having into a variable all the hours you want to run, another variable specify the minute, the third is for show debug info in the log
I'm not so skilled in LUA so I don't know if this would be the best way to reaching the result (I know... a vitual switch with a script and timers would probably be better because you can setup times you want... but .... I don't like virtual switches... they meks me confusing!

)
the fromCSV funzion move the hour string variable to a table
Code: Select all
debugger = tonumber(uservariables['SpeedTest_Debug'])
JSON = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- File per la decodifica del tracciato JSON restituito dallo speedtest
cTime = os.date("*t")
scName = '/home/pi/domoticz/scripts/speedtest-json.sh'
stForce = tonumber(uservariables['SpeedTest_Run']) -- Flag per SpeedTest forzato
runScript = false -- Semaforo per esecuzione Procedura
runMinute = tonumber(uservariables['SpeedTest_RunMinute']) -- Minutaggio di esecuzione
prxPrint = '>>> [ST] >>> ' -- Prefisso per stringhe di debug
--
-- INIZIO PROCEDURA PER CONVERSIONE STRINGA CSV IN TABELLA
--
function fromCSV (s)
s = s .. ',' -- ending comma
local t = {} -- table to collect fields
local fieldstart = 1
repeat
-- next field is quoted? (start with `"'?)
if string.find(s, '^"', fieldstart) then
local a, c
local i = fieldstart
repeat
-- find closing quote
a, i, c = string.find(s, '"("?)', i+1)
until c ~= '"' -- quote not followed by quote?
if not i then error('unmatched "') end
local f = string.sub(s, fieldstart+1, i-1)
table.insert(t, (string.gsub(f, '""', '"')))
fieldstart = string.find(s, ',', i) + 1
else -- unquoted; find next comma
local nexti = string.find(s, ',', fieldstart)
table.insert(t, string.sub(s, fieldstart, nexti-1))
fieldstart = nexti + 1
end
until fieldstart > string.len(s)
return t
end
--
-- FINE PROCEDURA PER CONVERSIONE STRINGA CSV IN TABELLA
--
commandArray = {}
-- Creazione array orari di esecuzione
arrRunOnTime = fromCSV(uservariables['SpeedTest_RunOnTime'])
-- Valutazione della variabile di esecuzione script obbligata
if stForce == 1 then
print(prxPrint..'SpeedTest forzato')
runScript = true
commandArray["Variable:SpeedTest_Run"] = tostring(0)
end
-- Valutazione orario (minuti e ore)
for i,runHour in pairs(arrRunOnTime) do
-- Debugging
if debugger == 1 then
print (prxPrint..'Orario reale/schedulato/forzato: '..cTime.hour..':'..cTime.min..'/'..runHour..':'..runMinute..'/'..stForce)
end
if tonumber(cTime.min) == tonumber(runMinute) then
if tonumber(runHour) == tonumber(cTime.hour) then
runScript = true
print(prxPrint..'SpeedTest Schedulato')
end
end
end
-- Debugging
if debugger == 1 then
print (prxPrint..'Semafori forzato/Esecuzione: '..stForce..'/'..tostring(runScript))
end
-- Script Principale
if runScript == true then
print(prxPrint..'Esecuzione SpeedTest')
os.execute(scriptPath)
file = io.open("/home/pi/domoticz/scripts/speed-test.json", "r")
json_text = file:read()
speeds = JSON:decode(json_text)
print(prxPrint..'['..cTime.hour..':'..cTime.min..'] >>> Dl/Ul/Pg: '..speeds.Download_Mbit..'/'..speeds.Upload_Mbit..'/'..speeds.Ping_ms)
commandArray[1]={['UpdateDevice']='147|0|'..speeds.Download_Mbit}
commandArray[2]={['UpdateDevice']='148|0|'..speeds.Upload_Mbit}
commandArray[3]={['UpdateDevice']='146|0|'..speeds.Ping_ms}
os.execute("rm /home/pi/domoticz/scripts/speed-test.json")
end
return commandArray