Closed vera closed 3 years ago
Looking through the file history, I just saw that this feature was included previously but then removed here:
Why was it removed?
Hi,
I will fix this as follows:
const char DisconectErrMsg[] = "%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n";
around line 160:
if (client == nullptr)
{
client = _gateway->getClientList()->getClient(senderAddr);
}
}
if (client != nullptr)
{
log(client, packet, 0);
if (client->isDisconnect() && packet->getType() != MQTTSN_CONNECT)
{
WRITELOG(DisconectErrMsg, ERRMSG_HEADER,
senderAddr->sprint(buf), ERRMSG_FOOTER);
/* send DISCONNECT to the client, if it is not connected */
MQTTSNPacket* snPacket = new MQTTSNPacket();
snPacket->setDISCONNECT(0);
Event* ev1 = new Event();
ev1->setClientSendEvent(client, snPacket);
delete packet;
continue;
}
else
{
ev = new Event();
ev->setClientRecvEvent(client, packet);
packetEventQue->post(ev);
}
}
else
{
/* new client */
if (packet->getType() == MQTTSN_CONNECT)
{
The MQTT-SN spec (v1.2, p. 17) states:
Currently, the gateway only prints an error message but does not react in any other way to incoming messages (e.g. SUBSCRIBE, PUBLISH) that it can't map to a client. For example, this is the case when the client's IP address has changed since the connection was established. Since the client expects a response from the gateway, this leads to the client retransmitting the request and finally timing out (p. 25):
With this change, the gateway sends a DISCONNECT message to the unknown client. The client is then able to re-CONNECT with the new IP address.
(I have not signed the ECA yet. if this is something that could be merged, I will try to get that done.)