1

I write Cumulocity agent with C++ SDK. I need to add a custom fragment to c8y_Network fragment directly from the agent. Can someone please give an example how to do it.

Namely: c8y_Network has 3 fragments - c8y_LAN/c8y_WAN/c8y_DHCP. My device with agent has 3 LANs, WiFi etc. So I want define new fragments e.g. c8y_LAN2, c8y_LAN3, c8y_WiFi etc.

Documentation says: "...you can add custom fragments." But don't say how.

Marv-CZ
  • 61
  • 1
  • 4

1 Answers1

0

You will need to create your own SmartRest template that reflects your addition to the c8y_Network fragment. Then you can use this template to update the c8y_Network fragment.

You do not need to change anything on the platform side or tell Cumulocity about your structure. You can just blindly send it.

JSON example:

{
    "c8y_Network": {
        "c8y_LAN1": {
            ...
        },
        "c8y_LAN2": {
            ...
        },
        "c8y_LAN3": {
            ...
        },
        "c8y_Wifi": {
            ...
        },
    }
}

The backend will not validate these structures. You application just needs to understand it. The default view for network in devicemanagement will not show your additions as it is not aware of this structure. You would need to have your own network plugin to visualise everything.

In cockpit you have certain widgets (e.g. asset properties) who will automatically detect any kind of structure in the device and there would be able to show this.

I suggest you take look at the implementation for the netcomm routers that use the C++ SDK https://bitbucket.org/m2m/cumulocity-agents-netcomm/src/master/

There are SmartRest templates (including one for c8y_Network) here: https://bitbucket.org/m2m/cumulocity-agents-netcomm/src/master/srtemplate.txt

The usage of this template is implemented in a lua plugin in that case: https://bitbucket.org/m2m/cumulocity-agents-netcomm/src/master/lua/net.lua

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23
  • Thanks, but it isn't answer for my question. I know SmartRest templates and mentioned implementation. My agent can fill current c8y_Network fragment. What I don't know, how to extend it with other custom fragments (see edited question). – Marv-CZ Jul 16 '19 at 20:20
  • @Marv-CZ I extended the answer in order to explain that part in more detail – TyrManuZ Jul 18 '19 at 09:23
  • Thanks for explanation. I saw to /inventory and custom fragments are saved there. What a pity the standard plugins aren't more flexible to represent addional values. Similar as measurement plugin, which shows any custom measurement. – Marv-CZ Jul 18 '19 at 09:58