Azure / iot-edge-v1

Azure IoT Edge
http://azure.github.io/iot-edge/
Other
524 stars 258 forks source link

Microsoft.Azure.IoT.Gateway/ message content type #505

Open damonbarry opened 6 years ago

damonbarry commented 6 years ago

Copied from Azure/azure-iot-protocol-gateway#114 (@almusawi):

Hi,

I am using Iot hub edge (V1) and it works fine in sending the data. but by using Microsoft.Azure.IoT.Gateway ,the message class, I can not set the content type for the message before sending it to the Iothub. and I can not use the Microsoft.Azure.Devices.Client in the Iot edge model which has in the message class the message.ContentEncoding = "utf-32" and message.ContentType = "application/json";.

Could you please help in that? How to add the content type to a message send by IoT edge model to Iot hub?

Thanks

almusawi commented 6 years ago

Hi, any ideas on this question?

Zuendelmeister commented 6 years ago

Why can't you use the Microsoft.Azure.Devices.Client?

almusawi commented 6 years ago

@Zuendelmeister it does not accepted when you try to publish the message to the broker

Zuendelmeister commented 6 years ago

Well in my knowledge its is like the following: broker message: Microsoft.Azure.IoT.Gateway message to iot hub: Microsoft.Azure.Devices.Client

Hence you have to use both. The ContentType and Encoding on the broker should not be important. And to send it to your IoTHub you can set it in the Microsoft.Azure.Devices.Client.Message.

damonbarry commented 6 years ago

We automatically copy the broker message's properties over to the IoT Hub message. However, we don't map anything into the IoT Hub message's system properties, and I think the content encoding and type are both system properties.

I believe we'd have to make changes to the iothub module, to the function IoTHubMessage_CreateFromGWMessage here: https://github.com/Azure/iot-edge/blob/2018-01-31/v1/modules/iothub/src/iothub.c#L642. When it maps properties between messages, it should look for the content encoding & type properties specifically and map them to system properties.

It sounds like a fairly easy fix, but I don't think the core team will be able to do this work anytime soon. If you'd like to do the work and make a pull request, we'd love to get it integrated into the repo.