Mysensors / PySerial errors
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...
Which version of pyserial is installed?
pip show pyserial
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..
Which versions of pyserial have you tested?
Looks as it is already reported at pyserial, for version 3:
https://github.com/pyserial/pyserial/issues/59
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 ?
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.
Removed all of 3.0 and installed 2.7. All is fine now. Thanks. I guess we need to keep this issue open?
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.)
A separate script using pyserial does work?
Here I start gateway and reset a node for presentation.

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?
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'
It doesn't seem to be python3 compatible unfortunately.
Install 32bit pyton 3.5.1, pyserial 3.0.1, no errors anymore.
@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.
pyserial 3.1 seems to fix the issue with "ReadFile failed ([WinError 6]"
Thanks! I'll upgrade pymysensors.
Fixed in https://github.com/home-assistant/home-assistant/pull/2917
pymysensors now requires pyserial 3.1.1.