Client mqtt python connect to the OpenRemote MQTT broker

Hi
Create an assent according to the links:


From a raspberry using python I am trying to connect to the mqtt api but it is not possible.

python code:

def connect(mqtt_client, mqtt_username, mqtt_password, broker_endpoint, port):
39 global connected
40
41 if not mqtt_client.is_connected():
42 mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
43 # mqtt_client.tls_set(ca_certs=TLS_CERT_PATH)
44 mqtt_client.on_connect = on_connect
45 mqtt_client.on_publish = on_publish
46 mqtt_client.tls_set(ca_certs=TLS_CERT_PATH, certfile=None,
47 keyfile=None, cert_reqs=ssl.CERT_REQUIRED,
48 tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
49 mqtt_client.tls_insecure_set(False)
50 mqtt_client.connect(broker_endpoint, port=port)
51 mqtt_client.loop_start()
52
53 attempts = 0
54
55 while not connected and attempts < 5: # Wait for connection
56 print(connected)
57 print(“Attempting to connect…”)
58 time.sleep(1)
59 attempts += 1
60
61 if not connected:
62 print("[ERROR] Could not connect to broker")
63 return False
64
65 return True

error screen:

python3 mqtt-ssl-openremote.py
False
Attempting to connect…
False
Attempting to connect…
False
Attempting to connect…
False
Attempting to connect…
False
Attempting to connect…
[ERROR] Could not connect to broker
Traceback (most recent call last):
File “mqtt-ssl-openremote.py”, line 95, in
main(mqtt_client)
File “mqtt-ssl-openremote.py”, line 83, in main
if not connect(mqtt_client, MQTT_USERNAME,
File “mqtt-ssl-openremote.py”, line 46, in connect
mqtt_client.tls_set(ca_certs=TLS_CERT_PATH, certfile=None,
File “/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py”, line 838, in tls_set
self.tls_set_context(context)
File “/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py”, line 746, in tls_set_context
raise ValueError(‘SSL/TLS has already been configured.’)
ValueError: SSL/TLS has already been configured.

the manager log presents the following error:

2021-08-18 15:30:45.132 INFO [nioEventLoopGroup-3-4 ] io.moquette.broker.NewNettyMQTTHandler : Closed client channel due to exception in processing,
2021-08-18 15:30:53.195 INFO [nioEventLoopGroup-3-1 ] oquette.broker.metrics.MQTTMessageLogger : C->B CONNECT ,
2021-08-18 15:30:53.195 SEVERE [nioEventLoopGroup-3-1 ] io.moquette.broker.NewNettyMQTTHandler : Error processing protocol message: CONNECT,
java.lang.ArrayIndexOutOfBoundsException: 1,
at org.openremote.manager.mqtt.KeycloakAuthenticator.checkValid(KeycloakAuthenticator.java:52),
at io.moquette.broker.MQTTConnection.login(MQTTConnection.java:236),
at io.moquette.broker.MQTTConnection.processConnect(MQTTConnection.java:161),
at io.moquette.broker.MQTTConnection.handleMessage(MQTTConnection.java:68),
at io.moquette.broker.NewNettyMQTTHandler.channelRead(NewNettyMQTTHandler.java:58),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357),
at io.moquette.broker.metrics.MQTTMessageLogger.channelRead(MQTTMessageLogger.java:46),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357),
at io.moquette.broker.metrics.MessageMetricsHandler.channelRead(MessageMetricsHandler.java:50),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357),
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324),
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357),
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357),
at io.moquette.broker.metrics.BytesMetricsHandler.channelRead(BytesMetricsHandler.java:51),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357),
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379),
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365),
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919),
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166),
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719),
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655),
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581),
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493),
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989),
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74),
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30),
at java.lang.Thread.run(Thread.java:748),
2021-08-18 15:30:53.197 INFO [nioEventLoopGroup-3-1 ] io.moquette.broker.NewNettyMQTTHandler : Closed client channel due to exception in processing

any help

1 Like

Your Python code is malformed. Can you attach a file or use preformatted text?

This is el file
mqtt-ssl-openremote.py.txt (2.6 KB)

When I use a windows client, communication is established, it is possible to subscribe to assent, but it is not possible to publish. because I don’t know which clientid should be used in the communication mqtt, user and password (token) is correct

@Don or @Michael can you help?

I think @Michael can. He will be back on Monday, maybe he can find the time to take a look.

Hi @btula,

Sorry for the late reply. Are you still experiencing this issue?

The code is updated in the meanwhile, so I suggest updating to the latest version of OpenRemote and checking the wiki again: https://github.com/openremote/openremote/wiki/User-Guide%3A-Manager-APIs

Best Regards,
Michael

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.