I am using PubSubClient.h to connect with AWS IoT and it worked fine with shadow topics with the following line
while (!virtual_thing.connect(virtual_thing_name.c_str())){
}
when I tried to do the same for Last Will and Testament topic with the following line , it failed with -4 MQTT state
while (!virtual_thing.connect(virtual_thing_name.c_str(), NULL, NULL, "theEndTopic", 1, true, "offline")){
}
exactly, where is the issue lying ??
J-M-L
February 13, 2024, 10:17am
2
error 4 in MQTT usually relates to "Connection Refused: Bad username or password" but are you getting this from the PubSubClient library or from the server?
WiFiClientSecure espClient;
PubSubClient virtual_thing(espClient);
this works
espClient.setTrustAnchors(&cert);
espClient.setClientRSACert(&client_crt, &key);
virtual_thing.setServer(MQTT_HOST, MQTT_PORT);
virtual_thing.setCallback(parse);
virtual_thing.setBufferSize(2048);
virtual_thing.setKeepAlive(120);
//const char* mqttUsername = NULL;
//const char* mqttPassword = NULL;
const char* willTopic = "/last/will/topic";
uint8_t willQoS = 1;
bool willRetain = true;
const char* willMessage = "Offline";
bool cleanSession = true;
while (!virtual_thing.connect(virtual_thing_name.c_str())){
//while (!virtual_thing.connect(virtual_thing_name.c_str(),NULL,NULL,willTopic,willQoS,willRetain,willMessage,cleanSession)) {
Serial.print(virtual_thing.state());
Serial.print(".");
delay(1000);
}
this too works
espClient.setTrustAnchors(&cert);
espClient.setClientRSACert(&client_crt, &key);
virtual_thing.setServer(MQTT_HOST, MQTT_PORT);
virtual_thing.setCallback(parse);
virtual_thing.setBufferSize(2048);
virtual_thing.setKeepAlive(120);
//const char* mqttUsername = NULL;
//const char* mqttPassword = NULL;
const char* willTopic = "/last/will/topic";
uint8_t willQoS = 1;
bool willRetain = true;
const char* willMessage = "Offline";
bool cleanSession = true;
//while (!virtual_thing.connect(virtual_thing_name.c_str())){
while (!virtual_thing.connect(virtual_thing_name.c_str(),NULL,NULL/*,willTopic,willQoS,willRetain,willMessage,cleanSession*/)) {
Serial.print(virtual_thing.state());
Serial.print(".");
delay(1000);
}
but this is not working
espClient.setTrustAnchors(&cert);
espClient.setClientRSACert(&client_crt, &key);
virtual_thing.setServer(MQTT_HOST, MQTT_PORT);
virtual_thing.setCallback(parse);
virtual_thing.setBufferSize(2048);
virtual_thing.setKeepAlive(120);
//const char* mqttUsername = NULL;
//const char* mqttPassword = NULL;
const char* willTopic = "/last/will/topic";
uint8_t willQoS = 1;
bool willRetain = true;
const char* willMessage = "Offline";
bool cleanSession = true;
//while (!virtual_thing.connect(virtual_thing_name.c_str())){
while (!virtual_thing.connect(virtual_thing_name.c_str(),NULL,NULL,willTopic,willQoS,willRetain,willMessage,cleanSession)) {
Serial.print(virtual_thing.state());
Serial.print(".");
delay(1000);
}
it shows - 2 in serial monitor
J-M-L
February 13, 2024, 5:18pm
4
Buffersize manipulation is not working.
Those guys in github left for ESP32 instead of solving for ESP8266
J-M-L
February 14, 2024, 7:55am
6
I suggest opening a GitHub issue then
Thanks for reaching out. I found the solution.
last will and testament message has to be in proper json
Because of the malformed message, aws iot didn't get connected in my case.
J-M-L
February 15, 2024, 4:02pm
8
Thanks for sharing the solution
system
Closed
August 13, 2024, 4:03pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.