someone who can help me out with a script

Moderator: leecollings

Post Reply
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

someone who can help me out with a script

Post 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
Attachments
bidgely.zip
(13.96 KiB) Downloaded 41 times
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: someone who can help me out with a script

Post 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.
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: someone who can help me out with a script

Post 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
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post 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.
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post by delchrys »

Hmm for_in gives invalid syntax

Verstuurd vanaf mijn P6-U06 met Tapatalk
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post by delchrys »

Hmm for_in gives invalid syntax
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post by delchrys »

Any other ideas
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: someone who can help me out with a script

Post by Egregius »

Must be python version.
Google for python loop 6 times and you'll find other ways.
delchrys
Posts: 51
Joined: Wednesday 02 March 2016 20:52
Target OS: -
Domoticz version:
Contact:

Re: someone who can help me out with a script

Post by delchrys »

It Works now seems I forgotten a space.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest