monstrenyatko / ArduinoMqtt

MQTT client for Arduino
MIT License
72 stars 12 forks source link

Curly Braces #10

Closed albertlt closed 7 years ago

albertlt commented 7 years ago

Hello. First of all, thanks a lot for publishing the library. Please mark this post as question and I'm sorry if this is a noob question (I am not from C background). While reading your example sketch: ConnectEsp8266WiFiClient.ino, I noticed the following codes in the loop() :

// Start new MQTT connection MqttClient::ConnectResult connectResult; // Connect { MQTTPacket_connectData options = MQTTPacket_connectData_initializer; options.MQTTVersion = 4; options.clientID.cstring = (char*)MQTT_ID; options.cleansession = true; options.keepAliveInterval = 15; // 15 seconds MqttClient::Error::type rc = mqtt->connect(options, connectResult); if (rc != MqttClient::Error::SUCCESS) { LOG_PRINTFLN("Connection error: %i", rc); return; } }

I don't understand what is the meaning of curly braces "without parent" right just below //Connect. As per my understanding, curly braces normally encapsulate code inside if, loop, function declaration, etc. But in your example, it's just simply a pair of curly braces. If I remove the curly braces, the code will also compile fine. I must be missing something, please enlighten me.

Also I am planning to use qos 2. I noticed in the description that this library support "simplified" qos 2. What does it mean? Lastly, is this library stable for production use?

monstrenyatko commented 7 years ago

Hi @albertlt

I use the {...} to highlight the block of the functionality and to request system to release stack used by the variables (like options and rc) when the block is completed and I don't need them anymore.

QoS2 is supported. Client processes and sends all required by QoS2 control messages. But due to the limitations of the platform the persistent is not supported. That is why I called it Simplified QoS2.

albertlt commented 7 years ago

Oh I see, thanks a lot for the explanation. Lastly, is the library stable for production use?

monstrenyatko commented 7 years ago

@albertlt The library is stable enough. I am using it for my pet projects. Messages encoder/decoder is based on Eclipse Paho MQTTPacket library that is very well tested.

If you find an issue please report.

albertlt commented 7 years ago

Great. Will do. Thanks a lot =)

monstrenyatko commented 7 years ago

@albertlt No problem :-) Let me know if you have questions.

albertlt commented 7 years ago

Hello again. I was trying to use this library for communicating with Home Assistant embedded MQTT server. While I could see from Serial that the command was sent correctly, it was not read by Home Assistant. I tried Qos 1 on the PUB and I could see ACK received in terminal, proving that server was responding. However, there might be problem with the topic or payload as receive was not responding. I then tried the PubSubClient by Knolleary and it worked. The Home Assistant server is responding to the client. What could be wrong here?

monstrenyatko commented 7 years ago

@albertlt It could be a problem with your broker. Does the broker support QoS2? Does the pubsubclient publishes with QoS2? Could you please try with test.mosquitto.org broker and share logs with MQTT_LOG_ENABLED defined to 1. If QoS1 publish works fine, that means the communication with the broker is definitely OK.

monstrenyatko commented 7 years ago

@albertlt Did you try QoS2 publishing with test.mosquitto.org broker? In my case, it works well.