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.
Post Reply
gennapium
Posts: 77
Joined: Thursday 18 August 2016 10:06
Target OS: Raspberry Pi
Domoticz version: beta
Location: Netherlands
Contact:

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

Post by gennapium » Monday 14 November 2016 18:40

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: 56
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 » Monday 14 November 2016 21:07

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

[email protected]:/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: 119
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo » Tuesday 15 November 2016 8:29

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

[email protected]:/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: 56
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 » Tuesday 15 November 2016 20:06

Still overflowing... driving me nuts...

Code: Select all

[email protected]:/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: 56
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 » Tuesday 15 November 2016 21:15

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: 119
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo » Wednesday 16 November 2016 8:36

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: 15
Joined: Tuesday 02 February 2016 12:08
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Denmark
Contact:

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

Post by ksga » Thursday 17 November 2016 9:26

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: 77
Joined: Thursday 18 August 2016 10:06
Target OS: Raspberry Pi
Domoticz version: beta
Location: Netherlands
Contact:

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

Post by gennapium » Thursday 17 November 2016 9:35

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: 15
Joined: Tuesday 02 February 2016 12:08
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Denmark
Contact:

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

Post by ksga » Thursday 17 November 2016 11:35

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: 79
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by bran2000 » Friday 18 November 2016 11:57

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: 119
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo » Friday 18 November 2016 16:16

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: 79
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by bran2000 » Friday 18 November 2016 16:54

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: 119
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo » Friday 18 November 2016 17:43

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: 77
Joined: Thursday 18 August 2016 10:06
Target OS: Raspberry Pi
Domoticz version: beta
Location: Netherlands
Contact:

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

Post by gennapium » Friday 18 November 2016 17:47

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: 79
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by bran2000 » Friday 18 November 2016 17:48

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: 79
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by bran2000 » Friday 18 November 2016 17:51

this is the line in my crontab :
*/1 * * * * /home/pi/domoticz/scripts/speedtestdomo.sh

bran2000
Posts: 79
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by bran2000 » Friday 18 November 2016 18:10

i tried also as root not working too.

User avatar
phoenixblue
Posts: 61
Joined: Friday 25 November 2016 12:20
Target OS: Raspberry Pi
Domoticz version: 3.7392
Contact:

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

Post by phoenixblue » Monday 28 November 2016 22:01

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

[email protected]:~/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?
scripts on github: Link

mikeoo
Posts: 119
Joined: Sunday 22 March 2015 8:35
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Holland
Contact:

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

Post by mikeoo » Tuesday 29 November 2016 8:46

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

[email protected]:~/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: 61
Joined: Friday 25 November 2016 12:20
Target OS: Raspberry Pi
Domoticz version: 3.7392
Contact:

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

Post by phoenixblue » Tuesday 29 November 2016 14:46

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:[email protected]$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:[email protected]$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:[email protected]$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.
scripts on github: Link

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests