I am running FreeRTOS 202104.00 on a PIC32MX and currently have a simple tcp project using FreeRTOS_send and FreeRTOS_recv from the FreeRTOS+TCP library.
I would like to create the a simple MQTT client project that connects to a public broker without TLS.
(1) Since I have a working tcp library, do I need to create a transport interface? My quess is that I have to set up the MQTT client to use my existing TCP layer using the sample implementations.
(2) I have studied the multitask demo under the Windows simulator that uses the coreMQTT Agent library, but that seems like overkill for my needs. Once I get the above resolved, should I focus on the MQTT_Plain_Text demo to get a single threaded client connecting to a public broker.
Yes, you do need a transport interface (which is just 2 function pointers) to allow coreMQTT to send and receive data. Here is more documentation and here is an example which should work for you.
Thank you very much Gaurav. The first link seems to present the Transport Interface a little more clearly that what I’ve read elsewhere, so between the two, I should be able to figure things out.
Working from the example under .\coreMQTT_Windows_Simulator\MQTT_Plain_Text I have run into a build error using MPLABX with a PIC32MX.
In file included from ../using_plaintext.h:31:0,
from ../PlaintextMQTTExample.c:67:
../../../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h:222:23: error:
expected '=', ',', ';', 'asm' or '__attribute__' before 'BaseType_t'
Looking at line 222 (static portINLINE …) in FreeRTOS_sockets.h, it looks like this:
/* The socket type itself. */
struct xSOCKET;
typedef struct xSOCKET * Socket_t;
typedef struct xSOCKET const * ConstSocket_t;
static portINLINE BaseType_t xSocketValid( Socket_t xSocket )
{
BaseType_t xReturnValue = pdFALSE;
/*
* There are two values which can indicate an invalid socket:
* FREERTOS_INVALID_SOCKET and NULL. In order to compare against
* both values, the code cannot be compliant with rule 11.4,
* hence the Coverity suppression statement below.
*/
/* coverity[misra_c_2012_rule_11_4_violation] */
if( ( xSocket != FREERTOS_INVALID_SOCKET ) && ( xSocket != NULL ) )
{
xReturnValue = pdTRUE;
}
return xReturnValue;
}
Any thoughts on what might be causing this compile problem? I’m using FreeRTOSv2021004.00 and it included FreeRTOS+TCP v2.3.2.
I am using the MPLAB/PIC32MX port:
…\FreeRTOSv202104.00\FreeRTOS\Source\portable\MPLAB\PIC32MX
The definition of portINLINE in FreeRTOSIPConfigDefaults.h is: #define portINLINE inline
Eliminating portINLINE from line 222 of FreeRTOS_sockets.h did indeed eliminate that build error - although now I have a host of new errors to work on.
I’ll have to check if removing that line broke a previous TCP project though.
It probably means that you do not need to remove this but the actual error is somewhere else. Can you share the complete build log? Can you share your project also?
and suspect that I don’t have my NetworkConext set up correctly. I’ll see if I can figure this out from all of the tips I received and will report back.
Happy to share the build log, but now that it is clean that may not be necessary. If I get stuck, I can upload a zip file of the project as well.
I’m still getting a stack overflow when trying to connect to the server. I am building the project with using_plaintext.c, which includes using_plaintext.h, which includes transport_interface.h. (I have uploaded all three files.)
Using the debugger, I can see that the overflow occurs when calling this function:
It was prvMQTTDemoTask() from PlaintextMQTTExample.c. Increasing it from 200 to 400 words seems to have enabled me to connect with the broker. Onto subscribing.
Success at last! I did have to remove portINLINE from line 222 of FreeRTOS_Sockets.h and increase the stack size of the demo task above the minimum. I used 400 words. Thank you!