monitor connection status of local client devices from IoT Core

0

Hey everyone, I am using Greengrass core devices as a MQTT bridge for local devices without connection to AWS IoT core to send data. Besides that I use fleet metrics to monitor the connection status of things against the IoT core but this only gives me the status of core devices or things that are directly connected.

I also want to see which things are connected to which coredevices.

I saw https://github.com/aws-greengrass/aws-greengrass-client-device-auth/issues/55 but I do not really understand how I should do this with device shadows? I added shadow manger as a component and added the the topics to mqtt bridge.

Can someone describe me how this should work?

Best Regards, Marco

Marco
gefragt vor 3 Monaten137 Aufrufe
2 Antworten
2
Akzeptierte Antwort

Hi Marco,

Currently, Greengrass doesn't publish connectivity status for client devices

However, if you're using EMQX as a local broker, you should be able to forward client connect/disconnect events from EMQX using MQTT Bridge:

{
  "mqttTopicMapping": {
    "ClientDeviceConnectedFromEMQX": {
      "topic": "$SYS/brokers/+/clients/+/connected",
      "source": "LocalMqtt",
      "target": "IotCore"
    },
    "ClientDeviceDisconnectedFromEMQX": {
      "topic": "$SYS/brokers/+/clients/+/disconnected",
      "source": "LocalMqtt",
      "target": "IotCore"
    }
  }
}
AWS
beantwortet vor 3 Monaten
profile picture
EXPERTE
überprüft vor 2 Monaten
profile pictureAWS
EXPERTE
Greg_B
überprüft vor 3 Monaten
0

Thanks for your answer, I was finally able to try it out and it works very good. I just had to make an adjustment on the topics. I seems not to work without adding a targetTopicPrefix because you can not forward to $SYS at IoT Core. But I am facing this error on forwarding these connect messages, maybe you can help me resolve that as this is related to the solution and might help others: When a devices connects or disconnects, the event is bridged correctly but I get this error message on the greengrass.log regarding the PUBACK message:

{"thread":"Thread-4","level":"INFO","eventType":null,"message":"Publishing message got a non-retryable reason code, not retrying","contexts":{"reason":"PUBACK:Topic can't start with $:a8e88322-20a1-9d20-5f1a-0709dd166a6d","topic":"$SYS/brokers/emqx@172.17.0.2/clients/demoThing/disconnected","reasonCode":"144"},"loggerName":"com.aws.greengrass.mqttclient.MqttClient","timestamp":1710150964535,"cause":null}
{"thread":"Thread-4","level":"ERROR","eventType":null,"message":"Failed to publish the message via Spooler and will retry","contexts":{"reason":"PUBACK:Topic can't start with $:a8e88322-20a1-9d20-5f1a-0709dd166a6d","reasonCode":"144"},"loggerName":"com.aws.greengrass.mqttclient.MqttClient","timestamp":1710150964535,"cause":null}

This is my topicMapping: for the {iot:thingName}, I also enable interpolateComponentConfiguration in the nucleus config.

"ClientDeviceConnectedFromEMQX": {
                    "topic": "$SYS/brokers/+/clients/+/connected",
                    "targetTopicPrefix": "coreDeviceConnections/{iot:thingName}/",
                    "source": "LocalMqtt",
                    "target": "IotCore"
                },
                "ClientDeviceDisconnectedFromEMQX": {
                    "topic": "$SYS/brokers/+/clients/+/disconnected",
                    "targetTopicPrefix": "coreDeviceConnections/{iot:thingName}/",
                    "source": "LocalMqtt",
                    "target": "IotCore"
                }
Marco
beantwortet vor 2 Monaten
  • Just to double check, did the updated configuration (with targetTopicPrefix) make it to the device? Can confirm with the greengrass cli (e.g. greengrass-cli component list). From the error, it looks like the prefix isn't being appended to the topic

  • Yes I think so, because the in IoT core the message arrives at the correct topic which is coreDeviceConnections/demoCoredevice/$SYS/brokers/emqx@172.17.0.2/clients/demoThing/disconnected.

    I think the problem ist that it is some sending a PUBACK back after fowarding the message and this PUBACK would still go to $SYS/... and this is not allowed. Is this possible? Dont know how to debug that exactly.

    I also tried to use a topic rewrite in EMQX and directly reweite $SYS/brokers/# into /metrics/brokers/# but I had no success. I think they disabled that for $SYS (https://github.com/emqx/emqx/issues/3690)

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen