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

How can I dynamically assign the MQTT broker address?

How can I dynamically assign the MQTT broker address

Hi all, I have a general question how to assign the MQTT broker address dynamically. Current Nordic IoT-SDK mqtt examples assign the mqtt broker address at compile time. What would be the best ( or standardized) way to implement a dynamic configuration for the nrf51.

Possible solutions:

  • add an additional service and configure it over BLE via Smart-phone.
  • or connect the nrf51 to border router and configure it over IPv6

Does anybody know which is the best solution? Thanks !

  • What about using DNS? There is a DNS query example in the IoT SDK to obtain the ipv6 address of a given host name. You can have a look at this example and try to incorporate this in to your project.

    EDIT

    I think you are left with the two solutions you write in your question. Either add an additional GATT service and configure it over BLE using a smart phone, or configure it over ipv6 from a server. Which one is the best depends on your application.

    If you choose to use BLE you can have a look at the commissioning demo in the IoT SDK. In this demo you first connect to the device with a smart phone and an app which writes to the flash on the chip which configures the advertising packets, so that the router recognizes the device and connects to it. You can use this example as a base and try to get it to change the broker address stored in flash instead.

    If you want to configure it after the router has connected and then with a server over ipv6, you can write your own simple protocol that runs on UDP, or you can try to implement SNMP (Simple Network Management Protocol) on the IoT device. Unfortunately, we don't have any examples for this.

  • Thanks for the answer. But with the DNS I have still the same problem, because I have to set the host name static at compile time. But I would like that the user can choose the hostname or ipV6 address to use his preferred Mqtt broker. For example if you design mqtt sensors and give them away to customers which want to integrate these sensors to there IOT platform. So the customer should be able to configure his mqtt broker without compiling the firmware. What would be good solution for managing this configuration process with BLE.

  • Hello,

    May I understand what is your use case to change the broker address without connecting the session again? Remember that TCP is point to point and associates IP address and port with the data endpoint, not just the port number. If you acknowledge this, then best way to dynamically connect to a broker is to disconnect using the API mqtt_disconnect and then connect to the new broker address (essentially treat it as new broker) using mqtt_connect API.

    Hope this helps!

    Regards, Krishna

Related