eclipse / paho.mqtt.embedded-c

Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)
https://eclipse.org/paho
Other
1.36k stars 753 forks source link

Example of connect with willFlag=1 #47

Closed evandavey closed 8 years ago

evandavey commented 8 years ago

I've searched the examples but can't find any that has a last will and testament. The code below generates a rc=-1 with MQTTSerialize_connect failing.

char willTopic[100] = "/device/";
strcat(willTopic,username);
strcat(willTopic,"/shadow/update");

MQTTPacket_connectData data = MQTTPacket_connectData_initializer;     
data.MQTTVersion = 3;
data.clientID.cstring = (char*) username;
data.username.cstring = (char*) username;
data.password.cstring = (char*) password;
data.cleansession = 1;
data.keepAliveInterval = 30;
data.will.message.cstring = (char*) "{\"connected\":false}";
data.will.topicName.cstring = (char*) willTopic;
data.willFlag = 1;

// this will call the read and write functions of the cellular code
int rc = _client->connect(data);
if (rc != 0) {
    ERROR(F("MQTT connect error: %d"),rc);
    return false;
} 
evandavey commented 8 years ago

I've managed to narrow this down to being a problem with the topicName. Turns out the max payload size needs to be increased.