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

Received an MQTT packet from a not connected client (CONNECT not sent yet) #3564

Closed
paulocabrita-ionos opened this issue Oct 9, 2023 · 2 comments

Comments

@paulocabrita-ionos
Copy link

Dear all,

I'm doing some tests using HONO + DITTO and I'm having an issue. I'm following the C2E Tour and following the instructions. All of them worked fine but when I try to use the MQTT adapter instead of the HTTP. I have 2 exceptions:

2023-10-09 17:32:06,003 ERROR [io.qua.ver.cor.run.VertxCoreRecorder] (vert.x-eventloop-thread-1) Uncaught exception received by Vert.x: java.lang.IllegalStateException: Received an MQTT packet from a not connected client (CONNECT not sent yet)                             ││     at io.vertx.mqtt.impl.MqttServerConnection.checkConnected(MqttServerConnection.java:468)                                                                                                                                                                                    ││     at io.vertx.mqtt.impl.MqttServerConnection.handlePublish(MqttServerConnection.java:361)                                                                                                                                                                                     ││     at io.vertx.mqtt.impl.MqttServerConnection.handleMessage(MqttServerConnection.java:158)                                                                                                                                                                                     ││     at io.vertx.mqtt.impl.MqttServerImpl.lambda$null$1(MqttServerImpl.java:102)                                                                                                                                                                                                 ││     at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55)                                                                                                                                                                                                       ││     at io.vertx.core.impl.ContextBase.emit(ContextBase.java:239)                                                                                                                                                                                                                ││     at io.vertx.core.net.impl.NetSocketImpl.handleMessage(NetSocketImpl.java:390)                                                                                                                                                                                               │
│     at io.vertx.core.net.impl.ConnectionBase.read(ConnectionBase.java:157)                                                                                                                                                                                                      │
│     at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:153)                                                                                                                                                                                                   │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)                                                                                                                                                                   │
│     at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)                                                                                                                                                                                         │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)                                                                                                                                                                   │
│     at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)                                                                                                                                                                               │
│     at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333)                                                                                                                                                                               │
│     at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:349)                                                                                                                                                                                            │
│     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)                                                                                                                                                                                   │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)                                                                                                                                                                   │
│     at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)                                                                                                                                                                        │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)                                                                                                                                                                                 │
│     at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800)                                                                                                                                                    │
│     at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:499)                                                                                                                                                                                              │
│     at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397)                                                                                                                                                                                                       │
│     at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)                                                                                                                                                                             │
│     at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)                                                                                                                                                                                                │
│     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)                                                                                                                                                                                    │
│     at java.base/java.lang.Thread.run(Unknown Source)
2023-10-09 17:32:06,003 ERROR [io.qua.ver.cor.run.VertxCoreRecorder] (vert.x-eventloop-thread-1) Uncaught exception received by Vert.x: java.lang.IllegalStateException: Received an MQTT packet from a not connected client (CONNECT not sent yet)                             │
│     at io.vertx.mqtt.impl.MqttServerConnection.checkConnected(MqttServerConnection.java:468)                                                                                                                                                                                    │
│     at io.vertx.mqtt.impl.MqttServerConnection.handleDisconnect(MqttServerConnection.java:445)                                                                                                                                                                                  │
│     at io.vertx.mqtt.impl.MqttServerConnection.handleMessage(MqttServerConnection.java:200)                                                                                                                                                                                     │
│     at io.vertx.mqtt.impl.MqttServerImpl.lambda$null$1(MqttServerImpl.java:102)                                                                                                                                                                                                 │
│     at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55)                                                                                                                                                                                                       │
│     at io.vertx.core.impl.ContextBase.emit(ContextBase.java:239)                                                                                                                                                                                                                │
│     at io.vertx.core.net.impl.NetSocketImpl.handleMessage(NetSocketImpl.java:390)                                                                                                                                                                                               │
│     at io.vertx.core.net.impl.ConnectionBase.read(ConnectionBase.java:157)                                                                                                                                                                                                      │
│     at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:153)                                                                                                                                                                                                   │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)                                                                                                                                                                   │
│     at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)                                                                                                                                                                                         │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)                                                                                                                                                                   │
│     at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)                                                                                                                                                                               │
│     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)                                                                                                                                                                                   │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 │
│     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)                                                                                                                                                                   │
│     at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)                                                                                                                                                                        │
│     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)                                                                                                                                                                 ││     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)                                                                                                                                                                 ││     at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)                                                                                                                                                                                 ││     at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800)                                                                                                                                                    ││     at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:499)                                                                                                                                                                                              ││     at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397)                                                                                                                                                                                                       ││     at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)                                                                                                                                                                             ││     at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)                                                                                                                                                                                                ││     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)                                                                                                                                                                                    ││     at java.base/java.lang.Thread.run(Unknown Source)

My goal:

  • to send data to the Hono MQTT endpoint and having a DT (from Ditto) changed with the values that are being sent from a Python script.

What I have done:

  • Creation of a new Digital Twin (DT) using the demo tenant of the Tour
  • Sending data to the DT using the Hono HTTP endpoint;
  • Checking if the values of the DT are changed. And yes, it works perfectly;
  • Sending data to the same DT using the Hono MQTT endpoint. I created a json payload with the structure of my DT. When I send the MQTT payload (using a python script), I have the 2 above exceptions and the python script gives no error;

What I have followed:

  • C2E Tour;
  • This python script from the Examples folder of the Ditto Repo. This Repo uses Mosquitto and not Hono;

I'm not sure what is this but I think it's related to this issue: vert-x3/vertx-mqtt#94

Any thoughts?

@sophokles73
Copy link
Contributor

This is not necessarily related to vert-x3/vertx-mqtt#94 but might also have its reason in your client starting to send PUBLISH packets before it has received the CONNACK from Hono. Can you check in your Python MQTT client if you are actually waiting for the CONNACK before sending any data?

@paulocabrita-ionos
Copy link
Author

Yes. You are absolutely right. It was related to the connect stage. I had to put a while loop in order to fix it.

If someone will face this issue, I did the following:

client.connect(broker_ip, MQTT_BROKER_PORT, 60)
while not client.connected_flag: #wait in loop
    print("In wait loop")
    time.sleep(1)

But... I'm facing another issue which I think it's related to a no such endpoint in the mqtt adapter.
I will close this one and open another one.

Thank you very much.

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