- Newest
- Most votes
- Most comments
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"
}
}
}
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"
}
Relevant content
- Accepted Answerasked 2 years ago
- Accepted Answerasked 21 days ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago
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)