Arm Mbed OS support forum

Azure Example - Message Encoding

Hi There.

I have been playing with the Azure example provided by Mbed (love it btw) and have got to the stage where I can successfully trigger MS Logic Apps from message events sent by my Nucleo Dev Board.

I am facing a bit of a challenge now, because the messages appear to be sent from the device using Base64 encoding, and I can’t seem to find out where/how to change that to UTF-8. Azure Apps natively use UTF-8, and so to streamline events in Azure, messages need to get there in UTF-8, otherwise I would probably need to build an Azure Function App just to change the encoding, before moving on with my workflow.

Any ideas on where that might be changed in the Mbed side?

Many thanks.

In case this is a little too vague, here is the example I am using: “mbed-os-example-for-azure”

I can see a header file named “azure_base64.h” in the directory mbed-client-for-azure → copied → c-utility → azure_c_shared_utility, however I can find no reference to its use.

All message headers and metadata arrives at Azure in utf-8, except the actual message body, which is in Base64. I can find no mention of encoding being implemented (maybe that’s the issue?). It doesn’t appear that the JSON data ending up in Azure has the message format defined either.

Perhaps if someone can point me to where the ContentType and ContentEncoding are set?


I have found the solution.

        sprintf(message, "{\"msg\":{\"date\":\"%s\",\"data\":{\"a\":%d,\"b\":%d,\"c\":%d}}}",buffer,1,2,3);       
        LogInfo("Sending: %s", message);

        message_handle = IoTHubMessage_CreateFromString(message);
        IoTHubMessage_SetContentTypeSystemProperty(message_handle, "application%2fjson");

Setting encoding is not enough, as it will still reach Azure in Base64. You also need to set ContentType.

I tried this initially as “application/json”, which failed. I later found a source which expressed it as “application%2fjson” which works.