Get Online/Offline status for iot thing using iot device client sdk

0

Hello, I was wondering if there's any easy and fast implantation way to get online/offline status in the console as soon as a iot thing comes online or goes offline. Any help is appreciated.

feita há 2 anos1353 visualizações
4 Respostas
1
Resposta aceita

Hi Subham. You may be interested to enable fleet indexing, particularly thing indexing and thing connectivity: https://docs.aws.amazon.com/iot/latest/developerguide/managing-index.html

With that enabled, you can then do searches within the console (Manage->Things->Fleet Indexing->Search). Example queries: https://docs.aws.amazon.com/iot/latest/developerguide/example-queries.html

You can use FleetHub so you have a GUI reporting connection status and last disconnection reason:

https://docs.aws.amazon.com/iot/latest/fleethubuserguide/aws-iot-monitor-user-queries-dashboard.html https://www.youtube.com/watch?v=WIUZ-aBSRzs

Fleet Hub works on top of fleet indexing, so fleet indexing needs to be enabled.

Please also be aware of Lifecycle Events; you can enable these and have AWS IoT Rules that action these events: https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html

profile pictureAWS
ESPECIALISTA
Greg_B
respondido há 2 anos
1

Another option is to use lifecycle events and subscribe with the MQTT test client in the AWS IoT console (or any other MQTT client) to $aws/events/presence/connected/# and $aws/events/presence/disconnected/#. If you want to get messages for a certain client only replace # with the clientId.

KR,

Philipp

AWS
ESPECIALISTA
respondido há 2 anos
0

Hey Greg and Phillip, thank you so much for the answer, it helped a lot. However when i used lifecycle event of connected or disconnected i found that only when the rpi is shutting down i am getting the mqtt message but when the device loses the connectivity i am not. Can you tell me if there's a way to implement this?

respondido há 2 anos
  • There is a keep_alive_secs that can be provided to reduce the time a session is reported as disconnected for situations such as losing connectivity. This can be set during the creating of the base MQTT connection object. Which SDK are you using, we can provide a link to the SDK docs.

  • I think Subham is using Device Client. This uses the CPP V2 SDK default keep alive, which appears to be 20 minutes: https://github.com/awslabs/aws-c-mqtt/blob/main/source/client.c#L40.

    Subham, I think this would be the line to change in device client: https://github.com/awslabs/aws-iot-device-client/blob/main/source/SharedCrtResourceManager.cpp#L346

    For example, to have a keep alive of 30s:

    if (!connection->Connect(config.thingName->c_str(), false, 30))
    

    If you CRTl-C to quit Device Client, it will send a Disconnect and the keep alive won't matter.

0

Thanks all for the inputs, the keep_alive_secs works when the device client is being run via a service. Couple more doubts

  1. I want to use lifecycle events to notify me via SNS which isn't working it keeps saying invalid sql statement when i did `SELECT * from '$aws/events/presence/connected/+'.
  2. The whole implementation seems very very tedious and it would be great to have tutorials for things like this.
respondido há 2 anos
  • Thanks for the help, the rule for notification worked

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas