CoreMQTT: Can't find where the network buffer gets allocated

Hello FreeRTOS Forums!

I’m playing around with the message size in MQTT, (seeing if I can send large messages 2GB ish) and the error I’m facing is that the assert:

assert( pContext->networkBuffer.pBuffer != NULL );

get called. I’ve struggles to see where this is allocated, any tips and that would really help.

See below snippet for exactly where the assert is from.

static MQTTStatus_t receivePacket( const MQTTContext_t * pContext,
MQTTPacketInfo_t incomingPacket,
uint32_t remainingTimeMs )
{
MQTTStatus_t status = MQTTSuccess;
int32_t bytesReceived = 0;
size_t bytesToReceive = 0U;

assert( pContext != NULL );
assert( pContext->networkBuffer.pBuffer != NULL );

Kind regards,
Dyfan

@Dyfan

The network buffer gets initialized/allocated to the MQTTContext_t during the MQTT_Init call. For example, in the case of MQTT_Mutual_Auth demo it’s done here.

In this case, the network buffer is statically allocated here.

2 Likes

@tony-josi-aws

Thanks for the speedy reply!

If I wanted to increase the MQTT messages that are received on the micrcontroller end, about 2GB would I have to increase this buffer and ipconfigTCP_RX_BUFFER_LENGTH to 2G?

Cheers!

@Dyfan

The ipconfigTCP_RX_BUFFER_LENGTH sets the size of the circular stream buffer for the TCP data reception used by the FreeRTOS+TCP stack. Its value can be set depending on how much RAM you have on your device; its default value, if not overridden in FreeRTOSIPConfig.h, is ( 4 * ipconfigTCP_MSS ).

Theoretically this should be the maximum size you could expect to receive from the FreeRTOS_recv. If you are increasing ipconfigTCP_RX_BUFFER_LENGTH please make sure to increase the size of the network buffer thats given to the MQTT_Init, democonfigNETWORK_BUFFER_SIZE in the example referred above.

@tony-josi-aws

Having increased both to 2GB about 11300 comes through, is there any other variables that need increasing?

Are you trying to send or receive messages? Your question says you are trying to send but the snippets are referring to receiving messages?

If you are receiving the packet I would suggest you set a breakpoint here where the packet is incoming, and then step through and see where it is failing. With that much data you are probably ending up timing out somewhere and not running out of space.

This line should be asking for 2GB of data, and as you can see before this you would have generated an error here if you asked for more data than the length of the network buffer (if buffer was too small in other words).

The actual reading of the data happens on this line, so in your debugger you should be able to follow it from here.

@cobusve I am trying to receive messages. If you could point out where I’m referencing sending messages I’m happy to edit it to make it clearer.

The links that you send me refer to the function receivePacket, however the path that this message come via the receiveSingleIteration. I’m essentially using the plaintext demo code is this where I might be going wrong? should I replace it with receivePacket?

I’ve stepped through the code, and all the variables are as expected but the data is just short. I can’t see any errors being flagged anywhere. Thanks for the previous help and I’ll appreciate anymore suggestions.

Step into this function and see how much data is being received?

1 Like