Buffer allocation failure on aws_iot_connect

Board: nRF7002DK

I extended the WiFi proviosing example of nRF7002 and added the aws part from aws_iot example. WiFi connection and IP allocation along with DNS resolution all working fine.
But during the TLS handshake there is buffer allocation failure resulting in TLS handshake failure. I am not able to find the exact root cause for this failure. 
Can anyone help me out to find what need to be fixed?


Following are the error codes I am facing
00> [00:00:16.697,143] <dbg> aws_iot: broker_init: IPv4 Address found 52.57.145.200
00> [00:00:16.697,296] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (0x2000bb20): Created socket 7
00> [00:00:17.098,937] <err> net_pkt: Data buffer (68) allocation failed.
00> [00:00:17.099,029] <err> net_sock_tls: TLS handshake error: -4e
00> [00:00:17.101,257] <err> aws_iot: mqtt_connect, error: -113
00> [00:00:17.101,257] <err> aws_iot: AWS broker connect failed -113

Following are the memory configs I have in my project

# Memories
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096
CONFIG_NET_MGMT_EVENT_STACK_SIZE=8192
CONFIG_NET_TCP_WORKQ_STACK_SIZE=4096
CONFIG_NET_BUF_RX_COUNT=10
CONFIG_NET_BUF_TX_COUNT=10
CONFIG_NET_BUF_DATA_SIZE=128
CONFIG_HEAP_MEM_POOL_SIZE=153600
CONFIG_NET_TC_TX_COUNT=2
CONFIG_NET_PKT_RX_COUNT=20
CONFIG_NET_PKT_TX_COUNT=20
  • Hi

    The data buffer allocation errors are likely because your NET packet buffers are set up too low, and you should try to increase these. Can you try setting up the network settings optimized for performance as shown here: https://github.com/nrfconnect/sdk-nrf/blob/v2.3.0-rc1/samples/wifi/shell/overlay-zperf.conf#L3-L8 

    Try that and see if the error message changes at all on your end please.

    Best regards,

    Simon

  • Setting the values as in shell example cause the RAM to overflow.
    I had to update the configs as below to resolve the overflow.  But still I am facing the issue shown below.

    CONFIG_NET_PKT_RX_COUNT=32
    CONFIG_NET_PKT_TX_COUNT=40
    CONFIG_NET_BUF_RX_COUNT=32
    CONFIG_NET_BUF_TX_COUNT=73
    CONFIG_NET_BUF_DATA_SIZE=1100
    CONFIG_HEAP_MEM_POOL_SIZE=140000


    LOGS:
    00> [00:00:21.477,966] <dbg> aws_iot: broker_init: IPv4 Address found 18.194.49.107
    00> [00:00:21.478,088] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (0x2000b860): Created socket 7
    00> [00:00:21.672,210] <err> aws_iot: mqtt_connect, error: -12


    Error Code:
    #define  ENOMEM 12   /* Not enough space */

  • Hi

    Seems like you haven't set them to the exact values from the Github link I provided, so just to confirm, do you also see the same error message with the following values as well?

    CONFIG_NET_PKT_RX_COUNT=32
    CONFIG_NET_PKT_TX_COUNT=48
    CONFIG_NET_BUF_RX_COUNT=32
    CONFIG_NET_BUF_TX_COUNT=96
    CONFIG_HEAP_MEM_POOL_SIZE=170000
    CONFIG_NET_BUF_DATA_SIZE=1100

    You can also try to increase the size of CONFIG_NRF_MODEM_LIB_HEAP_SIZE to avoid this MQTT error. The ENOMEM error from mqtt_connect is usually seen when there are no sockets available for it, so can you show us the prj.conf and main.c files of your project if that doesn't help either?

    Best regards,

    Simon

Related