Page 1 of 1

someone who can help me out with a script

Posted: Saturday 22 October 2016 19:37
by delchrys
hello all,

i have used domoticz for a while now, but i want to export my data to bidgely also.
i have found a script online and after some modifying it works now, but sometimes it halts.
when i look at the verbose output, i found out i have a socket timeout.
i guess my system is busy at the moment, getting or sending data to pvoutput, which is a other script that i am running.
but somehow i need some modifications in the script so that it retries after socket timeout. for now i can't see that a retry is used, but i have very little scripting skills only arduino programming.
is there someone who can help me with it?

kind regards,

bert

Re: someone who can help me out with a script

Posted: Saturday 22 October 2016 19:40
by delchrys
error i get is

Code: Select all

Traceback (most recent call last):
  File "bidgely.py", line 114, in <module>
    loop()
  File "bidgely.py", line 107, in loop
    el_data, gas_data = gather_data(settings.get_setting("seconds"))
  File "bidgely.py", line 58, in gather_data
    success, ElectricitySerial, ElectricityRateUsedOffPeak, ElectricityRateUsedPeak, ElectricityCurrentRate, ElectricityTotalUsed, ElectricityTotalGenerated, ElectricitySwitchPosition, GasSerial, GasLogDateTime, GasTotal = settings.rd.get_data(settings.get_setting("verbose"))
  File "/home/pi/testscripts/bidgely/domodata.py", line 15, in get_data
    GasTotal, GasLogDateTime = get_gas_values(settings.get_setting("domoticzurl"), settings.get_setting("domoticzdeviceid_gas"))
  File "/home/pi/testscripts/bidgely/domodata.py", line 107, in get_gas_values
    device_data = Domoticz(url).get_device(device_id)
  File "/home/pi/testscripts/bidgely/domodata.py", line 78, in get_device
    data = json.load(self.__execute__(url))
  File "/home/pi/testscripts/bidgely/domodata.py", line 71, in __execute__
    return urllib2.urlopen(req, timeout=5)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1200, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1111, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 444, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 400, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
socket.timeout: timed out

Re: someone who can help me out with a script

Posted: Saturday 22 October 2016 21:49
by Egregius
Does your script run in a loop?
Why not just execute once and execute it by cron?
That way, if it exits it'll just run again a minute later.

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 9:18
by delchrys
I borrowed this script from someone else because I can't script myself. So i wouldn't know how to make this script run once. It works but locks up sometimes.

Verstuurd vanaf mijn P6-U06 met Tapatalk

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 9:39
by Egregius
I don't know Python very good, but this would be my guess:

In bidgely.py there's a "while 1:" loop wich runs forever. In another part of the code (domodata.py:58) there's a sleep of 10 seconds. The script runs every 10 seconds.
So, if you change the endless while 1 loop to a loop that runs 6 times and execute the script by cron every minute it should run forever.

Try this:
change bidgely.py line 106:

Code: Select all

		while 1:
to

Code: Select all

		for _ in " "*6:
And add the script to cron:
sudo crontab -e
* * * * * /path/to/script.py

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 12:22
by delchrys
Will try that thanks, do i have to change the sleep command also?

Edit: or the sleep uses 10 and the other lines makes it run 6 times. So this script will run 1 minute. And cron makes it run every minute.

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 12:35
by delchrys
Hmm for_in gives invalid syntax

Verstuurd vanaf mijn P6-U06 met Tapatalk

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 12:35
by delchrys
Hmm for_in gives invalid syntax

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 22:29
by delchrys
Any other ideas

Re: someone who can help me out with a script

Posted: Sunday 23 October 2016 22:52
by Egregius
Must be python version.
Google for python loop 6 times and you'll find other ways.

Re: someone who can help me out with a script

Posted: Tuesday 25 October 2016 7:39
by delchrys
It Works now seems I forgotten a space.