Page 8 of 13

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

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

Ok, I got the last part working. but still othing happens within domoticz.
I the domoticz logfile it doesn't seem check on the script for some reason.

is there anything else I need to setup within domoticz besides creating 3 virtual devices?

I installed it through the following.
wget -O speedtest-cli https://raw.githubusercontent.com/sivel ... est_cli.py

within the CLI it works fine but somehow domoticz is seeing the output

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

Posted: Tuesday 18 April 2017 23:03
by safi78
Hi Trigun,

What's the output of the script if you run it manually?

Looks like it looses the location to output.txt.

Specifying that output.txt should be at ~/ and later cat'ing it from there might do the trick :)

Also, your speedtest package seems to be in the admin folder. Did you schedule this in the crontab for admin as well? Or another user (that might not have permissions on that folder?)

Can you try this? I hope that with the '~' it will place the output.txt to the home-folder of the user you schedule it for, so it wouldn't matter which user you use. Next to that it's more specific to where the output.txt is, might work ...

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"

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

Posted: Wednesday 19 April 2017 0:40
by Siewert308SW
Just wanna say thx for your script.
Using it to monitor some issues with my connection -> isp regarding ping times.
Schermafdruk 2017-04-19 00.38.56.png
Schermafdruk 2017-04-19 00.38.56.png (295.58 KiB) Viewed 5099 times

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

Posted: Wednesday 19 April 2017 0:42
by safi78
Siewert308SW wrote:Just wanna say thx for your script.
Nice to be appreciated :D

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

Posted: Wednesday 19 April 2017 19:59
by Trigun
safi78 wrote:Hi Trigun,

What's the output of the script if you run it manually?

Looks like it looses the location to output.txt.

Specifying that output.txt should be at ~/ and later cat'ing it from there might do the trick :)

Also, your speedtest package seems to be in the admin folder. Did you schedule this in the crontab for admin as well? Or another user (that might not have permissions on that folder?)

Can you try this? I hope that with the '~' it will place the output.txt to the home-folder of the user you schedule it for, so it wouldn't matter which user you use. Next to that it's more specific to where the output.txt is, might work ...

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"
Hi safi78,

thnx for you reply!
It perfectly generates an output.txt file in the folder, the data is correct when I compare it to the output in de CLI but for some reason Domoticz is not picking up the values. I have no idea why it isn't working.

Grtz.

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

Posted: Wednesday 19 April 2017 20:03
by safi78
Again,

What's the output of the script if you run it manually?

Are you sure your host, port and idx settings are correct? And that you can connect without a password?

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

Posted: Wednesday 19 April 2017 20:13
by Trigun
safi78 wrote:Again,

What's the output of the script if you run it manually?

Are you sure your host, port and idx settings are correct? And that you can connect without a password?
ok, this is what I do.
I connect to the CLI run the following command: /volume1/homes/admin/Speedtest/stdomo.sh (without a password)
I get the following result:
output1.JPG
output1.JPG (18.08 KiB) Viewed 5070 times
It takes long though for the script to finish, even though the results are already in the script.
+ even though there is no ping time, it does show a ping value in the output.txt file, I guess this is due to the fixed server I selected (5302)
I tried using the script you send in the previous reply, but so far no luck.

Grtz.

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

Posted: Wednesday 19 April 2017 20:19
by safi78
Can you try again without the '-s' after the 'curl' command?

As far as i can tell, you don't get a ping value (could be another version of speedtest-cli than I use).

And, curl returns it's result after trying to update domoticz, I don't see that here. (could be another version of curl).

Run it again, without the -s and send the results?

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

Posted: Wednesday 19 April 2017 20:26
by Trigun
did it.

the result in the output.txt file is as follows:
Knipsel1.JPG
Knipsel1.JPG (41.23 KiB) Viewed 5065 times
the output from the cli is as follows:
Knipsel.JPG
Knipsel.JPG (20.51 KiB) Viewed 5065 times
it cold very well be I got the wrong version.
perhaps you can tell me which one I need for a synology NAS.
do I perhaps need to install a specific version of curl?

Cheers

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

Posted: Wednesday 19 April 2017 20:29
by safi78
change

Code: Select all

/volume1/homes/admin/Speedtest/speedtest-cli --server 5302 > ~/output.txt
to

Code: Select all

/volume1/homes/admin/Speedtest/speedtest-cli --simple --server 5302 > ~/output.txt

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

Posted: Wednesday 19 April 2017 20:33
by Trigun
I got a ping value now :)
see:
Knipsel2.JPG
Knipsel2.JPG (21.1 KiB) Viewed 5061 times
but stil no result in Domoticz.

Grtz

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

Posted: Wednesday 19 April 2017 20:35
by safi78
change

Code: Select all

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"
to

Code: Select all

curl -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"
and show what happens.

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

Posted: Wednesday 19 April 2017 22:58
by Trigun
I don't know what happend, but i re-installed speedtest-cli and re-did the script using your update ~/ and it works!

thanks a lot safi78. much appreciated!!

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

Posted: Thursday 20 April 2017 8:26
by safi78
Trigun wrote:I don't know what happend, but i re-installed speedtest-cli and re-did the script using your update ~/ and it works!

thanks a lot safi78. much appreciated!!
I doubt if that was your problem, after adding the '--simple' the part to 'get' the data out of the txt was fixed already.

The problem was in your host/user/pass/idx and curl part, you probably changed something there.

Anyway, always glad to help!

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

Posted: Thursday 18 May 2017 18:02
by ilpier
Here's the problem!
On windows 10,with CMD!
Someone help me?
Prob.JPG
Prob.JPG (46.49 KiB) Viewed 4832 times

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

Posted: Friday 19 May 2017 8:22
by bertbigb
ilpier wrote:Here's the problem!
On windows 10,with CMD!
Someone help me?
Prob.JPG
If you provide your script also we could hopefully see where the mistake (typo) is. Now we only know it is in line 14 :D

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

Posted: Friday 19 May 2017 10:36
by ilpier
yes Sorry!
here's the code!

Code: Select all

#!/bin/bash

#setup
port=8080
username=Admin
password=***
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"

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

Posted: Friday 19 May 2017 10:54
by ben53252642
We need a combined sensor for Internet Upload and Download, like we have combined sensor for Temperature and Humidity, I have about 300 devices in my Domoticz, keeping them as organised as possible is essential!
1.PNG
1.PNG (56.03 KiB) Viewed 4803 times
2.PNG
2.PNG (220.93 KiB) Viewed 4803 times

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

Posted: Friday 19 May 2017 11:07
by bertbigb
Hi ilpier,

I think your problem is related to the fact that your windows system doesn't know where to find the several files.
Your speedtest.sh is at C:\Users\andre\Desktop and you run the script from folder C:\Users\andre
But where will the system find speedtest-cli and where should it write output.txt?

That is why in Linux you use something like:
/volume1/homes/admin/Speedtest/speedtest-cli --simple --server 5302 > ~/output.txt

Here it is obvious. The speedtest-cli is at location: /volume1/homes/admin/Speedtest/
The output.txt file is written in ~/ which means in Linux the user directory of the user who is running this script.

I suggest that you put the script speedtest.sh in the same folder as where you put the speedtest-cli and run the script from that location.
Lets see what happens but most likely you will have results.
Good luck.

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

Posted: Friday 19 May 2017 11:56
by ilpier
Thx @bertbidb,yes,i put .sh in the same folder of speedtest-cli and now,in the same folder i have output.txt with Ping,Download and Upload!
but in Domoticz nothing happen!