Search code examples
azure-iot-hub

No ContentType system property on messages sent to IoT hub via MQTT


I want to use IoT hub message routing; according to this azure blog, I have to set the message's ContentType and ContentEncoding to application/json and a supported encoding. I am sending module messages through MQTT and this SO answer says I should use a $.ct=application/json&$.ce=utf-8 url suffix.

I would expect telemetry message {'signalStrength': -19.0} sent to topic devices/E660CCC14B482231/modules/MyModule/messages/events/%24.ct=application%2Fjson&%24.ce=utf-8 to result in an IoT hub message with systemProperties 'content-encoding' and 'content-type' set, yet IoT explorer shows me that neither system properties are set:

{
  "body": {
    "signalStrength": -19
  },
  "enqueuedTime": "Thu Nov 10 2022 13:51:59 GMT-0700 (Mountain Standard Time)",
  "properties": {
    "serialNumber": "E660CCC14B482231"
  },
  "systemProperties": {
    "iothub-connection-device-id": "E660CCC14B482231",
    "iothub-connection-module-id": "MyModule",
    "iothub-connection-auth-method": "{'scope':'module','type':'sas','issuer':'iothub'}",
    "iothub-connection-auth-generation-id": "638006753232047843",
    "iothub-enqueuedtime": 1668113519787,
    "iothub-message-source": "Telemetry",
    "dt-dataschema": "dtmi:MyModule:MyDevice;1",
    "x-opt-sequence-number": 1192144,
    "x-opt-offset": "274899831448",
    "x-opt-enqueued-time": 1668113519865
  }
}

I've tried content types of "application/JSON" and "application/json", tried url-escaping "$.ct" and "$.ce", but I never see content-type and content-encoding show up in the systemProperties.


Solution

  • Sending telemetry to

    devices/E660CCC14B482231/modules/MyModule/messages/events/$.ct=application%2Fjson&$.ce=utf-8
    

    does set ContentType and ContentEncoding, but IoT explorer won't show them as system properties.