Skip to content

Can't get disconnected info when internet disconnection #32

Closed
@handgear

Description

@handgear

Hello,
Is there a way to get disconnect info when internet is off-line?
I'm trying to get connected status in loop by MQTT::Client->isConnected() and AWSWebSocketClient->connected().

In normal case it send & receive heartbeat(?) once a minute.

[WS][0][sendFrame]` ------- send massage frame -------
[WS][0][sendFrame] fin: 1 opCode: 2 mask: 1 length: 2 headerToPayload: 0
[WS][0][sendFrame] pack to one TCP package...
[write] n: 8 t: 186387
[WS][0][sendFrame] sending Frame Done (9153us).

[WS][0][handleWebsocketWaitFor] size: 2 cWsRXsize: 0
[readCb] n: 2 t: 186421
[WS][0][handleWebsocketWaitFor][readCb] size: 2 ok: 1
[WS][0][handleWebsocket] ------- read massage frame -------
[WS][0][handleWebsocket] fin: 1 rsv1: 0 rsv2: 0 rsv3 0  opCode: 2
[WS][0][handleWebsocket] mask: 0 payloadLen: 2
[readCb] n: 2 t: 186436

When the internet is off-line, after about 1min, it send below and never send it again.
(situation pretend sudden disconnection after normal state)

[WS][0][sendFrame] ------- send massage frame -------
[WS][0][sendFrame] fin: 1 opCode: 2 mask: 1 length: 2 headerToPayload: 0
[WS][0][sendFrame] pack to one TCP package...
[write] n: 8 t: 246673
[WS][0][sendFrame] sending Frame Done (9062us).

In this situation(off-line), MQTT::Client->isConnected() and AWSWebSocketClient->connected() are both true during loop.
It actually detects the disconnection after the internet recovered.

log after internet recovered:

[WS-Client] connection lost.
[WS-Client] client disconnected.
[WS-Client] connect wss...
[WS-Client] connected to qwertyqwerty.iot.ap-northeast-2.amazonaws.com:443.
[WS-Client][sendHeader] sending header...
[WS-Client][sendHeader] handshake GET /mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=qwertyqwerty%2Fqwertyqwerty%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20180108T061032Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=qwertyqwerty HTTP/1.1
Host: qwertyqwerty.iot.ap-northeast-2.amazonaws.com:443
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: qwertyqwerty==
Origin: file://
User-Agent: arduino-WebSocket-Client

[write] n: 535 t: 456279
[WS-Client][sendHeader] sending header... Done (58594us).

in this point MQTT::Client->isConnected() == true, AWSWebSocketClient->connected() == false in loop

458176 - conn: 2 - (13376)
[WS][0][handleWebsocket] clientDisconnect code: 1000
[WS-Client] client disconnected.
[WS-Client] connect wss...
[WS-Client] connected to qwertyqwerty.ap-northeast-2.amazonaws.com:443.
[WS-Client][sendHeader] sending header...
[WS-Client][sendHeader] handshake GET /mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=qwertyqwerty%2Fap-northeast-2%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20180108T061800Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=qwertyqwerty HTTP/1.1
Host: qwertyqwerty.iot.ap-northeast-2.amazonaws.com:443
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: qwertyqwerty==
Sec-WebSocket-Protocol: mqtt
Origin: file://
User-Agent: arduino-WebSocket-Client

and after this, it init webSocket and connect MQTT

Is there a way to get disconnect info when internet is off-line?


I tried with latest eclipse/paho.mqtt.embedded-c (release vertion 1.1.0)
wonder this was my case(eclipse-paho/paho.mqtt.embedded-c@5509124)

interestingly with this MQTTClient.h, MQTT::Client->isConnected() is false after MQTT connection.
So it reconnect session after every 1min.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions