Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing disconnect packet option. #12

Open
hdrut opened this issue Apr 20, 2018 · 0 comments
Open

Missing disconnect packet option. #12

hdrut opened this issue Apr 20, 2018 · 0 comments

Comments

@hdrut
Copy link

hdrut commented Apr 20, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant