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
gennapium
Posts: 54
Joined: Thursday 18 August 2016 10:06
Target OS: Linux
Domoticz version: Stable
Location: Netherlands
Contact:

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

Post by gennapium »

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 ?
Ubuntu server, Raspberry Pi, PiFace 2, RFXCom, Z-wave Stick, Kaku, Sensor
lukev
Posts: 66
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

Post by lukev »

mikeoo wrote:
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/b3 ... 654/5737ae
Too bad.... :cry:
Thanks for your help!

Code: Select all

root@DiskStation:/volume1/@appstore/domoticz/var/scripts# python speedtest-cli.py
Traceback (most recent call last):
  File "speedtest-cli.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: 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 »

lukev wrote:
mikeoo wrote:
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/b3 ... 654/5737ae
Too bad.... :cry:
Thanks for your help!

Code: Select all

root@DiskStation:/volume1/@appstore/domoticz/var/scripts# python speedtest-cli.py
Traceback (most recent call last):
  File "speedtest-cli.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
Try running it my way. You run in with Python command.
You only need two files in the folder (st2domo.sh and speedtest-cli)

Did you test it with the scripts i placed here.
viewtopic.php?f=21&t=13814&start=60#p103936

Then run sh /<path>/st2domo.sh and not with the python command.
lukev
Posts: 66
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

Post by lukev »

Still overflowing... driving me nuts...

Code: Select all

root@DiskStation:/volume1/@appstore/domoticz/var/scripts# sh st2domo.sh
Traceback (most recent call last):
  File "/volume1/@appstore/domoticz/var/scripts/speedtest-cli", 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
ping =  ms
download =  Mbps
upload =   Mbps
HTTP/1.1 200 OK
Content-Length: 24
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *

{
   "status" : "ERR"
}
HTTP/1.1 200 OK
Content-Length: 24
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *

{
   "status" : "ERR"
}
HTTP/1.1 200 OK
Content-Length: 24
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *

