Description
Hi,
I see there's no option for sending a disconnect packet to broker. This can be useful for sharing same broker connections among clients.
My 2 cents:
In ESP8266MQTTClient.cpp add:
bool MQTTClient::disconnect(void)
{
sendDisconnect();
free(_state.in_buffer);
free(_state.out_buffer);
LOG("[MQTT_client] disconnect!\n");
return true;
}
void MQTTClient::sendDisconnect()
{
_state.outbound_message = mqtt_msg_disconnect(&_state.connection);
_state.pending_msg_type = mqtt_get_type(_state.outbound_message->data);
_state.pending_msg_id = mqtt_get_id(_state.outbound_message->data,
_state.outbound_message->length);
LOG("Sending MQTT_MSG_TYPE_DISCONNECT\r\n");
_transportTraits->write(_tcp.get(), _state.outbound_message->data,
_state.outbound_message->length);
}
And their corresponding function declarations in header file:
bool disconnect();
void sendDisconnect();
Rgds,
Richard