miccoli / pyownet

Pure python client library for accessing OWFS via owserver protocol.
http://pyownet.readthedocs.io/
GNU Lesser General Public License v3.0
10 stars 6 forks source link

Program aborted with pyownet.protocol.OwnetError: [Errno 22] legacy - Invalid transaction #11

Closed EsMtt closed 7 years ago

EsMtt commented 7 years ago

I wrote a program to read sensor data from multiple RPis with OWFS and the latest pyownet. The reading repeats itself with the help of an threading timer every 1 to 3 seconds (similar to https://stackoverflow.com/questions/12435211/python-threading-timer-repeat-function-every-n-seconds/24488061#24488061). After an irregular number of iterations the program fails with the error:

Exception in thread Thread-76:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 1180, in run
    self.function(*self.args, **self.kwargs)
  File "/home/elias2/Schreibtisch/test.py", line 42, in _handle_target
    self.target()
  File "/home/elias2/Schreibtisch/test.py", line 98, in pi_to_sql
    sensorTemp = float(owproxy0.read(sensor + 'temperature'))
  File "/usr/local/lib/python3.5/dist-packages/pyownet/protocol.py", line 615, in read
    raise OwnetError(-ret, self.errmess[-ret], path)
pyownet.protocol.OwnetError: [Errno 22] legacy - Invalid transaction: '/28.EE3FE02C1602/temperature'

As I said before, the number of Exception in thread Thread-76: is variable. I connect to owserver with

owproxy0 = protocol.proxy(host=host0, port=owport, flags=0, persistent=False, verbose=False)
owproxy1 = protocol.proxy(host=host1, port=owport, flags=0, persistent=False, verbose=False)
...

and also tried

owproxy0 = protocol.proxy(host=host0, port=owport)
owproxy1 = protocol.proxy(host=host1, port=owport)
...

which causes the same issue. After that I can restart the code and after some time it will throw the same error.

On the single board computers Raspbian Jessie, kernel version 3.4.112 and OWFS 2.9p8 are used. The program runs on Ubuntu 16.04 LTS.

Thank you in advance for your answer.

miccoli commented 7 years ago

You are experiencing a server side-error, i.e. the server replies to your read request with an OWFS error code, in your example with error 22.

It is expected behaviour that the read method raises a OwnetError exception to signal the server-side error, so your code should include some form of error handling, typically within an except clause:

try:
    sensorTemp = float(owproxy0.read(sensor + 'temperature'))
except protocol.OwnetError as err:
    # error handling code here

If the error is only sporadic, may be the best strategy is simply to repeat the read after a small interval of time. (And sorry, I have no clue on what causes a 22 error on owserver.)

miccoli commented 7 years ago

Closing, since this problem is not related to pyownet.