Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange issues with version 0.5.0 #37

Closed
plague-doctor opened this issue Oct 10, 2021 · 3 comments
Closed

Strange issues with version 0.5.0 #37

plague-doctor opened this issue Oct 10, 2021 · 3 comments

Comments

@plague-doctor
Copy link

Yesterday I have updated the version to 0.5.0 and it stopped working. It is throwing errors:

2021-10-10 23:20:52 INFO     Starting modbus4mqtt v0.5.0
2021-10-10 23:20:52 INFO     Connected to MQTT.
2021-10-10 23:20:52 ERROR    Failed to poll modbus device, attempting to reconnect: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus4mqtt.py", line 87, in poll
    self._mb.poll()
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 71, in poll
    values = self._scan_value_range(table, group, self._scan_batching)
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 138, in _scan_value_range
    result = self._mb.read_input_registers(start, count, unit=0x01)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
    return self.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 107, in execute
    if not self.connect():
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 54, in connect
    self._getkey()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 43, in _getkey
    self._setup()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 23, in _setup
    self._aes_ecb = AES.new(self._key, AES.MODE_ECB)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
2021-10-10 23:21:52 ERROR    Failed to poll modbus device, attempting to reconnect: Modbus Error: [Connection] ModbusTcpClient(172.xxx.xxx.xxx:502): Connection unexpectedly closed 0.001899 seconds into read of 25 bytes without response from unit before it closed connection
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus4mqtt.py", line 87, in poll
    self._mb.poll()
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 71, in poll
    values = self._scan_value_range(table, group, self._scan_batching)
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 138, in _scan_value_range
    result = self._mb.read_input_registers(start, count, unit=0x01)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
    return self.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 107, in execute
    if not self.connect():
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 54, in connect
    self._getkey()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 40, in _getkey
    self._key_packet = self._recv(25)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 298, in _recv
    return self._handle_abrupt_socket_close(
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 343, in _handle_abrupt_socket_close
    raise ConnectionException(msg)
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] ModbusTcpClient(172.xxx.xxx.xxx:502): Connection unexpectedly closed 0.001899 seconds into read of 25 bytes without response from unit before it closed connection
2021-10-10 23:22:52 ERROR    Failed to poll modbus device, attempting to reconnect: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus4mqtt.py", line 87, in poll
    self._mb.poll()
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 71, in poll
    values = self._scan_value_range(table, group, self._scan_batching)
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 138, in _scan_value_range
    result = self._mb.read_input_registers(start, count, unit=0x01)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
    return self.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 107, in execute
    if not self.connect():
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 54, in connect
    self._getkey()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 43, in _getkey
    self._setup()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 23, in _setup
    self._aes_ecb = AES.new(self._key, AES.MODE_ECB)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
2021-10-10 23:23:52 ERROR    Failed to poll modbus device, attempting to reconnect: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus4mqtt.py", line 87, in poll
    self._mb.poll()
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 71, in poll
    values = self._scan_value_range(table, group, self._scan_batching)
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 138, in _scan_value_range
    result = self._mb.read_input_registers(start, count, unit=0x01)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
    return self.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 107, in execute
    if not self.connect():
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 54, in connect
    self._getkey()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 43, in _getkey
    self._setup()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 23, in _setup
    self._aes_ecb = AES.new(self._key, AES.MODE_ECB)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

When running directly from console, it is throwing errors but occasionally reads and publishes values. Once every 20-40 minutes.
When running inside container I am still waiting for a single happy read - none so far for over an hour.

I call it like that:

modbus4mqtt --hostname mqtt.mydomain.net --port 1883 --username mqtt_user --password password123 --mqtt_topic_prefix solar --config ./SG5K-D.yaml

Please help, the previous version worked fine...

@tjhowse
Copy link
Owner

tjhowse commented Oct 11, 2021 via email

@tjhowse
Copy link
Owner

tjhowse commented Oct 16, 2021

This should be fixed with v0.5.1. Please update and let me know how you go.

@tjhowse tjhowse closed this as completed Oct 16, 2021
@plague-doctor
Copy link
Author

Works again. Thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants