aws-mqtt
aws-mqtt copied to clipboard
mqttClient.end() result with clientInitiatedDisconnect = False
We have a rule for unplanned disconnections for our IoT devices And its picking up our automation which uses this Lib We use the .end to disconnect the client after it finished its job (under each handler) Which result with this JSON on the disconnection:
{
"clientId": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"timestamp": 1460065214626,
"eventType": "connected",
"sessionIdentifier": "00000000-0000-0000-0000-000000000000",
"principalIdentifier": "000000000000/ABCDEFGHIJKLMNOPQRSTU:some-user/
ABCDEFGHIJKLMNOPQRSTU:some-user",
"clientInitiatedDisconnect": false
}
This is how we setup each client :
`var mqttClient = this.AWSIoTData.device({
region: this.regionData,
host:this.host,
clientId: this.myclientId,
protocol: 'wss',
maximumReconnectTimeMs: 8000,
debug: true,
accessKeyId: cards.Data.AccessKeyId,
secretKey: cards.Data.SecretAccessKey,
sessionToken: cards.Data.Token });`
how can we close and kill a client with "clientInitiatedDisconnect": true ? Or is it a bug?
If I understand this correctly, your clients are connecting using https://github.com/aws/aws-iot-device-sdk-js and another (automation?) server is listening to the lifecycle events using aws-mqtt
library.
I would look closer in aws-iot-device-sdk-js
module to see if you are correctly terminating connection. Or use last will and testament to differentiate when and how client disconnected.
https://medium.com/devicepilot/monitoring-aws-iot-connections-9f2b43c99cf8