NCS 3.0.2 azure iot hub publish telemetry for bad topic

Hi,

I generated the credentials as described on the webpage, but az_iot_hub_client_telemetry_get_publish_topic always returned devices/<some garbage characters> and I got the error mqtt_helper: Cloud MQTT input error: -128, followed by a disconnect.

I add "snprintf(topic, sizeof(topic), "devices/%s/messages/events/", CONFIG_AZURE_IOT_HUB_DEVICE_ID);" after the function call to force the topic name, and now it works. But if there is a better solution, I would appreciate it.

Best regards

Mate

Parents
  • Hello,

    I got the error mqtt_helper: Cloud MQTT input error: -128, followed by a disconnect.

    #define NRF_ENOTCONN 128        /**< The socket is not connected */

    after the function call to force the topic name, and now it works. But if there is a better solution, I would appreciate it.


    I will need to ask internally to get an answer from our experts. While we wait for an answer from them, could you please provide full logs from the device? Modem traces might be good here as well to see if there is an issue with your certificates. 

    Thanks.

    Kind regards,
    Øyvind

Reply
  • Hello,

    I got the error mqtt_helper: Cloud MQTT input error: -128, followed by a disconnect.

    #define NRF_ENOTCONN 128        /**< The socket is not connected */

    after the function call to force the topic name, and now it works. But if there is a better solution, I would appreciate it.


    I will need to ask internally to get an answer from our experts. While we wait for an answer from them, could you please provide full logs from the device? Modem traces might be good here as well to see if there is an issue with your certificates. 

    Thanks.

    Kind regards,
    Øyvind

Children
  • I forgot to mention that's an NRF5340+NRF7002 device

  • Hello,

    here is the response I got from our team:

    This sounds more like a memory corruption issue. Please ask the customer about how they store their device ID and pass it in to the azure_iot_hub_connect() function. If the device ID is a non-static stack variable, it may have been overwritten by the time it is used.

    Please provide more details.

    Kind regards,
    Øyvindf1

  • Ok I find the problem was I store the ID in non static variable in the init function and now works fine, but I got the following warning in build time, is this normal?

    [544/665] Building C object modules/nrf/subsys/net/lib/mqtt_helper/CMakeFiles/..__nrf__subsys__net__lib__mqtt_helper.dir/mqtt_helper.c.obj
    In function 'broker_init',
    inlined from 'client_connect' at C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
    inlined from 'mqtt_helper_connect' at C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:410:46: warning: array subscript 'struct sockaddr_in6[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
    410 | broker6->sin6_family = addr->ai_family;
    | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: object 'broker' of size 20
    32 | static struct sockaddr_storage broker;
    | ^~~~~~
    In function 'broker_init',
    inlined from 'client_connect' at C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
    inlined from 'mqtt_helper_connect' at C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:411:44: warning: array subscript 'struct sockaddr_in6[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
    411 | broker6->sin6_port = htons(CONFIG_MQTT_HELPER_PORT);
    C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    C:/ncs/v3.0.2/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: object 'broker' of size 20
    32 | static struct sockaddr_storage broker;
    | ^~~~~~


    Best regards,
    Mate

Related