This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mqtt connect error

Hello, 

So I'm trying to modify the mqtt_simple sample program to connect to azure iot

I've modified the code in a few ways but when I went to run the program it gave me this error

Which from my understanding is a failure to connect w/ the mqtt client

and the mqtt_connect error comes from the mqtt.h/c file which is an error of  ENOMEM (err no memory??) in the tx_buf or the rx_buf

So I manually changed the buffer size in the config file

# General config
CONFIG_TEST_RANDOM_GENERATOR=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# BSD library
CONFIG_BSD_LIBRARY=y

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y

# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=n

# Appliaction
CONFIG_MQTT_PUB_TOPIC="publish"
CONFIG_MQTT_SUB_TOPIC="subscribe"
CONFIG_MQTT_CLIENT_ID="MyCDevice"
CONFIG_MQTT_BROKER_HOSTNAME="MaxusHub.azure-devices.net"
CONFIG_MQTT_BROKER_PORT=11105

# Main thread
CONFIG_MAIN_THREAD_PRIORITY=7
CONFIG_MAIN_STACK_SIZE=4096

CONFIG_HEAP_MEM_POOL_SIZE=1024

# Disable native network stack to save some memory
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=n

#added Configuring of buffer sizes?
CONFIG_MQTT_MESSAGE_BUFFER_SIZE = 128
CONFIG_MQTT_PAYLOAD_BUFFER_SIZE = 128

And once I try to build it, it gives me an out of tree board error

My main question is, would I be able to resolve the -12 mqtt_connect error by adjusting the buffer size? And if so, how would I go about doing that if not in the proj.conf file.

Any help is appreciated, thank you

Octavio

EDIT: I should add, I tried running SES as administrator and that didn't seem to help.

Parents
  • Hi,

    There is some syntax error in your config file, you should remove the space around the = sign, i.e. so it looks like this instead:

    CONFIG_MQTT_MESSAGE_BUFFER_SIZE=128
    CONFIG_MQTT_PAYLOAD_BUFFER_SIZE=128

    would I be able to resolve the -12 mqtt_connect error by adjusting the buffer size?

    It's worth trying, but if you are hitting the ENOMEM shown in the screenshot you attached, then it seems like you are getting the ENOMEM because the buffers are NULL.

    Did you call client_init() before calling mqtt_connect() ?

    	client_init(&client);
    	err = mqtt_connect(&client);

    And are the buffers defined like this ?

    /* Buffers for MQTT client. */
    static u8_t rx_buffer[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
    static u8_t tx_buffer[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
    static u8_t payload_buf[CONFIG_MQTT_PAYLOAD_BUFFER_SIZE];

  • Hi Sigurd, 

    Okay, so I've got my current problems narrowed down to the poll function in main.

    When it returns my fds.revents has a value of 0x10 which apparently means that the poll detected a closed connection?

    How would I go about enabling the socket for readability, or I guess how would I proceed from here?

    Thank you

  • When it returns my fds.revents has a value of 0x10 which apparently means that the poll detected a closed connection?

    How long time does it take before this happens ?

    Could you post the log output from the LTE Link Monitor app terminal ?

    Also, have you configured the certificate ? See this blog post

  • Well, it's a matter of seconds maybe milliseconds as it happens immediately after it enters the endless loop. So when I'm dealing with my test broker that manages to connect here's the state of fds after it enters the endless loop

    as you can see fds.revents is 1, which is the desired value in the third if statement

    however, when I try to use my iothub as a broker it comes back w/ 

    and stays frozen in the endless loop cycle

  • With revents = 0x10, then this seems to be an POLLHUP (Poll detected closed connection, polled socket has been closed by the peer). This could be an certificates issue. Have you added your IoT Hub certificate to the nRF9160?

Reply Children
Related