{
   "status" : "ERR"
}
Yesterday I even uninstalled my SickRage and Couchpotato to be able to uninstall and re-install the SynoCommunity Python package.
No luck on that end, only a lot of work.... :-(
lukev
Posts: 66
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

Post by lukev »

Update:

I have installed python2.7 via ipkg, because I read the overflow problem was linked to python2.5.
Because python2.5 is a part of my firmware, I now have 2 versions installed.

So I edited speedtest-cli, the first line now reads:

Code: Select all

#!/usr/bin/python2.7
instead of:

Code: Select all

#!/usr/bin/env python
Problem solved.... at last!
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 »

lukev wrote:Update:

I have installed python2.7 via ipkg, because I read the overflow problem was linked to python2.5.
Because python2.5 is a part of my firmware, I now have 2 versions installed.

So I edited speedtest-cli, the first line now reads:

Code: Select all

#!/usr/bin/python2.7
instead of:

Code: Select all

#!/usr/bin/env python
Problem solved.... at last!
Great solutions :D
ksga
Posts: 12
Joined: Tuesday 02 February 2016 11:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Denmark
Contact:

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

Post by ksga »

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 ?
+1
gennapium
Posts: 54
Joined: Thursday 18 August 2016 10:06
Target OS: Linux
Domoticz version: Stable
Location: Netherlands
Contact:

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

Post by gennapium »

In linux give the command echo $PATH and copy the result. In the script at the beginning enter:
PATH=PATH:(the result from echo PATH)

That did the trick for me.

Good luck.
Ubuntu server, Raspberry Pi, PiFace 2, RFXCom, Z-wave Stick, Kaku, Sensor
ksga
Posts: 12
Joined: Tuesday 02 February 2016 11:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Denmark
Contact:

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

Post by ksga »

gennapium wrote:In linux give the command echo $PATH and copy the result. In the script at the beginning enter:
PATH=PATH:(the result from echo PATH)

That did the trick for me.

Good luck.
Perfect - works like a charm :D
Thanks.
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by bran2000 »

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 ?
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 »

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 ?
One solution could be to replace spaces with TAB key.

For Synology for example you need to use a TAB between every character and NOT spaces.
My rule as example:

Code: Select all

*/30	*	*	*	*	root	sh /volume2/@appstore/speedtest/st2domo.sh
Must be:

Code: Select all

*/30[tab]*[tab]*[tab]*[tab*[tab]root[tab]sh /volume2/@appstore/speedtest/st2domo.sh
[tab] means press the TAB key, not typing [tab]

Remove all spaces and replace them with a tab.
Save the cronjob and don't forget to restart the cronjob!!!!!

I that is not working
Check the logfiles. Mabye you can find an error there.

Don't know what system you use but on most linux systems you can find it in: /var/log
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by bran2000 »

Thanks for your answer but i have other tasks and they work fine. i'll try with tab key between every character.
when you said "don't forget to restart the cronjob" it means restart the crontab, i did this : sudo /etc/init.d/cron restart
For your information, i have a raspberry pi.
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 »

bran2000 wrote:Thanks for your answer but i have other tasks and they work fine. i'll try with tab key between every character.
when you said "don't forget to restart the cronjob" it means restart the crontab, i did this : sudo /etc/init.d/cron restart
For your information, i have a raspberry pi.
Correct. You can also.restart the rasp. For.rasp you can use spaces.

Try also.user root in the cronjob line
gennapium
Posts: 54
Joined: Thursday 18 August 2016 10:06
Target OS: Linux
Domoticz version: Stable
Location: Netherlands
Contact:

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

Post by gennapium »

Did you add the path to the script as i wrote in this topic ? I think that is the problem.
Ubuntu server, Raspberry Pi, PiFace 2, RFXCom, Z-wave Stick, Kaku, Sensor
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by bran2000 »

it's not working.
when you said "Try also.user root in the cronjob line" you mean run the crontab with the root account ?
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by bran2000 »

this is the line in my crontab :
*/1 * * * * /home/pi/domoticz/scripts/speedtestdomo.sh
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by bran2000 »

i tried also as root not working too.
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 »

Hi,
Maybe an strange question, this is my first script i want to run on an Raspberry Pi but i think i have somewhere forget something.
I have use the script but when i want manual run it i get the following error's:

Code: Select all

pi@Domoticz:~/domoticz/scripts $ sh st2domo.sh
: not found 2: st2domo.sh:
: not found 12: st2domo.sh:
: not found 15: st2domo.sh:
: not found 16: st2domo.sh:
: not found 19: st2domo.sh:
cat: outst.txt: Bestand of map bestaat niet
cat: outst.txt: Bestand of map bestaat niet
cat: outst.txt: Bestand of map bestaat niet
: not found 23: st2domo.sh:
: not found 24: st2domo.sh:
 Mbpsoad =
 Mbpsd =▒
 msg =▒
: not found 29: st2domo.sh:
: not found 30: st2domo.sh:
st2domo.sh: 33: st2domo.sh: Syntax error: Bad fd number
What can be the problem?
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,
Maybe an strange question, this is my first script i want to run on an Raspberry Pi but i think i have somewhere forget something.
I have use the script but when i want manual run it i get the following error's:

Code: Select all

pi@Domoticz:~/domoticz/scripts $ sh st2domo.sh
: not found 2: st2domo.sh:
: not found 12: st2domo.sh:
: not found 15: st2domo.sh:
: not found 16: st2domo.sh:
: not found 19: st2domo.sh:
cat: outst.txt: Bestand of map bestaat niet
cat: outst.txt: Bestand of map bestaat niet
cat: outst.txt: Bestand of map bestaat niet
: not found 23: st2domo.sh:
: not found 24: st2domo.sh:
 Mbpsoad =
 Mbpsd =▒
 msg =▒
: not found 29: st2domo.sh:
: not found 30: st2domo.sh:
st2domo.sh: 33: st2domo.sh: Syntax error: Bad fd number
What can be the problem?
Did do adjust the script to your system. Ip - Passwoord - IDX etc.
Did you create st2domo.sh maby with notepad of wordpad. That can give problems with strange characters added when saving the file.

Place your script so we can see what you use.
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 »

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

Who is online

Users browsing this forum: No registered users and 1 guest