store right information from gateway & sensors

TITAN 46 Reputation points
2022-09-29T09:29:26.367+00:00

Hello,
I have an NCD IoT Edge Computer, currently connected to 2 sensors.
I have connected everything to a IoT Hub and I'm receiving the correct data in its right format in the Azure IoT Explorer (see image)
245990-image1.png

Now I want to store that data and analyse it from the storage.
I've followed the Azure tutorials and created a storage account and a container;
I have managed to route the data to the container but the received messages are not in the correct format:

{"EnqueuedTimeUtc":"2022-09-29T06:56:48.0350000Z","Properties":{},"SystemProperties":{"connectionDeviceId":"TINCDEdgeComputer","connectionAuthMethod":"{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}","connectionDeviceGenerationId":"637994300419159364","enqueuedTime":"2022-09-29T06:56:48.0350000Z"},"Body":"///////lots of gibberish////"}

The message routing settings:
245939-image2.png

245870-image3.png

In case needed, the device twin:
{
"deviceId": "//mydeviceid//",
"etag": "AAAAAAAAAAk=",
"deviceEtag": "MTg1NzA3NDM2",
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"connectionState": "Disconnected",
"lastActivityTime": "2022-09-29T09:19:22.2450795Z",
"cloudToDeviceMessageCount": 0,
"authenticationType": "sas",
"x509Thumbprint": {
"primaryThumbprint": null,
"secondaryThumbprint": null
},
"modelId": "",
"version": 10,
"properties": {
"desired": {
"$metadata": {
"$lastUpdated": "2022-09-29T08:26:13.3527078Z",
"$lastUpdatedVersion": 9
},
"$version": 9
},
"reported": {
"$metadata": {
"$lastUpdated": "2022-09-22T07:54:01.9159364Z"
},
"$version": 1
}
},
"capabilities": {
"iotEdge": false
}
}

If any other information is needed I will provide.

Thank you,
Roi

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,668 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,112 questions
{count} votes

2 answers

Sort by: Most helpful
  1. chbeier 1,866 Reputation points
    2022-09-30T10:00:30.387+00:00

    Your message body is base64 encoded. If you decode it you will get:
    (I replaced the MAC addresses. You should also edit your message to remove the original Base64 body content!)

    {  
        "nodeId": 0,  
        "firmware": 6,  
        "battery": "3.29",  
        "battery_percent": "99.64",  
        "counter": 1,  
        "sensor_type": 50,  
        "sensor_data": {  
            "rms_x": 36,  
            "rms_y": 23.58,  
            "rms_z": 26.05,  
            "max_x": 180.8,  
            "max_y": 190.32,  
            "max_z": 183.73,  
            "min_x": -191.05,  
            "min_y": -181.53,  
            "min_z": -185.19,  
            "vibration_temperature": 28,  
            "thermocouple_temperature": 25.5,  
            "current": 0  
        },  
        "sensor_name": "Predictive Maintenance Sensor",  
        "type": "sensor_data",  
        "addr": "aa:bb:cc:dd:ee:ff:gg:hh",  
        "received": 1664434607982,  
        "original": {  
            "mac": "aa:bb:cc:dd:ee:ff:gg:hh",  
            "receive_options": {  
                "ack": 0,  
                "broadcast": 0,  
                "type": ""  
            },  
            "data": [  
                127,  
                0,  
                6,  
                3,  
                255,  
                1,  
                0,  
                50,  
                0,  
                0,  
                14,  
                16,  
                0,  
                9,  
                54,  
                0,  
                10,  
                45,  
                0,  
                70,  
                160,  
                0,  
                74,  
                88,  
                0,  
                71,  
                197,  
                255,  
                181,  
                95,  
                255,  
                185,  
                23,  
                255,  
                183,  
                169,  
                0,  
                28,  
                0,  
                0,  
                9,  
                246,  
                0,  
                0,  
                0  
            ],  
            "type": "receive_packet"  
        }  
    }  
    
    1 person found this answer helpful.
    0 comments No comments

  2. QuantumCache 20,031 Reputation points
    2022-10-04T05:03:36.913+00:00

    Hello @TITAN , Welcome to Microsoft Q&A Platform and thanks for your query.

    When we set the ContentType and ContentEncoding , I see the message is displayed in the right human readable format inside the Blob Storage container.

      using var message = new Message(Encoding.ASCII.GetBytes(messageBody))  
                        {  
                            ContentType = "application/json",  
                            ContentEncoding = Encoding.UTF8.ToString(),  
                        };  
    

    247301-image.png

    247138-image.png

    When you don't set the ContentType and Content Encoding the Message Body is by default in base 64 encoded.

    247247-image.png

    For More info: Azure Storage as a routing endpoint

    If the response is helpful, please click "Accept Answer" and upvote it.
    Please comment in the below section for further help in this matter.

    0 comments No comments