Page 7 of 13

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

Posted: Friday 23 December 2016 10:15
by safi78
I created a fairly similar script for a differtent purpose, maybe you guys like it as well: viewtopic.php?f=21&t=14591

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

Posted: Saturday 07 January 2017 10:46
by johan99
Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?

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

Posted: Saturday 07 January 2017 10:59
by mikeoo
johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
Place your script and the command you use also here so we can check.

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

Posted: Saturday 07 January 2017 17:55
by gjaa
I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)

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

Posted: Saturday 07 January 2017 21:26
by johan99
mikeoo wrote:
johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
Place your script and the command you use also here so we can check.
Ok, here is first the code and after that is the command line.

Code: Select all

#!/bin/bash

#setup
port=8080
username=xxxx
password=xxxx
host=localhost
pingidx=239
downloadidx=241
uploadidx=240


# no need to edit
speedtest-cli --simple > 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"
command in windows (cmd runned in admin mode): python speedtest.sh

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

Posted: Sunday 08 January 2017 8:40
by mikeoo
johan99 wrote:
mikeoo wrote:
johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
Place your script and the command you use also here so we can check.
Ok, here is first the code and after that is the command line.

Code: Select all

#!/bin/bash

#setup
port=8080
username=xxxx
password=xxxx
host=localhost
pingidx=239
downloadidx=241
uploadidx=240


# no need to edit
speedtest-cli --simple > 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"
command in windows (cmd runned in admin mode): python speedtest.sh
Try to change host=localhost to host=ip-adres of domoticz and test if that change something.

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

Posted: Sunday 08 January 2017 8:55
by mikeoo
gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
Nice one's :mrgreen:

Tip
I did not see them when i try to change them for the Custum Sensor afther uploading the icons in Domoticz.
I reboot did not solve the problem.

You need the do a browser refresh and then you can see them.

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

Posted: Sunday 08 January 2017 16:59
by johan99
mikeoo wrote:
johan99 wrote:
mikeoo wrote: Try to change host=localhost to host=ip-adres of domoticz and test if that change something.
When i use the IP I get this error:

File "speedtest2.sh", line 7
host=192.168.0.188
^
SyntaxError: invalid syntax

I says the zero in the adress is the problem, dont know why, the adress is correct. When I edit the file i use a Windows PC and notepad++ and choose unix EOL.

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

Posted: Monday 09 January 2017 7:31
by mikeoo
johan99 wrote:
mikeoo wrote:
johan99 wrote:
When i use the IP I get this error:

File "speedtest2.sh", line 7
host=192.168.0.188
^
SyntaxError: invalid syntax

I says the zero in the adress is the problem, dont know why, the adress is correct. When I edit the file i use a Windows PC and notepad++ and choose unix EOL.
You can try the use a different editor. Lot of Windows editors give problems with linux files and to be sure try an other one. Because it say that er is a problem it looks like notepad++ does something with the file. Try Sublime Text https://sublimetext.com/3 that one is working fine with linux files

Create a new file again, don't copy and past the old one because then you can copy the strange characters in to the new file.

If it still not working maybe a pyhton version problem, try to run it without python command and just speedtest
viewtopic.php?f=21&t=13814&p=100190&hil ... ws#p100190

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

Posted: Tuesday 10 January 2017 11:39
by johan99
I tried sublimetext now aswell and get the same issues.
I think I set a Raspberry Pi up (have one not used for anything) and use that for this instead. Using it as a 2:nd Domoticz server. When reading this forum I realize that most of you use RP and most guides are written for RP.

Thanks for the help though. And I'll keep on using the Windows server as my main server for Domoticz and are intrested to hear from you who got everything working fine with Win and Domoticz.

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

Posted: Thursday 26 January 2017 19:35
by dtech
gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
How this icons can be added ?

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

Posted: Thursday 26 January 2017 20:46
by sincze
dtech wrote:
gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
How this icons can be added ?
I found the solution in the wiki
http://www.domoticz.com/wiki/Custom_ico ... binterface

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

Posted: Sunday 16 April 2017 16:41
by Trigun
Hi all, first of all, great feature!! i carried out all the steps bit for some reason the custom sensors don't show the values. When I run the script I do get the correct info, but the sensors are not showing anything. Does anyone have an idea where I went wrong?


Sent from my iPhone using Tapatalk

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

Posted: Sunday 16 April 2017 20:02
by EdwinK
I like this script a lot. One small thing though.

After the data, I get a '0' instead of the right value (ms, Mbp/s). Can this be fixed?

Image
Forget about the first tile, that is from another script.

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

Posted: Sunday 16 April 2017 20:35
by koowee
EdKo66 wrote:I like this script a lot. One small thing though.

After the data, I get a '0' instead of the right value (ms, Mbp/s). Can this be fixed?

Image
Forget about the first tile, that is from another script.
I think that you need to modify those, Device (Ping, Download and Upload) > Edit > Axis label (add ms or Mbp/s depending device)

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

Posted: Sunday 16 April 2017 22:08
by EdwinK
Ah.. Of course. Thanks :)

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

Posted: Tuesday 18 April 2017 19:21
by Trigun
Hey guys,

Really like the script! its working well when manually run. but for some reason I can't seem to get the output in domoticz.
does anyone have an idea?
I am running it on a Synology NAS.

Thnx in advance!

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

Posted: Tuesday 18 April 2017 19:54
by EdwinK
Running this on a Synology NAS too, and had it working in matter of minutes.

Synology doesn't have apt-get, so you need to find another way to get the files. I used easy_install, but can't quite remember how I did install that.
Search for easy_install and Synology on the Google.

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

Posted: Tuesday 18 April 2017 19:55
by EdwinK
gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)

Thanks for those icons ;)

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

Posted: Tuesday 18 April 2017 20:03
by Trigun
Hi Edko66,

is there a chance you can help me out here?
since I have no username and password for domoticz, this is my script.

Code: Select all

#!/bin/bash

#setup
host=192.168.10.21
port=8084
pingidx=8
downloadidx=6
uploadidx=7

# no need to edit
/volume1/homes/admin/Speedtest/speedtest-cli --server 5302 > 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://$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"
I can see the output.txt file it not in the same directory where thie stdomo.sh and speedtest-cli are in. shoudl this be?