Page 6 of 13
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 29 November 2016 20:20
by digisaster
bran2000 wrote:gennapium wrote:Hi,
I tested the script and when i start it it works fine. But when starting the script in cron, nothing happens. I can see the output.tx file is being updated but the info in the html page of domoticz is not updated. Also starting with sudo in cron doesn't help.
Does anyone know why ?
the same for me the script works fine but not the crontab, any idea ?
If you use cron, be sure to make all external command with full path.
So replace ping with
/bin/ping
Replace curl with
/usr/bin/curl
Replace speedtest-cli with
/usr/bin/speedtest-cli
This is the short answer.
The long answer is that cron will passes a minimal set of environment variables to your jobs. In most cases it will not know the current PATH, so it will not find the external commands. There are lots of ways how to work around this, but if you use the full path, it will just work.
p.s. if you don't know the full path, just type in "which {command}" and you will find the full path.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Tuesday 29 November 2016 21:40
by safi78
Hi Phoenixblue,
Weird that you get errors on 'empty' lines and commented out lines (with the #).
My guess would be invisible weird characters as well somehow. Why don't you just paste your created script (local) into nano (remote) in a terminal? That usually works for me.
Next to that, what happens if you run it with ./st2domo.sh instead of sh st2domo ?
And, did you install speedtest-cli?
It's such a simple script, what can possibly go wrong hehe

Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 30 November 2016 7:27
by mikeoo
phoenixblue wrote:Hi,
I use this script:
Code: Select all
#!/bin/bash
#setup
host=192.168.10.137
port=8080
username=mijn gebruikersnaam
password=mijn password
pingidx=27
downloadidx=28
uploadidx=29
# 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¶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"
I have made the sh file in windows with notepad++ and upload it with ftp to the rasp.
When I check the file with for example nano editor in SSH i see no strange characters.
Indeed
phoenixblue wrote:Hi,
I use this script:
Code: Select all
#!/bin/bash
#setup
host=192.168.10.137
port=8080
username=mijn gebruikersnaam
password=mijn password
pingidx=27
downloadidx=28
uploadidx=29
# 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¶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"
I have made the sh file in windows with notepad++ and upload it with ftp to the rasp.
When I check the file with for example nano editor in SSH i see no strange characters.
Change line
Code: Select all
speedtest-cli --simple > output.txt
to
/path to speedtest-cli/speedtest-cli --simple > output.txt
Still not working then there is as a told before a change with a problem with the file and wrong characters.
Try using WinSCP or Putty and nano and create a new file .
Past code in it and make it executable and try again.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 30 November 2016 15:26
by phoenixblue
I have for testing made an new file (test.sh) with nano from the terminal.
And insert the basic script and how strange it is, this works.
When I check the difference between the two files I see no different between it...
So I think that some were there is an hidden character or something..
Thanks for the tip.
Verstuurd vanaf mijn EVA-L09 met Tapatalk
Re: How to monitor your internet connection with virtual custom sensors
Posted: Thursday 01 December 2016 7:20
by mikeoo
phoenixblue wrote:I have for testing made an new file (test.sh) with nano from the terminal.
And insert the basic script and how strange it is, this works.
When I check the difference between the two files I see no different between it...
So I think that some were there is an hidden character or something..
Thanks for the tip.
Verstuurd vanaf mijn EVA-L09 met Tapatalk
Great it is working now.
Some stuff to read why this happens.
https://www.google.nl/search?ie=UTF-8&o ... or+windows
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 03 December 2016 9:45
by guantolento
but, it's possible setting in the script 1 server preferred with take the test ?
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 04 December 2016 7:18
by mikeoo
guantolento wrote:but, it's possible setting in the script 1 server preferred with take the test ?
Read pag 1. There you can read how you can use 1 specific server for testing.
viewtopic.php?f=21&t=13814#p100177
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 04 December 2016 14:50
by guantolento
ok but the list it's so long and i can view the first server ...
i think the server on the top are the nearest ..... i view server from 9000 km to 11000 km ....
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 04 December 2016 15:04
by mikeoo
guantolento wrote:ok but the list it's so long and i can view the first server ...
i think the server on the top are the nearest ..... i view server from 9000 km to 11000 km ....
Run it with a pipeline (|) more.
That way you can see the output per page.
Command:
Re: RE: Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 04 December 2016 16:53
by guantolento
mikeoo wrote:guantolento wrote:ok but the list it's so long and i can view the first server ...
i think the server on the top are the nearest ..... i view server from 9000 km to 11000 km ....
Run it with a pipeline (|) more.
That way you can see the output per page.
Command:
Thanks a lot. This evening i try.
Inviato dal mio GT-I9301I utilizzando Tapatalk
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 05 December 2016 0:40
by guantolento
i don't know why if i set manually one server the ping response don't work. my configuration is this:
Code: Select all
#setup
host=192.168.135.100
port=8080
username=xxxxxxxx
password=xxxxxxxx
pingidx=60
downloadidx=61
uploadidx=62
# no need to edit
speedtest-cli --server 3667 > 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$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 05 December 2016 7:29
by mikeoo
guantolento wrote:i don't know why if i set manually one server the ping response don't work. my configuration is this:
Code: Select all
#setup
host=192.168.135.100
port=8080
username=xxxxxxxx
password=xxxxxxxx
pingidx=60
downloadidx=61
uploadidx=62
# no need to edit
speedtest-cli --server 3667 > 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$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
The line speedtest-cli --server 3667 > output.txt is not correct when you need ping. You need to add --simple
I adjust your script like mine so try this one.
Code: Select all
#setup
host=192.168.135.100
port=8080
username=xxxxxxxx
password=xxxxxxxx
pingidx=60
downloadidx=61
uploadidx=62
# speedtest server number
serverst=3667
# no need to edit
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"
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 05 December 2016 13:29
by guantolento
This evening i try this and i give you a feedback.
Inviato dal mio GT-I9301I utilizzando Tapatalk
Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 07 December 2016 0:10
by guantolento
Now work perfect and without any mistakes. thanks a lot. bye bye.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Wednesday 07 December 2016 7:17
by mikeoo
guantolento wrote:Now work perfect and without any mistakes. thanks a lot. bye bye.
Great it is working now.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Saturday 10 December 2016 18:08
by guantolento
hi guys, today i change my router from the tp-link to fritzbox.
and without take any change on the rpi2 this is my new result with the test.

(i have a line with 10 dw and 1 up, in italy we are very poor with the lan structure !!!! hihihihi)
i think that the old router/modem/access point don't work very good as the new.
now the router work very good. bye bye.
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 18 December 2016 13:49
by dtech
Hi,
I try to add internet connection monitor to my domoticz and face same problems.
First is that I cannot create virtual switch in the menu to create it, I'm asked to add info for "Axis Labels" can you please let me know what should be there.
Second issue is that in output.txt file is do see correct values:

But when I start manually st32domo.sh I have these values:

There is different description. Do you know what I did wrong ?
This is my code of course without password
Code: Select all
#!/bin/bash
#setup
host=192.168.1.10
port=8081
username=XXX
password=XXX
pingidx=2470
downloadidx=2468
uploadidx=2469
# no need to edit
speedtest-cli --simple --server 4166 > 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"
I'm on the domoticz
Version: 3.6046
Build Hash: 0140857-modified
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 18 December 2016 14:31
by mikeoo
dtech wrote:Hi,
I try to add internet connection monitor to my domoticz and face same problems.
First is that I cannot create virtual switch in the menu to create it, I'm asked to add info for "Axis Labels" can you please let me know what should be there.
Second issue is that in output.txt file is do see correct values:

But when I start manually st32domo.sh I have these values:

There is different description. Do you know what I did wrong ?
I'm on the domoticz
Version: 3.6046
Build Hash: 0140857-modified
Axis is for Mbp/s and ms. Its a description of the value and you can fill in what you like.
The values needs the be the same so that is not correct.
Must be something wrong with your script or the program where you created the script is not correct for it. With some program's you get wrong characters extra in the script and then you get problems while running it.
Try this one and use WinSCP / Putty or Sublime Text for editing. Make sure you give it executable rights and then it must work.
Check also all 3 idx the you create the right one's.
I'm running latest Beta and this script is running fine.
Code: Select all
#!/bin/bash
#setup
host=192.168.1.10
port=8081
username=xxxxx
password=xxxx
pingidx=2470
downloadidx=2468
uploadidx=2469
# speedtest server number
serverst=4166
# no need to edit
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"
Re: How to monitor your internet connection with virtual custom sensors
Posted: Sunday 18 December 2016 21:17
by dtech
Thank you for your inputs, I have made the script file from the scratch in vi and all is working perfect. First file was made in Notepad++ and never ever before have issue like this.
Many Thanks
Re: How to monitor your internet connection with virtual custom sensors
Posted: Monday 19 December 2016 7:20
by mikeoo
dtech wrote:Thank you for your inputs, I have made the script file from the scratch in vi and all is working perfect. First file was made in Notepad++ and never ever before have issue like this.
Many Thanks
Great to hear all is working
