Page 5 of 13

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

Posted: Monday 14 November 2016 17:40
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 ?

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

Posted: Monday 14 November 2016 20:07
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

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

Posted: Tuesday 15 November 2016 7:29
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.

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

Posted: Tuesday 15 November 2016 19:06
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.... :-(

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

Posted: Tuesday 15 November 2016 20:15
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!

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

Posted: Wednesday 16 November 2016 7:36
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

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

Posted: Thursday 17 November 2016 8:26
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

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

Posted: Thursday 17 November 2016 8:35
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.

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

Posted: Thursday 17 November 2016 10:35
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.

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

Posted: Friday 18 November 2016 10:57
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 ?

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

Posted: Friday 18 November 2016 15:16
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

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

Posted: Friday 18 November 2016 15:54
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.

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

Posted: Friday 18 November 2016 16:43
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

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

Posted: Friday 18 November 2016 16:47
by gennapium
Did you add the path to the script as i wrote in this topic ? I think that is the problem.

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

Posted: Friday 18 November 2016 16:48
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 ?

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

Posted: Friday 18 November 2016 16:51
by bran2000
this is the line in my crontab :
*/1 * * * * /home/pi/domoticz/scripts/speedtestdomo.sh

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

Posted: Friday 18 November 2016 17:10
by bran2000
i tried also as root not working too.

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

Posted: Monday 28 November 2016 21:01
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?

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

Posted: Tuesday 29 November 2016 7:46
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.

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

Posted: Tuesday 29 November 2016 13:46
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.