locked
IOT-Hub appends String to Device2Cloud Message making it invalid RRS feed

  • Question

  • Hello,

    I noticed something strange. I have two different IOT-HUBS and a Simple default MQTT-Client with a static VALID JSON-String and depending on to which IOT-Hub I am sending, I get either VALID or INVALID Data. 

    IOT-HUB that is working:

    Working IOT-HUB

    Not Working IOT-HUB:

    Not Working IOT-Hub

    I could not figure out where the Properties:'readpipe':'' is coming form but I definitely do not have this in my Client Code. 
    Is there some kind of setting or configuration on the IOT-Hub responsible for this ?

    Thank you in advance.

    Kind Regards

    Shehata


    Friday, April 27, 2018 7:13 AM

Answers

  • - I can see in your Logs:

       2018-05-03T07:26:38.557 [Info] readpipe =

    you didn't mention who published this message, from your code or Azure IoT Hub Tester.

    Note, that the MQTT Device sends a D2C message via the device-facing endpoint topic such as:

       devices/{deviceID}/messages/events

    there is no way for Azure IoT Hub to use a custom topic for MQTT protocol. Sending a custom properties is via the topic, for instance:

       devices/{deviceID}/messages/events/readpipe=abcd

    you can use an Azure IoT Hub Tester to see how can be sent properties on the topic. It is interesting, that your Logs shows an empty property readpipe, what can not be done via the device-facing endpoint. In other words,

       devices/{deviceID}/messages/events/readpipe=

    will not show an empty properties in the D2C message, because the value of the properties can not be empty or null. 

    Note, that the Azure IoT Hub is not a generic MQTT Broker, you have to follow its implementation described in the Using the MQTT protocol directly.

    Thanks

    Roman




    Thursday, May 3, 2018 1:38 PM

