Unable to register a custom request template

What product/components do you use and which version/fix level?

Backend: 1011.0.12
UI: 1011.0.12

Are you using a free trial or a product with a customer license?

What are trying to achieve? Please describe in detail.

  • I need to register a custom template for sending some custom numerical values.

  • For this I have referred the C++sdk. There’s an example by the name ‘ex-03-measurement’ which I referred. This example tells us about how we can send dummy CPU workload to a device on Cumulocity IoT. I have tried this example and its works fine.

  • I referred the above mentioned example and a document named ‘Reference Guide’ topic SmartREST > Registration Process. Using these 2 sources as reference I created a template as follows,

    10,120,POST,/measurement/measurements,application/json,%%,NOW UNSIGNED NUMBER,"{"“time”":""%%"","“source”":{"“id”":""%%""},"“type”":"“Real”","“My_Cov”":{"“value”":%%,}}"

  • I am trying to register the above custom template via Postman. But I get a response as follows,
    43,1,Template already existing

  • What I know is there is no such template registered by me before and custom templates can be registered by using message-id starting from 100.

  • Can anyone point out what I am missing ?

Do you get any error messages? Please provide a full error message screenshot and log file.

Please find the attached screenshot for the above scenario,

Hi Prasad,

can you also share the headers of your request. Each template, which you create, will be added to a SmartRest template collection. This collection is identified by the custom header X-Id. Might be that a template already exists for the current template collection, which has the same id you also provided for your request to create a new template.

You could also try to change the value for the X-Id header.

Best regards
Christian

Hi Christian,

As you suggested I changed the X-Id to a random number ‘1234’ in the header and the registration worked. In response I received the following message: 20,765539.

Now I need to use this template to send the ‘My_Cov’ numerical values from the example ‘ex-03-measurement’ which I referred from the C++ sdk.

There’s this function in the sdk where we assign the template id to the agent.send function,

virtual void operator()(SrTimer &timer, SrAgent &agent)
{
    const int cpu = rand() % 100;
  
   if(cpu%2 == 0)
    agent.send("103," + agent.ID() + "," + to_string(cpu));
   
}

In the above function tried sending 120 (my custom template’s id) instead of the 103 as seen in the example. But it is not working. I might be missing something here.

My requirement is very small.

  • I want to use the ‘ex-03-measurement’ example from the C++ sdk.

  • This example sends a CPU workload using a template Id 103.

  • Instead of template Id103 I want to use my custom registered template Id 120 and see the custom measurement on a device registered on Cumuloicty IoT.

Can you please help me with this ?

Hi Christian,

I am still not able to send a custom measurement by registering a custom template.
I have provided a detailed explanation of what I am doing in the above comment
Please suggest where I am going wrong.

Hi Prasad,

I’m not familiar with the C++ SDK. Did you follow the steps as described in the guide? In particular, the section which describes how to manage to the X-Id header?

It is important to mention that you must store the correct SmartREST X-ID and device’s Cumulocity IoT ID in the inherited member variables xid and id respectively. They will be used by SrAgent after the integrate process for initializing the corresponding internal variables.

Did you set the xid variable at some point in your code?

Best regards
Christian

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.