Hello @wagnerr13,
Reviewing with another colleague it looks like this could be related to how an MQTT call back is fired when a message is received.
Rather then doing the following as shows in some old examples.
public void callMqttEvent(int event) {
// When a message is received through a subscribed topic,
// the function callMqttEvent is called
try {
MqttMessage msg;
msg = readMessage();
if (msg != null) {
String str = new String(msg.getPayload(), "UTF-8");
System.out.println("MQTT Message Received: " + str);
}
} catch (Exception e) {
System.out.println("Error callMqttEvent: " + e.toString());
}
}
You would want to do the following:
public void callMqttEvent(int event) {
// When a message is received through a subscribed topic,
// the function callMqttEvent is called
try {
if (event == 1) {
// MQTT connection event
} else {
// Incoming MQTT messageShareTagsOverTalk2M
MqttMessage msg;
msg = readMessage();
if (msg != null) {
String Message = new String(msg.getPayload(), "UTF-8");
Log.addLog("Incoming message : " + Message, Log.info);
msg.close();
}
}
} catch (Exception e) {
Log.addLog("Error callMqttEvent: " + e.toString(), Log.error);
}
}
}
Here, we check if it is a Connection up/down event or an incoming message event before reading the message.