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

nRF9160 DK + Azure IoT Hub Direct Method

Hi.

I have several issues when trying to respond to Direct Methods (using v1.4.0 of the SDK):

In azure_iot_hub.c:

evt.data.method.rid = atoi(topic->prop_bag[0].value);

1. rid is not an int, it's a hex value (this affects everything, also sending responses via azure_iot_hub_method_respond). strtol might work, but since this is used when sending responses, it's easier to just keep it as char[] instead.

2. prop_bag[0].value only contains the first char if rid=11 or rid=ab (azure_iot_hub_topic_parse in azure_iot_hub_topic.c does not parse the values in prop_bag correctly)

3. After correcting the above, I'm still not able to get responses when rid has 2 chars.

In azure_iot_hub_method_respond (azure_iot_hub.c) both topic and len is correct (at least it seems that way)

param.message.topic.topic.size = len;
printk("Sending response to: %s\n", topic);
return mqtt_publish(&client, &param);

..but I still get no reply in the other end if rid has more than 1 char.

Any idea what the last, missing part of the puzzle is to send responses when rid has 2 chars?

Parents
  • Hi Loker,

    There is a pending commit here https://github.com/nrfconnect/sdk-nrf/pull/3358 on the Direct Method. 
    Hopefully this will solve your problems

    Regards,
    Jonathan

  • Hi Jonathan, thanks!

    Your commit fixes the two first problems, but not the last problem. There's a bug when mqtt_rx.c is parsing the incoming packet in mqtt_handle_packet. The buffer is not reset between packets. Every time a new Direct Method has a _shorter_ topic than the previous, the last char from the topic in the previous message is still in the buffer and becomes part of the (incorrectly) parsed topic.

    Here is an example:

    This is what mqtt_rx.c is parsing (incorrect):
    Topic: $iothub/methods/POST/Open/?$rid=1
    Topic: $iothub/methods/POST/Close/?$rid=2
    Topic: $iothub/methods/POST/Open/?$rid=32
    Topic: $iothub/methods/POST/Open/?$rid=42
    Topic: $iothub/methods/POST/Close/?$rid=5
    Topic: $iothub/methods/POST/Open/?$rid=65
    Topic: $iothub/methods/POST/Close/?$rid=7
    Topic: $iothub/methods/POST/Open/?$rid=87
    Topic: $iothub/methods/POST/Close/?$rid=9
    Topic: $iothub/methods/POST/Open/?$rid=a9
    Topic: $iothub/methods/POST/Open/?$rid=b9
    Topic: $iothub/methods/POST/Close/?$rid=c

    This is what Azure IoT Hub sent (what mqtt_rx.c should have parsed):
    Topic: $iothub/methods/POST/Open/?$rid=1
    Topic: $iothub/methods/POST/Close/?$rid=2
    Topic: $iothub/methods/POST/Open/?$rid=3
    Topic: $iothub/methods/POST/Open/?$rid=4
    Topic: $iothub/methods/POST/Close/?$rid=5
    Topic: $iothub/methods/POST/Open/?$rid=6
    Topic: $iothub/methods/POST/Close/?$rid=7
    Topic: $iothub/methods/POST/Open/?$rid=8
    Topic: $iothub/methods/POST/Close/?$rid=9
    Topic: $iothub/methods/POST/Open/?$rid=a
    Topic: $iothub/methods/POST/Open/?$rid=b
    Topic: $iothub/methods/POST/Close/?$rid=c

  • Hi, 

    Looking in to the problem and will update you when we have a solution or temporary workaround as soon as possible. 

    Regards,
    Jonathan

  • Hi,

    If the print function is not set up correctly hen this might happen, using the following setup:

    printf("Topic: %.*s\n", evt->topic.len, evt->topic.str);


    should be a functioning solution unless there is something else that does not behave as it should.  If you still have a problem could you provide the code you are using ?

    Regards,
    Jonathan
Reply Children
Related