Hi Forsquirel,
I have tried QOS2 but still the packets are failing, I have enabled DEBUG and the serial monitor is as below:
Sending sensorValue val 35…MQTT publish packet:
0 [0x30], [0x19], [0x00], [0x15], b [0x62], u [0x75], c [0x63], h [0x68],
a [0x61], d [0x64], e [0x65], _ [0x5F], p [0x70], / [0x2F], f [0x66], e [0x65],
e [0x65], d [0x64], s [0x73], / [0x2F], i [0x69], n [0x6E], p [0x70], u [0x75],
t [0x74], 3 [0x33], 5 [0x35],
Client sendPacket returned: 27
OK!
MQTT publish packet:
4 [0x34], [0x1B], [0x00], [0x15], b [0x62], u [0x75], c [0x63], h [0x68],
a [0x61], d [0x64], e [0x65], _ [0x5F], p [0x70], / [0x2F], f [0x66], e [0x65],
e [0x65], d [0x64], s [0x73], / [0x2F], o [0x6F], n [0x6E], o [0x6F], f [0x66],
f [0x66], [0x00], [0x04], O [0x4F], N [0x4E],
Client sendPacket returned: 29
Read data: P [0x50],
Packet Type: P [0x50],
Read data: [0x02],
Packet Length: 2
Read data: [0x00], [0x04],
Publish QOS1+ reply: P [0x50], [0x02], [0x00], [0x04],
Failed
MQTT ping packet:
⸮ [0xC0], [0x00],
Client sendPacket returned: 2
Read data: ⸮ [0xD0],
Packet Type: ⸮ [0xD0],
Read data: [0x00],
Packet Length: 0
here is main loop is that help you to spot any error:
void loop() {
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();
// this is our ‘wait for incoming subscription packets’ busy subloop
// try to spend your time here
Adafruit_MQTT_Subscribe *subscription;
mqtt.processPackets(1000);
sensorValue = analogRead(A0);
if(lastSensorValue!= sensorValue){
lastSensorValue = sensorValue;
Serial.print(F("\nSending sensorValue val “));
Serial.print(sensorValue, DEC);
Serial.print(”…");
if (! input_p.publish(sensorValue)) {
Serial.println(F(“Failed”));
} else {
Serial.println(F(“OK!”));
delay(3000);
if(sensorValue<60){
if (! onoffbutton_p.publish(“ON”)) {
Serial.println(F(“Failed”));
} else {
Serial.println(F(“OK!”));
}
}
}
delay(1000);
}
// ping the server to keep the mqtt connection alive
if(! mqtt.ping()) {
mqtt.disconnect();
}
}