Jump to content

Cumulocity Configuration: Difference between revisions

From Teltonika Networks Wiki
No edit summary
Updated visuals to correspond with updates of Cumulocity registration, Cockpit, Device manager. Updated links for registration, documentation. Updated steps to add device to Cumulocity. Updated WebUI page example of Cumulocity to correspond with latest release (7.20). Update application template with current template used in Teltonika devices. Updated locations of template and lua scripts. Updated documentation of templates.
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[[File:Networking_rutos_configuration_examples_cumulocity_logo.png|right]]
[[File:Cumulocity logo.png|right|164x164px]]
<b>Cumulocity IoT</b> is a cloud-based, real-time IoT management platform that's also compatible with Teltonika-Networks devices.
<b>Cumulocity IoT</b> is a cloud-based, real-time IoT management platform that's also compatible with Teltonika-Networks devices.


Line 21: Line 21:


<ul>
<ul>
     <li><b>[https://signup.softwareag.cloud/#/?product=cumulocity Register an account]</b> on Cumulocity.</li>
     <li><b>[https://www.cumulocity.com/start-your-journey/free-trial/ Register an account]</b> on Cumulocity.</li>
     <li>Wait a few minutes after the registration and open your email account. You should have received an email with the subject 'Welcome to Cumulocity IoT'. Open the email and <b>click 'Login to Cumulocity IoT'</b>.<br>[[File:Networking_rutos_configuration_examples_cumulocity_1.png|border|class=tlt-border]]</li>
     <li>Wait a few minutes after the registration, open your email account and look for an email with the subject 'Welcome to Cumulocity IoT'. Open it and <b>click 'Login to now'<nowiki/></b>.<br>[[File:Cumulocity iot successful device registration.png|border]]
     <li>Upon a successful login you should be redirected to the <b>Cumulocity Cockpit</b>.<br>[[File:Networking_rutos_configuration_examples_cumulocity_2.png|border|class=tlt-border]]</li>
</li>
     <li>Upon a successful login you should be redirected to the <b>Cumulocity Cockpit</b>.<br>[[File:Cumulocity iot main menu current.png|border|1073x1073px]]</li>
</ul>
</ul>


Line 32: Line 33:
<ul>
<ul>
     <li>Log in to your device's WebUI.</li>
     <li>Log in to your device's WebUI.</li>
     <li><b>Go to Services → Package Manager</b> and install Cumulocity.<br>[[File:Networking_rutos_configuration_examples_cumulocity_3.png|border|class=tlt-border]]</li>
     <li>Go to '''System → Package Manager''' and install '''Cumulocity - Cloud of Things'''.<br>   [[File:Networking_rutos_configuration_example_cumulocity_710_1.png|border|class=tlt-border|900px]]</li>
     <li></b>Go to Services → Cloud Solutions → Cumulocity</b> and configure it as follows.
     <li>Go to '''Services → Cloud Solutions → Cumulocity''' and configure it as follows.
         <ol>
         <ol>
             <li>Enable Cumulocity</li>
             <li>Enable Cumulocity</li>
            <li>Enable SSL/TLS</li>
             <li>Specify your Cumulocity server's address in the 'Server Address' field.</li>
             <li>Specify your Cumulocity server's address in the 'Server Address' field.</li>
             <li>Set a connection frequency interval (at least 1 minute).</li>
             <li>Set a connection frequency interval (at least 1 minute).</li>
             <li>Click 'Save & Apply'.</li>
             <li>Click 'Save & Apply'.</li>
         </ol>[[File:Networking_rutos_configuration_examples_cumulocity_4.png|border|class=tlt-border]]
         </ol>[[File:Cumulocity iot WebUI page 7.20.png|border|900x900px]]
     </li>
     </li>
</ul>
</ul>
Line 47: Line 49:
Register your Teltonika-Networks device on Cumulocity.
Register your Teltonika-Networks device on Cumulocity.
<ul>
<ul>
     <li>Find the 'Application switcher' in the top-right corner of the Cumulocity dashboard and <b>go to 'Device management'</b>.<br>[[File:Networking_rutos_configuration_examples_cumulocity_5.png|border|class=tlt-border]]</li>
     <li>Find the 'Application switcher' in the top-right corner of the Cumulocity dashboard and <b>go to 'Device management'</b>.<br>[[File:Cumulocity iot Application switcher navigation to device management.png|border]]
     <li>Then expand the 'Devices' tab in left-hand menu, go to 'Registration' and <b>click 'Register device'</b>.<br>[[File:Networking_rutos_configuration_examples_cumulocity_6.png|border|class=tlt-border]]</li>
</li>
     <li>Complete the registration.
     <li>Then expand the 'Devices' tab in left-hand menu, go to 'Registration' and <b>click 'Register device'</b>.<br>[[File:Cumulocity iot Device manager main menu.png|border|1085x1085px]]
</li>
    <li>In the drop-down menu select option '''<nowiki/>'General'<nowiki/>'''.
[[File:Cumulocity iot registering device.png|border|395x395px]] </li>
     <li>To complete the registration:
         <ol>
         <ol>
            <li>Choose 'General device registration'.</li>
             <li>Enter your device's serial number into the '''<nowiki/>'Device ID'''' field. The serial number can be found on the device's housing, box or in the WebUI, <i>Status → System</i> page.</li>
             <li>Enter your device's serial number into the 'Device ID' field. The serial number can be found on the device's housing, box or in the WebUI, <i>Status → System</i> page.</li>
             <li>Click '''<nowiki/>'Next'<nowiki/>'''.
             <li>Click 'Next'.</li>
[[File:Cumulocity iot Device registration step 1.png|1083x1083px]]
        </ol>[[File:Networking_rutos_configuration_examples_cumulocity_7.png]]
</li><li>If the device connects successfully, you should see an indication similar to the one below. '''Click 'Close'<nowiki/>''' .
    </li>
[[File:Cumulocity iot Device registration step 1 success.png|border|1082x1082px]]
    <li>If the device connects successfully, you should see an indication similar to the one below. Click 'Complete' to finish the registration.</li>
</li><li>When pop-up window is closed, connection status has to be accepted by clicking button '''<nowiki/>'Accept'<nowiki/>'''. If needed, user can add security token when adding the device.
[[File:Cumulocity iot Device registration step 2.png|border|416x416px]]
</li>
        </ol> </li>
    <li>Now added device can be seen in the '''<nowiki/>'Devices'<nowiki/>''' tab in left-hand menu, go to '''<nowiki/>'All devices'<nowiki/>'''.[[File:Cumulocity iot added device success confirmation.png|border|1082x1082px]]
Here is successfully added device to the list and ready to use.
</li>
</ul>
</ul>
<!--
==Installing example application==


First, you need to install Cumulocity. Go to System -> Package manager:
==Explanation of example application==


[[File:Package manager.jpg]]
There are two steps when adding new properties:


When you open package manager you will see a list of packages. You need click install on Cumulocity, see below:
1. Writing template


2. Writing lua script which will stream information.


[[File:Screenshot from 2019-11-27 16-00-24.png]]
By default, template location inside router is „/usr/local/usr/lib/lua/cm/srtemplate.txt“. It contains such content:
 
==Configuring and launching example application==
After you successfully installed Cumulocity, in „Services“ tab there should be an option called „IoT Platforms“.
 
[[File:cumiot.png]]
 
[[File:cumiotwindow.png]]
 
Only single field is required, which is Server Address. This is the same URL of Cumulocity Cockpit website. In this example, it is myservername.cumulocity.com.
 
Explanation of other options:
 
Use SSL/TLS – connection will use TLS, however, you need to have a signed SSL certificate, otherwise application would not be able to connect to the Cumulocity server.
 
Reset Auth – once device has been removed from the Cumulocity Device Management, you will need to reset authentication in order to re-register device.
 
Also click „Enable“ to enable example application. See below:
 
[[File:cumiotvalues.png]]
 
Now click „Save“ and if everything is correct – example application will successfully connect to the Cumulocity server.
 
Now you need to register device on Device Management in Cumulocity Cockpit.
 
Device registration is done by writing down device's serial number. In order to obtain your device's serial number, look at the backplate of it or navigate to your device's control panel and then to „Status → Device“ page:
 
[[File:cumdevice.png]]
 
In this case, serial number is 09516845.
 
Now log into your Cumulocity Cockpit portal, in this example URL is https://myservername.cumulocity.com.
 
Go to the Device Management page:
 
[[File:cumcockpit.png]]
 
[[File:cumdevicemanagement.png]]
 
Then navigate to Registration page:
 
[[File:cumdevicepage.png]]
 
Click „Register device“:
 
[[File:cumdeviceregister.png]]
 
Click „General device registration“:
 
[[File:cumnewdevice.png]]
 
Write device’s serial number in „Device ID“ field and click „Next“:
 
[[File:cumdeviceregistration.png]]
 
As shown below, registration is successful:
 
[[File:cumsuccessresgister.png]]
 
Click „Finish“ to  close this pop-up. Now if everything is correct, a new device widget should show up with a status „PENDING ACCEPTANCE“:
 
[[File:cumpendingdevice.png]]
 
Click „Accept“ button to accept this device.
 
Now navigate to „All devices“ page:
 
[[File:cumalldevices.png]]
 
Here you should be able to see list of all registered devices:
 
[[File:cumallregistereddevices.png]]
 
Click on „TLT-RUT955 Router“ name to get into information page:
 
[[File:cumdeviceinfo.png]]
 
Notice „Device Data“ widget, it contains information from the router device. By navigating to „Control“ tab, you can restart device by clicking „More → Restart Device“:
 
[[File:cumdevicecontrol.png]]
 
You can go back to Cumulocity Cockpit page the same way you entered Device managemant page:
 
[[File:cumnavigatecockpit.png]]
 
Then navigate to „Home“ page:
 
[[File:cumnavigatehome.png]]
 
And then click „Add widget“:
 
[[File:cumaddwidget.png]]
 
Select „Asset properties“ widget and type title, then select „TLT-RUT955 Router“ in „Target Assets or Devices“:
 
[[File:cumcreatewidget.png]]
 
To add more information into widget, click „Add property“ and click on „Show“ to add that property.
 
In example application, these properties are used:
 
Hardware – Model, Revision, Serial Number
 
Mobile – Cell ID, Connection Type, Current Operator, ICCID, IMEI and Signal


WAN – IP and Wan Type
Teltonika-Networks_RUTOS_v1.0


Total properties:
10,100,GET,/identity/externalIds/SerialNumber/%%,,application/json,%%,STRING,


[[File:cumtotalprops.png]]
<nowiki>10,101,POST,/inventory/managedObjects,application/json,application/json,%%,STRING,"{""name"":""%%"",""c8y_IsDevice"":{},""com_cumulocity_model_Agent"":{}}"</nowiki>


Then click „Save“ and you should be able to see widget with properties you have set:
10,102,POST,/identity/globalIds/%%/externalIds,application/json,,%%,STRING STRING,"{""externalId"":""%%"",""type"":""SerialNumber""}"


[[File:cumdevicewidgetinfo.png]]
10,103,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING,"{""name"": ""%%"", ""type"": ""%%""}"


==Explanation of example application==
10,104,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING,"{""name"": ""%%"",""type"": ""%%"",""c8y_Hardware"":{""model"":""%%"",""revision"":""%%"",""serialNumber"":""%%""},""c8y_Firmware"":{""name"":""%%"",""version"":""%%"",""url"":""%%""},""c8y_Mobile"":{""imei"":""%%"",""cellId"":""%%"",""iccid"":""%%"",""imsi"":""%%"",""currentOperator"":""%%"",""connType"":""%%"",""mnc"":""%%"",""lac "":""%%""},""c8y_SupportedOperations"":[""c8y_Restart"", ""c8y_Firmware""]}"
There are two steps when adding new properties:


1. Writing template
<nowiki>10,105,POST,/measurement/measurements,application/json,,%%,NOW UNSIGNED NUMBER,"{""time"":""%%"",""source"":{""id"":""%%""},""type"":""c8y_SignalStrength"",""c8y_SignalStrength"":{""rssi"":{""value"":%%,""unit"":""dBm""}}}"</nowiki>


2. Writing lua script which will stream information.
<nowiki>10,106,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING,"{""c8y_Network"":{""c8y_WAN"":{""ip"":""%%""}},""wanType"":""%%""}"</nowiki>


By default, template location inside router is „/usr/lib/lua/cm/srtemplate.txt“. It contains such content:
10,107,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING,"{""c8y_SupportedOperations"":[""%%""]}"


  rut955-v0.01
10,108,PUT,/devicecontrol/operations/%%,application/json,,%%,UNSIGNED STRING,"{""status"":""%%""}"


  10,100,GET,/identity/externalIds/SerialNumber/%%,,application/json,%%,STRING,
<nowiki>10,109,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING,"{""c8y_Connection"":{""status"": ""%%""}}"</nowiki>


  10,101,POST,/inventory/managedObjects,application/json,application/json,%%,STRING,"{""name"":""%%"",""c8y_IsDevice"":{},""com_cumulocity_model_Agent"":{}}"
<nowiki>10,110,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING,"{""c8y_Availability"":{""lastMessage"": ""%%"", ""status"": ""%%""}}"</nowiki>


  10,102,POST,/identity/globalIds/%%/externalIds,application/json,application/json,%%,STRING STRING,"{""externalId"":""%%"",""type"":""SerialNumber""}"
<nowiki>10,111,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED NUMBER,"{""c8y_RequiredAvailability"":{""responseInterval"": %%}}"</nowiki>


  10,103,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING    STRING STRING,"{""name"": ""%%"", ""type"": ""%%""}"
10,112,POST,/identity/globalIds/%%/externalIds,application/json,,%%,STRING STRING,"{""externalId"":""%%"",""type"":""c8y_Serial""}"


  10,104,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING    STRING STRING STRING,"{""c8y_Hardware"":  {""model"":""%%"",""revision"":""%%"",""serialNumber"":""%%""}}"
11,500,$.managedObject,,$.id
11,501,,$.c8y_IsDevice,$.id
11,502,,$.c8y_Restart,$.id,$.deviceId
11,503,,$.c8y_Firmware,$.id,$.c8y_Firmware.url,$.c8y_Firmware.name,$.deviceId


  10,105,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING    STRING STRING STRING STRING STRING STRING,"{""c8y_Mobile"":  {""imei"":""%%"",""cellId"":""%%"",""iccid"":""%%"",""connType"":""%%"",""currentOperat  or"":""%%""},""signal"":""%%""}"
First line contains template version. In this case it is „Teltonika-Networks_RUTOS_v1.0“.


  10,106,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING    STRING STRING,"{""c8y_Network"":{""c8y_WAN"":{""ip"":""%%""}},""wanType"":""%%""}"
When template is updated, version must be updated as well, otherwise device will use non-updated template version.
 
  10,107,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,UNSIGNED STRING,"{""c8y_SupportedOperations"":[""%%""]}"
 
  10,108,PUT,/devicecontrol/operations/%%,application/json,application/json,%%,UNSIGNED    STRING,"{""status"":""%%""}"
 
  11,500,$.managedObject,,$.id
  11,501,,$.c8y_IsDevice,$.id
  11,502,,$.c8y_Restart,$.id,$.deviceId
 
First line contains template version. In this case it is „rut955-v0.01“.
 
When template is updated, version must be updated aswell, otherwise device will use non-updated template version.


The following lines contains requests starting with a number „10“ and responses - starting with a number „11“. Now explanation of request:
The following lines contains requests starting with a number „10“ and responses - starting with a number „11“. Now explanation of request:
Line 228: Line 126:
Method - POST
Method - POST


URL - /inventory/managedObjects
URI - /inventory/managedObjects


Content Type - application/json
Content Type - application/json
Line 242: Line 140:




Type – requests are identified by a number 10
Type – requests are identified by a number 10.
 
Code – request identifier number, each request must contain unique number.


Code – request code number, each request must contain unique number
Method HTTP method of request.


Method HTTP method of request
URI URL that will be used in request.


URL URL that will be used in request
Content Type it is Content-Type header field value.


Content Type – it is Content-Type header field value
Accept – it is Accept header field value, mostly equal to Content Type.


Accept – it is Accept header field value, mostly equal to Content Type
Placeholder  - string which will be replaced in URI or Template.


Placeholder  - string which will be replaced in URL or Template JSON
Params – what kind of params are replaced, JSON template contains two strings.


Params what kind of params are replaced, JSON template contains two strings
Template sent as JSON or plain-text payload after the placeholders have been replaced with the parameter values.


Template – JSON template which will be sent




Line 273: Line 172:
Value 2 - $.id
Value 2 - $.id


Value3 - $.deviceId
Value 3 - $.deviceId
 




Type – responses are identified by a number 11
Type – responses are identified by a number 11.


Code – response code, each response must contain unique number
Code – response identifier code, each response must contain unique number.


Cond – JSON path base pointing to an object or object list from which values are  
Cond – JSON path base pointing to an object or object list from which values are extracted.
extracted


Value… - JSON values
Value … - JSON values. Unlimited number of values can be specified.


Take a look for more information about templates: https://www.cumulocity.com/guides/reference/smartrest.
Take a look for more information about templates: https://cumulocity.com/docs/smartrest/smartrest-introduction/.


Now explanation of logic inside lua script. By default, example application’s lua script location is „/usr/bin/lua/cm“. Application will scan this folder for any *.lua files and load them if they contains „init“ function.  Script’s „stream.lua“ content:
Now explanation of logic inside lua script. Custom lua scripts can be placed in „/usr/local/usr/lib/lua/cm/“. Application will scan this folder for any *.lua files and load them if they contains „init“ function.  Here is an example of a custom lua script:


   -- stream.lua
   -- stream.lua
Line 338: Line 237:
       c8y:send('106,'..c8y.ID..','..wanip..','..wantype)
       c8y:send('106,'..c8y.ID..','..wanip..','..wantype)
   end
   end




Line 349: Line 249:


For more information about Lua API, download Cumulocity C++ SDK: https://bitbucket.org/m2m/cumulocity-sdk-c/downloads and look up inside „sdk/doc/lua.html“ with a browser.
For more information about Lua API, download Cumulocity C++ SDK: https://bitbucket.org/m2m/cumulocity-sdk-c/downloads and look up inside „sdk/doc/lua.html“ with a browser.
<!--==Configuring and launching example application==
If everything is correct with adding the device, a new device widget should show up with a status „PENDING ACCEPTANCE“:
[[File:cumpendingdevice.png]]
Click „Accept“ button to accept this device.
Now navigate to „All devices“ page:
[[File:cumalldevices.png]]
Here you should be able to see list of all registered devices:
[[File:cumallregistereddevices.png]]
Click on „TLT-RUT955 Router“ name to get into information page:
[[File:cumdeviceinfo.png]]
Notice „Device Data“ widget, it contains information from the router device. By navigating to „Control“ tab, you can restart device by clicking „More → Restart Device“:
[[File:cumdevicecontrol.png]]
You can go back to Cumulocity Cockpit page the same way you entered Device managemant page:
[[File:cumnavigatecockpit.png]]
Then navigate to „Home“ page:
[[File:cumnavigatehome.png]]
And then click „Add widget“:
[[File:cumaddwidget.png]]
Select „Asset properties“ widget and type title, then select „TLT-RUT955 Router“ in „Target Assets or Devices“:
[[File:cumcreatewidget.png]]
To add more information into widget, click „Add property“ and click on „Show“ to add that property.
In example application, these properties are used:
Hardware – Model, Revision, Serial Number
Mobile – Cell ID, Connection Type, Current Operator, ICCID, IMEI and Signal
WAN – IP and Wan Type
Total properties:
[[File:cumtotalprops.png]]
Then click „Save“ and you should be able to see widget with properties you have set:
[[File:cumdevicewidgetinfo.png]]


==External Links==
==External Links==
Line 359: Line 317:


{{Template: trademark disclaimer}}
{{Template: trademark disclaimer}}
[[Category:IoT Platforms]]
-->
-->
[[Category:IoT platforms]]

Revision as of 17:33, 18 December 2025

Main Page > General Information > Configuration Examples > Third party services > IoT platforms > Cumulocity Configuration

Cumulocity IoT is a cloud-based, real-time IoT management platform that's also compatible with Teltonika-Networks devices.

Introduction

This article contains step-by-step instructions on how to set up a Cumulocity server and register a Teltonika-Networks device on it.

Basic setup

Basic setup consists of:

  1. Creating a Cumulocity account
  2. Configuring Cumulocity on a Teltonika-Networks device
  3. Registering the device on your Cumulocity server

Create an account


First of all, you will need to set up your Cumulocity environment (server).

  • Register an account on Cumulocity.
  • Wait a few minutes after the registration, open your email account and look for an email with the subject 'Welcome to Cumulocity IoT'. Open it and click 'Login to now'.
  • Upon a successful login you should be redirected to the Cumulocity Cockpit.

Configure a device


Set up Cumulocity on your Teltonika-Networks device.

  • Log in to your device's WebUI.
  • Go to System → Package Manager and install Cumulocity - Cloud of Things.
  • Go to Services → Cloud Solutions → Cumulocity and configure it as follows.
    1. Enable Cumulocity
    2. Enable SSL/TLS
    3. Specify your Cumulocity server's address in the 'Server Address' field.
    4. Set a connection frequency interval (at least 1 minute).
    5. Click 'Save & Apply'.

Register a device


Register your Teltonika-Networks device on Cumulocity.

  • Find the 'Application switcher' in the top-right corner of the Cumulocity dashboard and go to 'Device management'.
  • Then expand the 'Devices' tab in left-hand menu, go to 'Registration' and click 'Register device'.
  • In the drop-down menu select option 'General'.
  • To complete the registration:
    1. Enter your device's serial number into the 'Device ID' field. The serial number can be found on the device's housing, box or in the WebUI, Status → System page.
    2. Click 'Next'.
    3. If the device connects successfully, you should see an indication similar to the one below. Click 'Close' .
    4. When pop-up window is closed, connection status has to be accepted by clicking button 'Accept'. If needed, user can add security token when adding the device.
  • Now added device can be seen in the 'Devices' tab in left-hand menu, go to 'All devices'. Here is successfully added device to the list and ready to use.

Explanation of example application

There are two steps when adding new properties:

1. Writing template

2. Writing lua script which will stream information.

By default, template location inside router is „/usr/local/usr/lib/lua/cm/srtemplate.txt“. It contains such content:

Teltonika-Networks_RUTOS_v1.0
10,100,GET,/identity/externalIds/SerialNumber/%%,,application/json,%%,STRING,
10,101,POST,/inventory/managedObjects,application/json,application/json,%%,STRING,"{""name"":""%%"",""c8y_IsDevice"":{},""com_cumulocity_model_Agent"":{}}"
10,102,POST,/identity/globalIds/%%/externalIds,application/json,,%%,STRING STRING,"{""externalId"":""%%"",""type"":""SerialNumber""}"
10,103,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING,"{""name"": ""%%"", ""type"": ""%%""}"
10,104,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING,"{""name"": ""%%"",""type"": ""%%"",""c8y_Hardware"":{""model"":""%%"",""revision"":""%%"",""serialNumber"":""%%""},""c8y_Firmware"":{""name"":""%%"",""version"":""%%"",""url"":""%%""},""c8y_Mobile"":{""imei"":""%%"",""cellId"":""%%"",""iccid"":""%%"",""imsi"":""%%"",""currentOperator"":""%%"",""connType"":""%%"",""mnc"":""%%"",""lac "":""%%""},""c8y_SupportedOperations"":[""c8y_Restart"", ""c8y_Firmware""]}"
10,105,POST,/measurement/measurements,application/json,,%%,NOW UNSIGNED NUMBER,"{""time"":""%%"",""source"":{""id"":""%%""},""type"":""c8y_SignalStrength"",""c8y_SignalStrength"":{""rssi"":{""value"":%%,""unit"":""dBm""}}}"
10,106,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING,"{""c8y_Network"":{""c8y_WAN"":{""ip"":""%%""}},""wanType"":""%%""}"
10,107,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING,"{""c8y_SupportedOperations"":[""%%""]}"
10,108,PUT,/devicecontrol/operations/%%,application/json,,%%,UNSIGNED STRING,"{""status"":""%%""}"
10,109,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING,"{""c8y_Connection"":{""status"": ""%%""}}"
10,110,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED STRING STRING,"{""c8y_Availability"":{""lastMessage"": ""%%"", ""status"": ""%%""}}"
10,111,PUT,/inventory/managedObjects/%%,application/json,,%%,UNSIGNED NUMBER,"{""c8y_RequiredAvailability"":{""responseInterval"": %%}}"
10,112,POST,/identity/globalIds/%%/externalIds,application/json,,%%,STRING STRING,"{""externalId"":""%%"",""type"":""c8y_Serial""}"
11,500,$.managedObject,,$.id
11,501,,$.c8y_IsDevice,$.id
11,502,,$.c8y_Restart,$.id,$.deviceId
11,503,,$.c8y_Firmware,$.id,$.c8y_Firmware.url,$.c8y_Firmware.name,$.deviceId

First line contains template version. In this case it is „Teltonika-Networks_RUTOS_v1.0“.

When template is updated, version must be updated as well, otherwise device will use non-updated template version.

The following lines contains requests starting with a number „10“ and responses - starting with a number „11“. Now explanation of request:

Type - 10

Code - 101

Method - POST

URI - /inventory/managedObjects

Content Type - application/json

Accept - application/json

Placeholder - %%

Params - STRING STRING

Template - JSON


Type – requests are identified by a number 10.

Code – request identifier number, each request must contain unique number.

Method – HTTP method of request.

URI – URL that will be used in request.

Content Type – it is Content-Type header field value.

Accept – it is Accept header field value, mostly equal to Content Type.

Placeholder - string which will be replaced in URI or Template.

Params – what kind of params are replaced, JSON template contains two strings.

Template – sent as JSON or plain-text payload after the placeholders have been replaced with the parameter values.


Explanation of response:

Type - 11

Code - 502

Cond - <none>

Value 1 - $.c8y_Restart

Value 2 - $.id

Value 3 - $.deviceId


Type – responses are identified by a number 11.

Code – response identifier code, each response must contain unique number.

Cond – JSON path base pointing to an object or object list from which values are extracted.

Value … - JSON values. Unlimited number of values can be specified.

Take a look for more information about templates: https://cumulocity.com/docs/smartrest/smartrest-introduction/.

Now explanation of logic inside lua script. Custom lua scripts can be placed in „/usr/local/usr/lib/lua/cm/“. Application will scan this folder for any *.lua files and load them if they contains „init“ function. Here is an example of a custom lua script:

  -- stream.lua
  local utl = require "luci.util"
  local sys = require "luci.sys"
  local DEVICE_NAME = 'TLT-RUT955 Router'
  local DEVICE_TYPE = 'Router'
  function restart(r)
     local deviceId = r:value(2)
     c8y:send('108,'..deviceId..',SUCCESSFUL')
     sys.exec("reboot")
  end
  function init()
     srInfo('*** Stream Init ***')
     -- set device name and type
     c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)
     -- set restart as supported operation
     c8y:send('107,'..c8y.ID..',c8y_Restart')
     -- set imei, cellid and iccid first time
     mobileDataStream()
     -- create timer which will stream mobile info data
     local m_timer = c8y:addTimer(10 * 1000, 'mobileDataStream')
     m_timer:start()   
     -- register restart handler
     c8y:addMsgHandler(502, 'restart')
     return 0
  end
  function mobileDataStream()
     local imei = utl.trim(sys.exec("gsmctl -i"))
     local cell = utl.trim(sys.exec("gsmctl -C"))
     local icc = utl.trim(sys.exec("gsmctl -J"))
     local type = utl.trim(sys.exec("gsmctl -t"))
     local oper = utl.trim(sys.exec("gsmctl -o"))
     local sign = utl.trim(sys.exec("gsmctl -q"))..' dBm'
     local req = '105,'..c8y.ID
     req = req..','..imei
     req = req..','..cell
     req = req..','..icc
     req = req..','..type
     req = req..','..oper
     req = req..','..sign
     -- send mobile info
     c8y:send(req)
     local wantype = utl.trim(sys.exec("uci get -q network.wan.ifname"))
     local wanip = utl.trim(sys.exec("curl -s http://whatismyip.akamai.com"))
     -- send wan info
     c8y:send('106,'..c8y.ID..','..wanip..','..wantype)
  end


Once application finds lua script, it will call „init“ function. This is where all initialization of timers and other stuff should be.

Sending information is quite simple:

  c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)

By using „c8y:send“ function, first string contains request code, which was defined in the template, earlier. Then comma must appear after each value. The above line shows how we update device name and device type with our own.

For more information about Lua API, download Cumulocity C++ SDK: https://bitbucket.org/m2m/cumulocity-sdk-c/downloads and look up inside „sdk/doc/lua.html“ with a browser.