core icon indicating copy to clipboard operation
core copied to clipboard

Mysensors / PySerial errors

Open sander76 opened this issue 10 years ago • 18 comments

Moving from my old rpi to my new rpi2 (with jesse installed). The home assistant log shows the following error:

Exception in thread Thread-12:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/home/pi/.homeassistant/lib/mysensors/mysensors.py", line 249, in run
    if self.serial is None and not self.connect():
  File "/home/pi/.homeassistant/lib/mysensors/mysensors.py", line 230, in connect
    timeout=self.timeout)
  File "/home/pi/.homeassistant/lib/serial/serialutil.py", line 171, in __init__
    self.open()
  File "/home/pi/.homeassistant/lib/serial/serialposix.py", line 311, in open
    self._update_dtr_state()
  File "/home/pi/.homeassistant/lib/serial/serialposix.py", line 605, in _update_dtr_state
    fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
OSError: [Errno 22] Invalid argument

I guess it has to do with connecting to the serial port. When I manually connect to the serial port using pyserial (/dev/ttyMySensorsGateway) all is well. Doing the same from withing Home assistant it produces the above error. Not sure how to start solving this...Any help appreciated...

sander76 avatar Jan 09 '16 20:01 sander76

Which version of pyserial is installed?

pip show pyserial

MartinHjelmare avatar Jan 09 '16 20:01 MartinHjelmare

Just upgraded to version 3 hoping it will solve things, but unfortunately it does not. When I just connect using pyserial in a separate script it does work..

sander76 avatar Jan 09 '16 20:01 sander76

Which versions of pyserial have you tested?

MartinHjelmare avatar Jan 09 '16 20:01 MartinHjelmare

Looks as it is already reported at pyserial, for version 3:

https://github.com/pyserial/pyserial/issues/59

MartinHjelmare avatar Jan 09 '16 20:01 MartinHjelmare

Ok Thanks. Just installed pyserial version 2.7

sudo pip install pyserial==2.7

Version 2.7 is now installed property.

But now I'm a bit confused. when going to

~/.homeassistant/lib

it still shows

pyserial-3.0.dist-info

So I guess home assistant is still using version 3.0. Or am I wrong ?

sander76 avatar Jan 09 '16 21:01 sander76

You can try uninstalling pyserial with pip, then remove any leftovers manually, then reinstall the pyserial version you want to try. You will probably have to repeat this step any time you upgrade homeassistant, since it seems to want to install pyserial 3.

Hopefully the bugs in pyserial 3 will be ironed out quickly, cause I think it comes with solutions for some older bugs also, so I was looking forward to this release. It's still very new, and a major release, so I guess it was more or less expected to bring some new critters.

MartinHjelmare avatar Jan 09 '16 21:01 MartinHjelmare

Removed all of 3.0 and installed 2.7. All is fine now. Thanks. I guess we need to keep this issue open?

sander76 avatar Jan 10 '16 08:01 sander76

Try pyserial 2.7, 3.0.1 get the same result. Windows 8.1, 64bit pyton 3.5.1, mysensors dev branch. Any ideas?

mysensors: gateways: - port: 'COM5' persistence_file: 'found_mysensors.json' baud_rate: 115200 debug: true persistence: true version: '1.5' optimistic: 'true'

Gateway output: 0;255;3;0;14;Gateway startup complete.

Console error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\logging\__init__.py", line 982, in emit
    stream.write(msg)
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 466-473: character maps to <undefined>
Call stack:
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\mysensors\mysensors.py", line 345, in run
    LOGGER.exception('Serial exception')
Message: 'Serial exception'
Arguments: ()
ERROR:mysensors.mysensors:Serial exception
Traceback (most recent call last):
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\mysensors\mysensors.py", line 341, in run
    line = self.serial.readline()
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\serial\serialwin32.py", line 236, in read
    raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
serial.serialutil.SerialException: ReadFile failed ([WinError 6] \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0434\u0435\u0441\u0
43a\u0440\u0438\u043f\u0442\u043e\u0440.)
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\mysensors\mysensors.py", line 341, in run
    line = self.serial.readline()
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\serial\serialwin32.py", line 236, in read
    raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
serial.serialutil.SerialException: ReadFile failed ([WinError 6] \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0434\u0435\u0441\u0
43a\u0440\u0438\u043f\u0442\u043e\u0440.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\logging\__init__.py", line 982, in emit
    stream.write(msg)
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 466-473: character maps to <undefined>
Call stack:
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
  File "c:\users\bazis\appdata\local\programs\python\python35\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\mysensors\mysensors.py", line 345, in run
    LOGGER.exception('Serial exception')
Message: 'Serial exception'
Arguments: ()
ERROR:mysensors.mysensors:Serial exception
Traceback (most recent call last):
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\mysensors\mysensors.py", line 341, in run
    line = self.serial.readline()
  File "C:\Users\bazis\AppData\Roaming\.homeassistant\lib\serial\serialwin32.py", line 236, in read
    raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
serial.serialutil.SerialException: ReadFile failed ([WinError 6] \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0434\u0435\u0441\u0
43a\u0440\u0438\u043f\u0442\u043e\u0440.)

bazis avatar Mar 31 '16 21:03 bazis

A separate script using pyserial does work?

sander76 avatar Apr 01 '16 04:04 sander76

Here I start gateway and reset a node for presentation. image

bazis avatar Apr 01 '16 19:04 bazis

Googling indicates this could be a problem with win 64 ctypes on python and a pyserial bug after this kind of exception was reported and fixed in pyserial 2.5.

You could try pyserial 2.4. If that version works you should report this to pyserial, to get some info on why this has resurfaced.

It's strange why it works out of home assistant, though. Are you sure you're using the same pyserial lib in both cases?

MartinHjelmare avatar Apr 01 '16 23:04 MartinHjelmare

I'm new in pyton, so debug is hard, I cant even install it.

C:\Windows\System32>pip3 install pyserial==2.4
Collecting pyserial==2.4
  Using cached pyserial-2.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\bazis\AppData\Local\Temp\pip-build-hn2t_6ty\pyserial\setup.py", line 5
        print "standart distutils"
                                 ^
    SyntaxError: Missing parentheses in call to 'print'

bazis avatar Apr 02 '16 08:04 bazis

It doesn't seem to be python3 compatible unfortunately.

MartinHjelmare avatar Apr 02 '16 09:04 MartinHjelmare

Install 32bit pyton 3.5.1, pyserial 3.0.1, no errors anymore.

bazis avatar Apr 02 '16 12:04 bazis

@sander76 Could you test the latest release of pyserial (3.1) and see if that fixes this issue compared to pyserial 3.01? A fix for this error was previously merged in master at pyserial and is included in pyserial 3.1.

If pyserial 3.1 fixes this problem, I will upgrade pymysensors to use 3.1.

MartinHjelmare avatar Jun 02 '16 17:06 MartinHjelmare

pyserial 3.1 seems to fix the issue with "ReadFile failed ([WinError 6]"

blaatunga avatar Jun 27 '16 06:06 blaatunga

Thanks! I'll upgrade pymysensors.

MartinHjelmare avatar Jun 27 '16 09:06 MartinHjelmare

Fixed in https://github.com/home-assistant/home-assistant/pull/2917

pymysensors now requires pyserial 3.1.1.

MartinHjelmare avatar Sep 03 '16 14:09 MartinHjelmare