ESP8266 - MQTT - Dropped a Packet

Dear Home Assistant Experts,

I am just building a basic ESTP12E kit to detect photocell (ADC) pin0 and trigger the LED GPIO13.
I am using arduino IDE to program and using below libs:
#include <ESP8266WiFi.h>
#include “Adafruit_MQTT.h”
#include “Adafruit_MQTT_Client.h”

I have subscribe to onOffSwitch and I am publishing to the same feed when the sensor has value lower than particular value. I am monitoring using serial monitor and after every successful publish to feed onOffSwitch I have immediate subscription read of feed onOffSwitch in the loop. I am getting below ERROR, I have tried delay of 10000 and the problem still persists.

Dropped a Packet

(Note that I am not using Qos, shall I use Qos to avoid the packet drops)

Is there anything wrong, I am doing? can someone has any working example?

I will share the code soon.

Regards,
Pankaj

https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels

There’s really no reason anymore to not use QOS 2. For ‘smart devices’ it makes much more sense to use it. For things like weather stations or non interactive things then it’s fine to go 0, but for on/off stuff or anything where getting the message is important go 2.

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();
}

}

Any recommendation from experts?

Can you copy and paste your error, and format your code using the instructions in the big blue box at the top of the page. Then someone might have a chance at seeing what is going on.