All replies

  • Hello Shehata,

    Have you checked that whether there is a property named 'readpipe' added to the message, like following in your code?

    message.Properties.Add("readpipe", string.Empty);

    I don't believe that the same code runs with different result.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 30, 2018 2:33 AM
  • Hello Micheal,

    Thank you for your quick response.

    This was the first thing I checked, but the only this that I am changing is the Connection String to the IOT-HUB. 
    I am not adding any additional properties to my message. 

    Here is a snippet from the part in my code where I create the message and send it to the IOT-Hub.

    The only think changing in this Code is the fbMqttClient Connection string and on the IOT-Hubs I get two different Results depending on the IOT-Hub.

    KR

    Haroun

    Monday, April 30, 2018 7:32 AM
  • Hello Haroun,

    It is indeed strange. There are some questions to be confirmed: 

    1.What are the locations of the two IoT Hub?

    2.Can you provide the device twin properties of the the devices(BBG-Friggi1 & Demo_1)?

    3.What tool do you use to receive the messages? Is it a customized tool or Device Explorer downloaded from GitHub?

    4.Can you capture the logs all about the messages published from the mqtt client?

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 1, 2018 2:53 AM
  • Hello Michael,

    1. The Location of the both of the IoT-Hub are West Europe 

    2. We changed the Demo_1 device but the Error still remains

    3. We use the Device Explorer downloaded from the Github?

    4. I am using TwinCat 3 to programm a Beckhoff device and unfortunatly no deep logging is avaible for the MqttClient.

    Kind Regards,

    Haroun

    Wednesday, May 2, 2018 7:28 AM
  • Hi Shehata,

    - try to use MQTTBox client to prove your issue or Azure IoT Hub Tester to simulate a mqtt device using a direct MQTT protocol to the Azure IoT Hub. 

    Thanks

    Roman



    • Edited by Roman Kiss Wednesday, May 2, 2018 3:29 PM
    Wednesday, May 2, 2018 1:05 PM
  • Hello Roman,

    I have tested it with Azure IoT Hub Tester and it seems to work.

    

    Another Finding of mine :
    I have connected an asa-job to the iot-hub that takes all the messages and writes them into a blob storage, while the Device Explorer still displays wrong messages the content of the blob storage file contains valid JSON messages. 

    I can not pinpoint the Error Source, either it is with the MqttClient or with the Iot-Hub or maybe with the Device Explorer.

    Kind Regards,

    Haroun Shehata

    Wednesday, May 2, 2018 2:25 PM
  • - you can eliminate a Device Explorer by Azure IoTHubTrigger function. The following code snippet shows its implementation:

    using System;
    
    public static void Run(string myIoTHubMessage, IDictionary<string, object> properties, IDictionary<string, object> systemproperties, TraceWriter log)
    {
        log.Info($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");
        foreach (var prop in properties)
            log.Info($"\t{prop.Key} = {prop.Value}");
    
        foreach (var prop in systemproperties)
            log.Info($"\t{prop.Key} = {prop.Value}");
    }

    and the function.json file:

    {
      "bindings": [
        {
          "type": "eventHubTrigger",
          "name": "myIoTHubMessage",
          "direction": "in",
          "path": "yourIoTHub",
          "connection": "yourIoTHubconnection",
          "consumerGroup": "yourconsumerGroup"
        }
      ],
      "disabled": false
    }
    Notice, that the function is using own consumer group to avoid a balancing within the Default consumers, such as a Device Explorer. In other words, go to the Azure IoT Hub to add a new consumer group for the above function.

    The Logs panel of the azure function will show all D2C messages from the Azure IoT Hub. You can see also all properties. This is a raw iot device message.

    Thanks

    Roman



    • Edited by Roman Kiss Wednesday, May 2, 2018 3:30 PM
    Wednesday, May 2, 2018 3:28 PM
  • Hello,

    Sorry for my late response I have implemented the Azure Function and the same error appears in the logs, here you can see it.

    2018-05-03T07:26:38.557 [Info] Function started (Id=4214a84d-a79d-4f3d-a4bc-f353508243fa)
    2018-05-03T07:26:38.557 [Info] C# IoT Hub trigger function processed a message: {"Timestamp": "2018-05-03T10:19:10.507077200Z","Tag":"Klappe3_2","Value":"73.0105263157895","Unit":"%","Terminal":"8","Channel":"2","Status":"OK" }
    2018-05-03T07:26:38.557 [Info] readpipe =
    2018-05-03T07:26:38.557 [Info] iothub-connection-device-id = bb-vm1
    2018-05-03T07:26:38.557 [Info] iothub-connection-auth-method = {"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}
    2018-05-03T07:26:38.557 [Info] iothub-connection-auth-generation-id = 636281057145204197
    2018-05-03T07:26:38.557 [Info] iothub-enqueuedtime = 5/3/2018 7:26:38 AM
    2018-05-03T07:26:38.557 [Info] iothub-message-source = Telemetry
    2018-05-03T07:26:38.557 [Info] x-opt-sequence-number = 40057872
    2018-05-03T07:26:38.557 [Info] x-opt-offset = 3281387308288
    2018-05-03T07:26:38.557 [Info] x-opt-enqueued-time = 5/3/2018 7:26:38 AM
    2018-05-03T07:26:38.557 [Info] EnqueuedTimeUtc = 5/3/2018 7:26:38 AM
    2018-05-03T07:26:38.557 [Info] SequenceNumber = 40057872
    2018-05-03T07:26:38.557 [Info] Offset = 3281387308288
    2018-05-03T07:26:38.557 [Info] Function completed (Success, Id=4214a84d-a79d-4f3d-a4bc-f353508243fa, Duration=0ms)

    I have tested my code with a Mosquitto broker 

    KR, 

    Haroun

    Thursday, May 3, 2018 7:48 AM
  • - I can see in your Logs:

       2018-05-03T07:26:38.557 [Info] readpipe =

    you didn't mention who published this message, from your code or Azure IoT Hub Tester.

    Note, that the MQTT Device sends a D2C message via the device-facing endpoint topic such as:

       devices/{deviceID}/messages/events

    there is no way for Azure IoT Hub to use a custom topic for MQTT protocol. Sending a custom properties is via the topic, for instance:

       devices/{deviceID}/messages/events/readpipe=abcd

    you can use an Azure IoT Hub Tester to see how can be sent properties on the topic. It is interesting, that your Logs shows an empty property readpipe, what can not be done via the device-facing endpoint. In other words,

       devices/{deviceID}/messages/events/readpipe=

    will not show an empty properties in the D2C message, because the value of the properties can not be empty or null. 

    Note, that the Azure IoT Hub is not a generic MQTT Broker, you have to follow its implementation described in the Using the MQTT protocol directly.

    Thanks

    Roman




    Thursday, May 3, 2018 1:38 PM
  • Hello Roman,

    I think i found the issue, I changed the publish topic from 'devices/bb-vm1/messages/events/readpipe' to 'devices/bb-vm1/messages/events/'. 

    And when I tried to test it with another IOT-HUB I just changed the ConnectionString and left the Topics the same and because there was no device 'bb-vm1' in the other IOT-Hub it took the default topic. Does this sound right ?

    Thanks you all for your help sorry to have bothered you with such trivial mistake. 

    Kind Regards 

    Haroun

    Friday, May 4, 2018 6:05 AM