This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

AWS IoT library and access to mqtt topics

Greets,

I'm using the aws_iot library atop an nRF9160 successfully to connect and interact with AWS services. 

The aws_iot_evt_handler_t callback is triggered when messages arrive, but it is passed a pointer to struct aws_iot_evt which is of little use.

The library handles parsing of topics of interest (e.g. for FOTA) but then only calls the client code callback with the payload, whereas the, pretty crucial (at least in our application), topics are hidden away in underlying layers.

At this point, I've hacked the struct aws_iot_evt to add a pointer to the raw struct mqtt_evt, and added code in aws_iot.c mqtt_evt_handler() to actually assign it, so that in my handler I can actually do stuff with

  evt->mqtt->param.publish.message.topic

So, this solution works but is ugly, and will stop working as soon as we update the SDK.

My question is: since the aws_iot is gobbling up and masking the topics, there must be some mechanism that I am not seeing--what is it?  What is the recommended approach for using aws_iot while actually leveraging the full spectrum of MQTT functions, namely get ahold of topics?

Thanks,

P

Parents Reply Children
  • No worries! From the information you have provided, it looks like your on a fairly updated master branch from before Easter. 

    I forwarded your solution to one of our R&D engineers and he confirms the issue. If the workaround works for you, then please use this for now. The engineer informs that your request has been added to the todo list, and a solution will be added in a future release. 

    Kind regards,
    Øyvind

  • Ok, great.  If R&D can implement a cleaner solution than mine, that would be awesome.  Access to

    param.publish.message.topic

    isn't just verbose, it's "dangerous"...

    mqtt_evt_param being a union, you have tread carefully when accessing members (e.g. the size of the topic can easily be non-zero if the param is being used as something else) and you windup with trouble.

    Short version, some kind of safe accessor for the topics would be nice.

    In any case, thanks.

Related