matthijsvisser / kamstrup-402-mqtt

This project provides a Python library that enables communication with the Kamstrup Multical 402 heat meter. The configured parameters will be read from the meter at a certain interval and published in MQTT messages.
MIT License
45 stars 11 forks source link

Stuck on "AttributeError: 'kamstrup' object has no attribute 'serial'" #5

Closed coolnr closed 2 years ago

coolnr commented 2 years ago

Hi Matthijs, i followed steps in your git and am trying to get everything but I am stuck now. It seems there is something wrong with my serial connection. Hope you can direct me in the right way? I am not a python/linux expert...

I am quite sure my USB is connected to ttyUSB0 as I can see from dmesg : FTDI USB Serial Device converter now attached to ttyUSB0

But when I add ttyUSB0 to config.yaml and I run the script with python3 daemon.py & I get this mesage:

File "/root/kamstrup-402-mqtt/daemon.py", line 92, in <module> main() File "/root/kamstrup-402-mqtt/daemon.py", line 89, in main daemon.run() File "/root/kamstrup-402-mqtt/daemon.py", line 81, in run values = self.heat_meter.run() File "/root/kamstrup-402-mqtt/kamstrup_meter.py", line 104, in run if self.serial.is_open: AttributeError: 'kamstrup' object has no attribute 'serial'

matthijsvisser commented 2 years ago

Hi,

Are you sure that you've installed PySerial and not Serial? pip show pyserial Should return something like this: Name: pyserial Version: 3.4

coolnr commented 2 years ago

Yes I am very sure. Allready checked it before, also did a uninstall and install again.

Here is what pip show pyserial returns:

Name: pyserial Version: 3.5 Summary: Python Serial Port Extension Home-page: https://github.com/pyserial/pyserial Author: Chris Liechti Author-email: cliechti@gmx.net License: BSD Location: /usr/local/lib/python3.9/dist-packages Requires: Required-by:

matthijsvisser commented 2 years ago

Does pip show serial return anything?

I would expect a stacktrace in the debug.log file if there are any problems with declaring the serial port object. Can you paste those contents? tail -f debug.log -n 50

coolnr commented 2 years ago

Pip show serial gives package not found

What perhaps could be the issue is that something with USB passtrough is not going right. I have installed this on a container in Proxmox. I will dive into this as well.

Here is my tail -f debug.log -n 50 output:

`root@warmtemeting:~/kamstrup-402-mqtt# tail -f debug.log -n 50 During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/kamstrup-402-mqtt/kamstrup_meter.py", line 92, in init self.serial = serial.Serial( File "/usr/local/lib/python3.9/dist-packages/serial/serialutil.py", line 244, in init self.open() File "/usr/local/lib/python3.9/dist-packages/serial/serialposix.py", line 325, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0' [2022-03-02 20:54:39 daemon.py init: 41 - INFO - initializing daemon] [2022-03-02 20:54:39 mqtt_handler.py connect: 43 - INFO - Connected to MQTT at: 192.168.1.254:1883] [2022-03-02 20:54:39 mqtt_handler.py connect: 45 - INFO - with username ***, QoS level = 0 and retain = False] [2022-03-02 20:54:39 kamstrup_meter.py init: 100 - ERROR - [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'] Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/serial/serialposix.py", line 322, in open self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/kamstrup-402-mqtt/kamstrup_meter.py", line 92, in init self.serial = serial.Serial( File "/usr/local/lib/python3.9/dist-packages/serial/serialutil.py", line 244, in init self.open() File "/usr/local/lib/python3.9/dist-packages/serial/serialposix.py", line 325, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0' [2022-03-02 21:02:01 daemon.py init: 41 - INFO - initializing daemon] [2022-03-02 21:02:01 mqtt_handler.py connect: 43 - INFO - Connected to MQTT at: 192.168.1.254:1883] [2022-03-02 21:02:01 mqtt_handler.py connect: 45 - INFO - with username ***, QoS level = 0 and retain = False] [2022-03-02 21:02:01 kamstrup_meter.py init: 100 - ERROR - Could not configure port: (25, 'Inappropriate ioctl for device')] Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/serial/serialposix.py", line 398, in _reconfigure_port orig_attr = termios.tcgetattr(self.fd) termios.error: (25, 'Inappropriate ioctl for device')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/kamstrup-402-mqtt/kamstrup_meter.py", line 92, in init self.serial = serial.Serial( File "/usr/local/lib/python3.9/dist-packages/serial/serialutil.py", line 244, in init self.open() File "/usr/local/lib/python3.9/dist-packages/serial/serialposix.py", line 332, in open self._reconfigure_port(force_update=True) File "/usr/local/lib/python3.9/dist-packages/serial/serialposix.py", line 401, in _reconfigure_port raise SerialException("Could not configure port: {}".format(msg)) serial.serialutil.SerialException: Could not configure port: (25, 'Inappropriate ioctl for device')`

coolnr commented 2 years ago

hi @matthijsvisser , i reinstalled everything in a VM (instead of container). And now it's working! So problem was USB passthrough to Debian container, even when USB is listed.....

Thanks for your help, i can now enjoy your work!

image

matthijsvisser commented 2 years ago

Awesome, nice job. Don't forget to star the project for updates!