Hello,
I am trying to use the nRF9160 DK to publish some sensor data to an Azure IoT Hub. I have been able to successfully connect to the mqtt broker and publish simple strings as an D2C event message, but I am wanting to publish a json structure instead to take advantage of existing handling on our IoT Hub that I am not involved with in terms of development.
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"
}
}
Does anybody more familiar with zephyr's mqtt library or Azure's IoT Hub 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*'.
I included a copy of my project (mqtt_simple.zip), leaving out any specific information about my device or iot hub hostname if it would help anybody. Just find and replace all mentions of '{device-id}' with your proper device-id, replace '{hostname}' with the proper hostname of your iot hub, and replace '{shared-access-token}' with your generated token for your device. Do this for '\src\main.c', '\Kconfig', and '\prj.conf'.
I am using the command-line tool for Azure IoT Hub to monitor events:
In the command to monitor events, replace '{hostname}' with the proper hostname for your IoT Hub and {consumer-group} with a proper consumer group on your IoT Hub.
If I left out any important information that would be helpful, please let me know and I will provide it ASAP.
Thanks!
Isaac