Skip to content

Conversation

@RyanTSnow-eaton
Copy link

fix: #569

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/device-sdk-c/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

In addition to the functional changes, I have also updated the template.c applications device file and device profile to include tags on the SensorOne device resource, the Device1 device, and a new device command in the profile which includes device command tags.

The device tags take precedence over command tags if tags have overlapping keys as is in the GO SDK implementation of this feature.

The tags for a received EdgeX event are also now exposed in the GET and PUT handlers for the device services.

Testing Instructions

  1. Run the device-template service in this branch: template.c
  2. Exercise the GET or SET calls associated with the Device1 device.
  3. Inspect the message bus, the related events should now include the tags in both the device level event, and each individual resource reading:
{
  "apiVersion": "v3",
  "contentType": "application/json",
  "correlationID": "976a443a-bd2e-4f8e-8fd2-402dabab00ce",
  "errorCode": 0,
  "payload": {
    "apiVersion": "v3",
    "event": {
      "apiVersion": "v3",
      "deviceName": "Device1",
      "id": "ea2773b0-3287-4b99-a554-3afb3ceca26e",
      "origin": 1761135717329020200,
      "profileName": "TemplateSensor",
      "readings": [
        {
          "apiVersion": "v3",
          "deviceName": "Device1",
          "id": "ffe6e561-e510-4ea8-95e2-ea97053278ce",
          "origin": 1761135717329020200,
          "profileName": "TemplateSensor",
          "resourceName": "SensorOne",
          "tags": {
            "resourceTag1": "someResourceTag1"
          },
          "value": "Template result",
          "valueType": "String"
        },
        {
          "apiVersion": "v3",
          "deviceName": "Device1",
          "id": "40ca0f07-7540-4e19-8662-4e6c3e167ef9",
          "origin": 1761135717329020200,
          "profileName": "TemplateSensor",
          "resourceName": "SensorTwo",
          "value": "Template result",
          "valueType": "String"
        }
      ],
      "sourceName": "SensorOneTwo",
      "tags": {
        "cmdTag1": "someCmdTag1",
        "deviceTag1": "someDeviceTag1"
      }
    },
    "statusCode": 200
  }
}

@iain-anderson
Copy link
Member

You can probably simplify things using iot_data_map_merge()

eg

iot_data_t *tags = iot_data_alloc_map (IOT_DATA_STRING);
iot_data_map_merge (tags, x);
iot_data_map_merge (tags, y);
iot_data_map_merge (tags, z);
// any or all of x, y, z may be NULL, that's okay

if (iot_data_map_size (tags))
{
    iot_data_string_map_add (evmap, "tags", tags);
}

@RyanTSnow-eaton
Copy link
Author

You can probably simplify things using iot_data_map_merge()

eg

iot_data_t *tags = iot_data_alloc_map (IOT_DATA_STRING);
iot_data_map_merge (tags, x);
iot_data_map_merge (tags, y);
iot_data_map_merge (tags, z);
// any or all of x, y, z may be NULL, that's okay

if (iot_data_map_size (tags))
{
    iot_data_string_map_add (evmap, "tags", tags);
}

Done in f95b37f! Yeah this greatly simplified merging the tags, thank you for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add resource, command, and device tags to reading/event

2 participants