How to enable MQTT demo and OTA simultensouly?

Hi,
I am able to achieve AWS freertos MQTT demo running on my platform.
Also, I m able to sepratly run OTA demo in AWS freertos code. It is currently only running OTA agent.

If I updated the MQTT demo using AWS freertos OTA job, it will run MQTT “hello world” demo and disable OTA agent and will not be able to perform the next OTA cycle.

Now my query is how to merge them both in a single application that should not disable either or functionality?

Regards.

Hi,
Can one help me here ?

Regards.

Hi Arjun,

You can call Iot_CreateDetachedThread multiple times in iot_demo_runner.c:

static demoContext_t mqttDemoContext =
{
.networkTypes = democonfigNETWORK_TYPES,
.demoFunction = RunMqttDemo,
.networkConnectedCallback = DEMO_networkConnectedCallback,
.networkDisconnectedCallback = DEMO_networkDisconnectedCallback
};

Iot_CreateDetachedThread( runDemoTask,
&mqttDemoContext,
1U,
democonfigDEMO_STACKSIZE );

static demoContext_t otaDemoContext =
{
.networkTypes = democonfigNETWORK_TYPES,
.demoFunction = vStartOTAUpdateDemoTask,
.networkConnectedCallback = DEMO_networkConnectedCallback,
.networkDisconnectedCallback = DEMO_networkDisconnectedCallback
};

Iot_CreateDetachedThread( runDemoTask,
&otaDemoContext,
0U,
democonfigDEMO_STACKSIZE );

You may need to use a semaphore or some other mechanism depending on how you would like those demos to synchronize.

Hi,

Thank for update i will try and update.
meanwhile I want to understand, what is the use of OTA_UPDATE_DEMO in AWS freeRTOS, updating the OTA_UPDATE_DEMO demo itself, not updating the custom code?

What is the correct way to update my application using OTA_UPDATE_DEMO ?

Do you mean to ask the purpose of OTA demo? If so, it is meant to show how to use the OTA library to remotely update your firmware. Depending on your needs, you can use it as it is or modify it as per your requirements.

Thanks.

So, Lets. If I want to upgrade the AWS any of the demo (i.e. MQTT, SHADOW, ,TCP_ECHO_CLIENT, DEFENDER, GREENGRASS_DISCOVERY) using OTA_UPDATE_DEMO from AWS. How can I upgrade it?

Thanks

I see - so what you are asking is how can you combine 2 demos. Like you want to run both MQTT and OTA. If that is correct, you will need to make some changes:

Hope that helps.

Thanks.

Hi @aggarg

Those links are no longer available with the latest version of the demos.

I would love to have the same MQTT and OTA. I got OTA working with the latest demo, but I don’t know how to get a generic MQTT handler parsing JSON commands from a topic (turn this relay on/off).

What would be the best way to get that working?

Is there any sample project with OTA and MQTT handling?

Hello @phstc!

The demo for OTA over MQTT makes use of both MQTT and OTA. The MQTT agent, created as a task here, can be used for both OTA and MQTT messages. You can then call MQTT-Agent functions to do things like message publication.

As for parsing JSON messages from a topic, you can configure your callback method given for your subscription to parse the JSON message.

As mentioned by @aggarg above, it would be best to run the OTA and MQTT agents as separate tasks. Your JSON send & receive functionality can also be grouped into a separate task.

I hope this helps.

1 Like

@kstribrn thank you! that’s very helpful, I will give it a try.

it would be best to run the OTA and MQTT agents as separate tasks

What do you mean by that? I’m very new to FreeRTOS.

We’re all beginners at some point :slight_smile:

In the demo, the OTA agent and MQTT agent are already both individual tasks. This allows the MQTT manager to handle synchronization of what’s being sent and by whom. For example the MQTT agent might be sending a JSON message (like the one you’d like to handle) while the OTA Agent has requested to send a message which is turn queued to only send after the JSON message is sent successfully. Synchronization - one of the features of the MQTT agent - is important because it prevents two send or receive requests from clashing and causing problems.

In your case - running separate tasks will keep both your OTA, MQTT, and JSON messaging functionality cleaner, easier to maintain, and able to better utilize processor time.

For more on tasks, I’d highly recommend reading our getting started guide on the subject. Tasks and how they are scheduled are one of the most key concepts of what makes an RTOS what it is.

1 Like