BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: Opportunities of implementing MQTT and their benefits  (Read 612 times)

Vladi

  • Newbie
  • *
  • Posts: 13
    • View Profile
Opportunities of implementing MQTT and their benefits
« on: June 03, 2020, 10:51:48 AM »

Hello guys,

I'm using the MM900EV3A Board with the FT900 microcontroller and I want to implement a MQTT communication between the board and my host computer.
Bridgetk provides an example for implementing MQTT with the lwIP library using freeRTOS.

My question is: What are the bebefits of implementing MQTT together with an RTOS?

During my research for MQTT implementations I found another very common way to implementing MQTT without lwIP and freeRTOS: Using the eclipse paho library for C.
My first impression is that it seems to be easier to implement a mqtt client with paho rather than with lwIP/freeRTOS.
But what is the disadvantage of using a "normal" mqtt library?

I hope you guys can help me understanding this :)
Logged

BRT Community

  • Administrator
  • Full Member
  • *****
  • Posts: 245
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #1 on: June 05, 2020, 04:32:17 PM »

Hello,

Here's some feedback from the author of BRT_AN_041 FT90x-MQTT-Application:

You would still need networking support and some form of low level OS.

mbed and FreeRTOS are providing much the same support.

mbed has support for Ethernet and other stuff but you’d have to port it to FT900.

The advantage is that we have already implemented FreeRTOS, lwIP and mbedTLS in that example.

Maybe other users in the community have more input?

Best Regards,

BRT Community
Logged

Vladi

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #2 on: June 14, 2020, 12:44:31 PM »

Hey,

thanks for the answer.

First I thought it makes it more complex for me to develope my MQTT aplication because I don´t have any experience with RTOS.
But now I figured out that it shall be harder to develope applications when I just use the raw API of lwIP (Bare metal). The API with an RTOS shall be easier for application developement.
Is that correct?
Probably it would be hard to port your MQTT example to bare metral right? So I should just better study how an RTOS works.

One question: Which lwIP-API do you use for your lwIP examples? Is it the Netconn API or the BSD Socket API?

Best regards

Vladi
Logged

BRT Community

  • Administrator
  • Full Member
  • *****
  • Posts: 245
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #3 on: June 17, 2020, 04:45:52 PM »

Hello Vladi,

Quote
One question: Which lwIP-API do you use for your lwIP examples? Is it the Netconn API or the BSD Socket API?

It doesn't use either of them. The MQTT app for lwIP does it.

Best Regards,
BRT Community
Logged

Vladi

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #4 on: July 23, 2020, 03:50:11 PM »

Dear BRT Community,

let's have a look on this callback fuction from the MQTT example:

static void client_mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len)
{
   struct sub_info *subInfo = (struct sub_info *)arg;

   DEBUG_PRINTF("MQTT RECIEVE: %s (%u)\r\n", topic, (unsigned int)tot_len);

   memset(subInfo, 0, sizeof(struct sub_info));

   /* Decode topic string into a user defined reference */
   if(strcmp(topic, TOPIC_CONTROL) == 0)
   {
      subInfo->topic = TOPIC_CONTROL;
   }
   tfp_printf("%d\r\n", __LINE__);
}

I don't get what the intention of the first line of this function is.
When I'm debugging the code then there is a strange number in arg.
However, I tried to just struct sub_info *subInfo; but the result of this is that the microcontroller does a reset after the if condition.

That means this line has a purpose. But what is the purpose of this "arg"? Why does the micorocntroller a reset when not including "= (struct sub_info *)arg;"

I would really appreciate if someone could help me understanding this.
Logged

BRT Community

  • Administrator
  • Full Member
  • *****
  • Posts: 245
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #5 on: July 24, 2020, 04:36:57 PM »

Hello,

This is basic C language. It is called a typecast. More information on this is available online.

Best Regards,
BRT Community
Logged

Vladi

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #6 on: July 29, 2020, 06:42:57 PM »

Hello,

yeah I know this but the question is: Why there is a typecast needed?
In arg there are strange numbers.

Why can't I just let the pointer uninitialized like:
 struct sub_info *subInfo;
subInfo->topic = TOPIC_CONTROL;

Is it because in arg is the adress of the pointer on the heap? And pointers need to have an address where they point to?
Logged

BRT Community

  • Administrator
  • Full Member
  • *****
  • Posts: 245
    • View Profile
Re: Opportunities of implementing MQTT and their benefits
« Reply #7 on: August 10, 2020, 02:20:35 PM »

Hello,

It is a method used in C to allow the passing of arbitrary data (as void *) to a function. The function can then optionally perform actions to determine how to handle the data. In this case a pointer is made to the data which assumes the data is of a particular structure.

The MQTT client in lwIP has an arbitrary argument which is passed to each callback function. This argument can be used to tell between different contexts (e.g. for different MQTT subscriptions etc). This argument is for the callback to mqtt_subscribe where a mqtt_incoming_publish_cb_t is passed. The argument passed to the callback allows the code to work out what to do with the incoming data.

Best Regards,
BRT Community
Logged