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
Websocket connection doesn’t get messages on subscription after terminated reconnect #645
Comments
a) you can definitely use more than just websockets mqtt with that module. even st talks about native mqtt, http rest, anything you like. anyway... b) you seem to be subscribing at qos2, but only publishing at qos 0? If that's the case, messages will not be queued for your subscriber when it goes offline. It's unclear from your logs when you are disconnecting things. I presume you're seeing them disconnect later, after the keepalive, or if you reconnect soon enough, you're seeing that "client xxxx already connected..." line. c) your client is subscribing with what seems to be a fixed clientid, good, but without cleansession set to false, you're also not going to get anything queued for you, even if you fix your qos problem. |
Thank you for your fast answer. I have double checked, the STMicroelectronics Wireless Module SPWF04S does only support MQTT over Websockets:
As next step I have fixed all publishes and subscriptions to QoS 2 but it was still doesn’t working. After I have changed the Fixed ID to a Random ID which I generate each time new, everything seems to work. But I still don’t get it: after the client starts and establishes connection (with clean session and a fixed ID), the client should get new messages (I don’t think and want to talk about persistence) from the subscription. But why does the client don’t get this messages? |
are you having problems gettting messages that were published while you were powered off? That's what I thought the first time. If so, you must have a fixed ID, (NOT random id) and you must NOT have clean session. |
No. I do not receive any messages that were sent after the device was turned on and connected to the server. For a better understanding, I have compiled the following protocol here (please mind the second connection, the first and third is working):
|
I can reproduce this issue. It happen when a new client replace an existing one (i.e. using the same clientid) and cleansession is False. To reproduce this issue, I'm using:
Run the following client:
You will see that the message is only received by first and third client.
On server logs:
If you change TRANSPORT and PORT to "tcp" and 1885, the client will works as expected. I think the issue come because mqtt3_handle_connect will add a duplicate key in contexts_by_id which is not permitted by uthash. |
This behaviour was fixed earlier, but I've now ensured that the old client gets removed from the hash before the duplicate one is added. This will be in 1.5.3. |
Fix duplicate clients being added to by_id hash before the old client was removed. Closes #645.
Fix duplicate clients being added to by_id hash before the old client was removed. Closes #645.
I still have similar problems in 1.5.8 |
I’m using a STMicroelectronics Wireless Module (SPWF04S) as MQTT Websocket Client. This device doesn’t support any other protocol. After the connection is established the Wireless Module does subscribe on the topic
c2d/dev/00000007/
to receive messages from the server which are dedicated to this device. If I now disconnect the device from the mains and connect it again (while this procedure the device doesn’t close the Websocket Connection), the device does again subscribe on the topicc2d/dev/00000007/
but then doesn’t receive any messages from this topic. If I reconnect the device from mains again, the device receives messages. That means every second time I connect the device, the device doesn't receive messages from the broker from this topic. I also can reproduce this fault with a Desktop Websockets MQTT Client when I terminate the executable (sigkill
) instead of normally closing it.I’m using
mosquito 1.4.14
andlibwebsockets 2.4.1
(fresh build today).Here are the logs (with log_type all).
Normal Situation:
Broken Situation:
The Broker does not send the Received PUBLISH from 864e7ddd-89f8-485d-a876-a24e98fe3cef to SPWF04S.
That’s how the connection looks like (always the same):
The text was updated successfully, but these errors were encountered: