How to monitor your internet connection with virtual custom sensors

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.
guantolento
Posts: 122
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby guantolento » Thursday 03 November 2016 19:41

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 ?
RPI2 + Z Stick Gen 5 + System Alive Checker + Weather Underground + MB Sensor + Dummy + 1 Wall Plug NodOn + 3 Danfoss Room Sensor + 7 Danfoss Z Thermostat + 1 Swiid Chord + 9 Fibaro FGS222 2x1.5Kw

User avatar
safi78
Posts: 374
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby safi78 » Thursday 03 November 2016 19:47

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? :lol:
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

guantolento
Posts: 122
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: Italy BG
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby guantolento » Thursday 03 November 2016 19:55

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 ?????
RPI2 + Z Stick Gen 5 + System Alive Checker + Weather Underground + MB Sensor + Dummy + 1 Wall Plug NodOn + 3 Danfoss Room Sensor + 7 Danfoss Z Thermostat + 1 Swiid Chord + 9 Fibaro FGS222 2x1.5Kw

User avatar
safi78
Posts: 374
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby safi78 » Thursday 03 November 2016 19:59

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.
:)
Last edited by safi78 on Thursday 03 November 2016 20:22, edited 2 times in total.
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

User avatar
safi78
Posts: 374
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby safi78 » Thursday 03 November 2016 20:10

I do have a Pi though :P

I use it for the USB P1 Smartmeter (which will influence my test) and running domoticz (idem) and running this test (ditto) :P

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-geerling/getting-gigabit-networking
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: monitor internet connection with virtual sensors

Postby lukev » Friday 11 November 2016 21:49

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..... :cry:

User avatar
jumbotroll
Posts: 471
Joined: Tuesday 13 January 2015 15:36
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Oslo,Norway
Contact:

Re: monitor internet connection with virtual sensors

Postby jumbotroll » Saturday 12 November 2016 13:25

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..... :cry:


Install Python spk first and then log in to your NAS with Telnet or SSH and type: sudo pip install speedtest-cli
Regards
Jumbotroll
http://www.jadahl.com

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: monitor internet connection with virtual sensors

Postby lukev » Saturday 12 November 2016 17:47

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?

User avatar
jumbotroll
Posts: 471
Joined: Tuesday 13 January 2015 15:36
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Oslo,Norway
Contact:

Re: monitor internet connection with virtual sensors

Postby jumbotroll » Saturday 12 November 2016 17:59

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
Regards
Jumbotroll
http://www.jadahl.com

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby lukev » Saturday 12 November 2016 18:03

Code: Select all

root@DiskStation:~# sudo easy_install pip
sudo: easy_install: command not found
root@DiskStation:~#


:roll:



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 ...

User avatar
jumbotroll
Posts: 471
Joined: Tuesday 13 January 2015 15:36
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Oslo,Norway
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby jumbotroll » Saturday 12 November 2016 18:05

lukev wrote:

Code: Select all

root@DiskStation:~# sudo easy_install pip
sudo: easy_install: command not found
root@DiskStation:~#


:roll:


I don't remember what I did :-) but I also installed python version 3.4 from synocommunity.
Regards
Jumbotroll
http://www.jadahl.com

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby lukev » Saturday 12 November 2016 18:09

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:~#

User avatar
jumbotroll
Posts: 471
Joined: Tuesday 13 January 2015 15:36
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Oslo,Norway
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby jumbotroll » Saturday 12 November 2016 18:16

Found this: https://forum.synology.com/enu/viewtopic.php?t=59837

Solution:
download https://raw.github.com/pypa/pip/master/ ... get-pip.py

run:
ds>python get-pip.py

run:
DS> sudo pip install speedtest-cli

done
Regards
Jumbotroll
http://www.jadahl.com

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby lukev » Saturday 12 November 2016 18:57

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

mikeoo
Posts: 93
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby mikeoo » Sunday 13 November 2016 11:17

@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&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=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.
Last edited by mikeoo on Tuesday 15 November 2016 8:30, edited 1 time in total.

User avatar
safi78
Posts: 374
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby safi78 » Sunday 13 November 2016 14:53

Nice.
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby lukev » Sunday 13 November 2016 15:18

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

mikeoo
Posts: 93
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby mikeoo » Monday 14 November 2016 8:29

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/b3166cc5984464cb38f1d94cf83262d820161114062654/d1b1bfb2ad4a74986875b652f19fb2e720161114062654/5737ae

link is working until 21/11/2016

lukev
Posts: 27
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby lukev » Monday 14 November 2016 13:36

Thanks, gonna try tonight!!

User avatar
emme
Posts: 372
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Postby emme » Monday 14 November 2016 13:46

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! :P)

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
Attachments
Cattura-1.jpg
variables list
Cattura-1.jpg (10.13 KiB) Viewed 279 times
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!


Return to “Third party and supplementary tools”

Who is online

Users browsing this forum: No registered users and 1 guest