Chat freely about anything...

User avatar
By EadF
#11183
biobier wrote:Thanks got it working!
This is my working code snipped in case it can help someone:
Code: Select allint tempSize = sizeof("%d.%d", (int)(lastTemp),(int)((lastTemp - (int)lastTemp)*100));


Sorry to nitpick, but sizeof() does not calculate the lenght of the string as you intend.

In this case it returns the size of a char pointer - 4 bytes.
I think you better use strlen().
User avatar
By myeoman
#11514 @tuanpm: Have you implemented the CONNACK message, in particular the sessionPresent flag as described at http://www.hivemq.com/mqtt-essentials-part-3-client-broker-connection-establishment/ ?

The reason I ask is that I am trying to do the following:
1. Publish message(s) to a broker using qos 1 or 2.
2. When the ESP8266 connects to that broker, pick up those messages that it missed while offline.

Or perhaps there is another way to do this?

[update]: I see that this feature was only introduced in MQTT version 3.1.1 as explained at http://www.hivemq.com/6-facts-why-its-worth-upgrading-to-mqtt-3-1-1/ :

Session Present Flag: If a client connects with a persistent session (which means he doesn’t use a clean session), an additional flag was introduced in the CONNACK message to indicate that the broker already has prior session information of the client like subscriptions, queued messages and other information
User avatar
By myeoman
#11911 Having done some more research, I suspect that you don't need to use the new CONNACK mechanism that I mentioned in the previous post.

Even under MQTT 3.1, when a client reconnects (using the same client id and with cleansession=0), the broker will send any stored messages that were published to that broker with qos>=1, and which were not able to be delivered to the client because it was disconnected.

I have confirmed this works using other clients (e.g. Paho python client https://eclipse.org/paho/clients/python/ and MQTT Inspector for IOS http://jpmens.net/2013/11/19/mqtt-inspector-for-ios/.

Yet, whatever I try, I cannot get it to work using the MQTT client library for ESP8266. Anyone had better luck, or have any ideas?
User avatar
By tuanpm
#11942
myeoman wrote:Having done some more research, I suspect that you don't need to use the new CONNACK mechanism that I mentioned in the previous post.

Even under MQTT 3.1, when a client reconnects (using the same client id and with cleansession=0), the broker will send any stored messages that were published to that broker with qos>=1, and which were not able to be delivered to the client because it was disconnected.

I have confirmed this works using other clients (e.g. Paho python client https://eclipse.org/paho/clients/python/ and MQTT Inspector for IOS http://jpmens.net/2013/11/19/mqtt-inspector-for-ios/.

Yet, whatever I try, I cannot get it to work using the MQTT client library for ESP8266. Anyone had better luck, or have any ideas?


I have not tried it, but I get the message with retain = 1. You can share the code that you use to try?