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

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:

    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() ?

    And are the buffers defined like this ?

  • 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

  • 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?

  • That was gonna be my next question, how would I go about using my certificates? I've been reading through the mqtt_simple program and I can't seem to find a way to use certificates. I've also been reading through the asset_tracker code and I guess I don't really understand how the certificates work??

  • You can provision the certificate using nrf_inbuilt_key_write(). Example shown here and here.

    Or use AT command %CMNG, see this link. If you are running the latest LTE link monitor app, there is now a certificate manager that you can use for the AT command approach:

    91dk_at_client_increased_buf.hex

  • My question is more of, what function or what procedure checks the certificate against the value the server is looking for. I have A certificate from azure's iot sdk, but I guess I'm not sure where I would put it or what I would do with it

Reply
  • My question is more of, what function or what procedure checks the certificate against the value the server is looking for. I have A certificate from azure's iot sdk, but I guess I'm not sure where I would put it or what I would do with it

Children
  • octvargas said:
    what function or what procedure checks the certificate against the value the server is looking for

     That is handled by the modem fw (where the TLS(1.2)/DTLS(1.2) and TCP/UDP/IPV4/IPV6 Dual Stack is implemented).

    octvargas said:
    I'm not sure where I would put it or what I would do with it

     I would have tried the method used in e.g. aws_fota sample. Put the certificate in a certificates.h that you create, call provision_certificates() , and configure the MQTT library to be used with TLS. Also set CONFIG_MQTT_LIB_TLS=y in prj.conf, you might also need to set CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

  • Thanks! That helps a lot, I'll try it and report back.

    Thanks again

  • Hi again Sigurd,

    So I think I've got this somewhat sorted out, I added a provision_certificates function, added the baltime root certificate that comes w/ the Azure SDK to certificates.h, and was able to configure the prj file. After some debugging of all that, I'm now stuck on this issue: 

    once I get into the actual loop, my event handler comes back w/ a result of 5 and fails to connect. 

    Any help is appreciated, Thank you

  • What function is returning 5? mqtt_connect() ?

  • mqtt_input in the loop, it calls upon several functions which eventually call the event handler.

    As you can see the switch statement for the event handler returns "MQTT connect failed: %d" with the result value as the return value