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

I am trying to use the nRF9160 DK as a gateway to send sensor data to an Azure IoT Hub for further handling.

I was previously using Particle to solve this problem, and they provided a simple webhook service that basically did all of the work for me in integrating the device=>cloud connections to Azure.

I have seen a few different threads with people trying to accomplish this, but I haven't come across a decent start to finish guide for working specifically with Azure IoT Hub.

I have tried adapting a few different mqtt examples to connect to our IoT Hub, but seem to be pretty far over my head working with this dk compared to using Particle hardware.

I am not involved with the setup of the IoT Hub, but it is already configured to receive http PATCH requests from Particle's backend.

If anyone could point me in a good direction to get my dk talking with the azure iot hub, it would be much appreciated.

If I left out any information that is relevant to my question, please let me know and I will provide it ASAP.

Thanks!

Parents
  • Hello,

    I don't have much experience working with Azure, but in principle it should be similar to other cloud backends. I assume you have configured some sort of endpoint on Azure with an URL or ip address that you want to connect to. You should change MQTT_BROKER_HOSTNAME in Kconfig to match the hostname of your Azure endpoint. You probably also need to configure the mqtt_simple project to use TLS connection, and provision certificates from Azure to the device. If you're unsure how to do that, let me know so I can guide you.

    You should also read the Microsoft Azure documentation on how to communicate with devices over mqtt.

    I hope this was helpful, and ask if you have more questions.

Reply
  • Hello,

    I don't have much experience working with Azure, but in principle it should be similar to other cloud backends. I assume you have configured some sort of endpoint on Azure with an URL or ip address that you want to connect to. You should change MQTT_BROKER_HOSTNAME in Kconfig to match the hostname of your Azure endpoint. You probably also need to configure the mqtt_simple project to use TLS connection, and provision certificates from Azure to the device. If you're unsure how to do that, let me know so I can guide you.

    You should also read the Microsoft Azure documentation on how to communicate with devices over mqtt.

    I hope this was helpful, and ask if you have more questions.

Children
  • Thanks for the reply!

    I've actually gotten the mqtt_simple example to connect to my IoT Hub now.

    I've actually been dealing with a new, more specific problem with publishing data (device-to-cloud). I can publish data and see the event on our IoT Hub, but the IoT Hub is already configured to receive a json payload. I tried formatting the outgoing message into something more json-esque using line breaks and such, but when I see the message come in, it includes the escape character ('\') that I was trying to use for line breaks and quotation marks.

    I have successfully recieved this d2c message:

    {
        "event": {
            "origin": "{device-id}",
            "payload": "a"
        }
    }

    I want this:

    {
        "event": {
            "origin": "{device-id}",
            "payload": {
                "published_at": "XXXX-XX-XXXXX:XX:XX.XXXX",
                "device_id": "{device-id}",
                "data": "0.710180:1.796526:48.254000:58.799999:988.430000",
                "event": "demo"
            }
        }
    }

    But I am getting this:

    {
        "event": {
            "origin": "{device-id}",
            "payload": "{\n\"published_at\": \"XXXX-XX-XXXXX:XX:XX.XXXX\",\n\"device_id\": \"{device-id}\"\n,\"data\":\"0.710180:1.796526:48.254000:58.799999:988.430000\",\n\"event\": \"demo"
        }
    }

    Do you know what my options would be for formatting my message going into the mqtt_publish_param in mqtt.h? I feel like my hands are tied since the program is configured to send messages composed as type 'u8_t*'.

    Let me know if I should make a separate ticket for the new question.

  • This looks like it could be a parsing issue. I'm not sure this can be solved by formatting differently on the client side, but it might be possible. You should make a separate ticket for this question.

Related