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.

Moderator: leecollings

Post Reply
digisaster
Posts: 6
Joined: Monday 28 November 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
safi78
Posts: 204
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Contact:

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

Post 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 :)
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post 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&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"
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&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"
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.
User avatar
phoenixblue
Posts: 76
Joined: Friday 25 November 2016 11:20
Target OS: Windows
Domoticz version:
Contact:

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

Post 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
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post 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
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post by guantolento »

but, it's possible setting in the script 1 server preferred with take the test ?
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post 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
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post 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 ....
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post 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:

Code: Select all

speedtest-cli --list | more
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post 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:

Code: Select all

speedtest-cli --list | more
Thanks a lot. This evening i try.

Inviato dal mio GT-I9301I utilizzando Tapatalk
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post 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&param=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice$
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post 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&param=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=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&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"
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post by guantolento »

This evening i try this and i give you a feedback.

Inviato dal mio GT-I9301I utilizzando Tapatalk
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post by guantolento »

Now work perfect and without any mistakes. thanks a lot. bye bye.
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo »

guantolento wrote:Now work perfect and without any mistakes. thanks a lot. bye bye.
Great it is working now.
guantolento
Posts: 129
Joined: Saturday 01 October 2016 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Italy BG
Contact:

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

Post 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. :shock: :shock: :shock: (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.
Attachments
Cattura.JPG
Cattura.JPG (42.6 KiB) Viewed 4640 times
Master (pi3) - MB sensors + Dummy + Sysfs gpio + 1 NodOn MSP-3 + 1 Aeotec DSB28 Energy Meter + 3 Danfoss RS Room + 7 Danfoss Z Thermostat + 1 Swiid Inter + 9 FGS222
Slave01 (pi2) - MB sensors + Dummy + Weather Underground + 2 FGS223 + 1 FGWPE/F
dtech
Posts: 20
Joined: Thursday 26 November 2015 8:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

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

Second issue is that in output.txt file is do see correct values:
Image
But when I start manually st32domo.sh I have these values:
Image
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&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"
I'm on the domoticz
Version: 3.6046
Build Hash: 0140857-modified
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

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

Second issue is that in output.txt file is do see correct values:
Image
But when I start manually st32domo.sh I have these values:
Image
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&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"
dtech
Posts: 20
Joined: Thursday 26 November 2015 8:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post 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
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

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

Post 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 :mrgreen:
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests