Changes

317 bytes removed ,  07:18, 3 September 2020
no edit summary
Line 1: Line 1: −
[[File:cum.png|right|160px]]
+
#REDIRECT [[Cumulocity Configuration]]
The '''Cumulocity''' is now compatible with RUT routers.
+
The '''Cumulocity''' is now compatible with Teltonika RUT routers.
 
==Description==
 
==Description==
    
Cumulocity is the leading independent Device and Application Management Internet of Things (IoT) Platform since 2010. Our Internet of Things Platform connects and manages your machines effortlessly, so you can focus on your business's value adding activities.
 
Cumulocity is the leading independent Device and Application Management Internet of Things (IoT) Platform since 2010. Our Internet of Things Platform connects and manages your machines effortlessly, so you can focus on your business's value adding activities.
  −
{{Template: trademark disclaimer}}
      
==Summary==
 
==Summary==
Line 30: Line 28:  
[[File:cumulocityportal.png]]
 
[[File:cumulocityportal.png]]
   −
==Preparing firmware with example application==
+
==Installing example application==
   −
First, you need to obtain GPL from https://teltonika-networks.com/gpl. Now you need to run “make menuconfig” command inside GPL folder.
+
First, you need to install Cumulocity. Go to System -> Package manager:
   −
[[File:cummakeconfig.png]]
+
[[File:Package manager.jpg]]
   −
You need to add example application so it can be built. Navigate to “Network” section and select “cmstreamapp” with spacebar key. It will show “<*>” once application is added, see below:
+
When you open package manager you will see a list of packages. You need click install on Cumulocity, see below:
   −
[[File:cumnetworksection.png]]
     −
Now do the same with “Luci” section,  “Applications → luci-app-iot”. This will enable to configure example package from router control panel, see below for example:
+
[[File:Screenshot from 2019-11-27 16-00-24.png]]
 
  −
[[File:cumlucisection.png]]
  −
 
  −
Everything should be ready and you can exit. Now run “make” command and firmware will appear in “bin/ar71xx/tltFws” directory. You can flash “GPL_…._WEBUI.bin” file.
      
==Configuring and launching example application==
 
==Configuring and launching example application==
After you successfully built and flashed firmware, in „Services“ tab there should be an option called „IoT Platforms“.  
+
After you successfully installed Cumulocity, in „Services“ tab there should be an option called „IoT Platforms“.  
    
[[File:cumiot.png]]
 
[[File:cumiot.png]]
Line 161: Line 154:  
==Explanation of example application==
 
==Explanation of example application==
 
There are two steps when adding new properties:
 
There are two steps when adding new properties:
 +
 
1. Writing template
 
1. Writing template
   Line 167: Line 161:  
By default, template location inside router is „/usr/lib/lua/cm/srtemplate.txt“. It contains such content:
 
By default, template location inside router is „/usr/lib/lua/cm/srtemplate.txt“. It contains such content:
   −
rut955-v0.01
+
  rut955-v0.01
   −
10,100,GET,/identity/externalIds/SerialNumber/%%,,application/json,%%,STRING,
+
  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,101,POST,/inventory/managedObjects,application/json,application/json,%%,STRING,"{""name"":""%%"",""c8y_IsDevice"":{},""com_cumulocity_model_Agent"":{}}"
   −
10,102,POST,/identity/globalIds/%%/externalIds,application/json,application/json,%%,STRING STRING,"{""externalId"":""%%"",""type"":""SerialNumber""}"
+
  10,102,POST,/identity/globalIds/%%/externalIds,application/json,application/json,%%,STRING STRING,"{""externalId"":""%%"",""type"":""SerialNumber""}"
   −
10,103,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING STRING STRING,"{""name"": ""%%"", ""type"": ""%%""}"
+
  10,103,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING   STRING STRING,"{""name"": ""%%"", ""type"": ""%%""}"
   −
10,104,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING STRING STRING STRING,"{""c8y_Hardware"":{""model"":""%%"",""revision"":""%%"",""serialNumber"":""%%""}}"
+
  10,104,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING   STRING STRING STRING,"{""c8y_Hardware"":   {""model"":""%%"",""revision"":""%%"",""serialNumber"":""%%""}}"
   −
10,105,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING STRING STRING STRING STRING STRING STRING,"{""c8y_Mobile"":{""imei"":""%%"",""cellId"":""%%"",""iccid"":""%%"",""connType"":""%%"",""currentOperator"":""%%""},""signal"":""%%""}"
+
  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"":""%%""}"
   −
10,106,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING STRING STRING,"{""c8y_Network"":{""c8y_WAN"":{""ip"":""%%""}},""wanType"":""%%""}"
+
  10,106,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,STRING   STRING STRING,"{""c8y_Network"":{""c8y_WAN"":{""ip"":""%%""}},""wanType"":""%%""}"
   −
10,107,PUT,/inventory/managedObjects/%%,application/json,application/json,%%,UNSIGNED STRING,"{""c8y_SupportedOperations"":[""%%""]}"
+
  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"":""%%""}"
+
  10,108,PUT,/devicecontrol/operations/%%,application/json,application/json,%%,UNSIGNED   STRING,"{""status"":""%%""}"
   −
11,500,$.managedObject,,$.id
+
  11,500,$.managedObject,,$.id
11,501,,$.c8y_IsDevice,$.id
+
  11,501,,$.c8y_IsDevice,$.id
11,502,,$.c8y_Restart,$.id,$.deviceId
+
  11,502,,$.c8y_Restart,$.id,$.deviceId
    
First line contains template version. In this case it is „rut955-v0.01“.  
 
First line contains template version. In this case it is „rut955-v0.01“.  
Line 198: Line 192:     
Type - 10
 
Type - 10
 +
 
Code - 101
 
Code - 101
 +
 
Method - POST
 
Method - POST
 +
 
URL - /inventory/managedObjects
 
URL - /inventory/managedObjects
 +
 
Content Type - application/json
 
Content Type - application/json
 +
 
Accept - application/json
 
Accept - application/json
 +
 
Placeholder - %%
 
Placeholder - %%
 +
 
Params - STRING STRING
 
Params - STRING STRING
 +
 
Template - JSON
 
Template - JSON
 +
      Line 230: Line 233:     
Type - 11
 
Type - 11
 +
 
Code - 502
 
Code - 502
 +
 
Cond - <none>
 
Cond - <none>
 +
 
Value 1 - $.c8y_Restart
 
Value 1 - $.c8y_Restart
 +
 
Value 2 - $.id
 
Value 2 - $.id
 +
 
Value3 - $.deviceId
 
Value3 - $.deviceId
 +
    
Type – responses are identified by a number 11
 
Type – responses are identified by a number 11
Line 249: Line 258:  
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. 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:
   −
-- stream.lua
+
  -- stream.lua
local utl = require "luci.util"
+
  local utl = require "luci.util"
local sys = require "luci.sys"
+
  local sys = require "luci.sys"
 +
  local DEVICE_NAME = 'TLT-RUT955 Router'
 +
  local DEVICE_TYPE = 'Router'
   −
local DEVICE_NAME = 'TLT-RUT955 Router'
+
  function restart(r)
local DEVICE_TYPE = 'Router'
+
      local deviceId = r:value(2)
 +
      c8y:send('108,'..deviceId..',SUCCESSFUL')
 +
      sys.exec("reboot")
 +
  end
   −
function restart(r)
+
  function init()
  local deviceId = r:value(2)
+
      srInfo('*** Stream Init ***')
  c8y:send('108,'..deviceId..',SUCCESSFUL')
+
      -- set device name and type
  sys.exec("reboot")
+
      c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)
end
+
      -- 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 init()
+
   function mobileDataStream()
  srInfo('*** Stream Init ***')
+
      local imei = utl.trim(sys.exec("gsmctl -i"))
 
+
      local cell = utl.trim(sys.exec("gsmctl -C"))
  -- set device name and type
+
      local icc = utl.trim(sys.exec("gsmctl -J"))
  c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)
+
      local type = utl.trim(sys.exec("gsmctl -t"))
 
+
      local oper = utl.trim(sys.exec("gsmctl -o"))
   -- set restart as supported operation
+
      local sign = utl.trim(sys.exec("gsmctl -q"))..' dBm'
  c8y:send('107,'..c8y.ID..',c8y_Restart')
+
      local req = '105,'..c8y.ID
 
+
      req = req..','..imei
  -- set imei, cellid and iccid first time
+
      req = req..','..cell
  mobileDataStream()
+
      req = req..','..icc
 
+
      req = req..','..type
  -- create timer which will stream mobile info data
+
      req = req..','..oper
  local m_timer = c8y:addTimer(10 * 1000, 'mobileDataStream')
+
      req = req..','..sign
  m_timer:start() 
+
      -- send mobile info
 
+
      c8y:send(req)
  -- register restart handler
+
      local wantype = utl.trim(sys.exec("uci get -q network.wan.ifname"))
  c8y:addMsgHandler(502, 'restart')
+
      local wanip = utl.trim(sys.exec("curl -s http://whatismyip.akamai.com"))
  return 0
+
      -- send wan info
end
+
      c8y:send('106,'..c8y.ID..','..wanip..','..wantype)
 
+
  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
        Line 314: Line 313:  
Sending information is quite simple:
 
Sending information is quite simple:
   −
c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)
+
  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.
 
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.
Line 322: Line 321:  
==External Links==
 
==External Links==
 
https://www.cumulocity.com/try-for-free
 
https://www.cumulocity.com/try-for-free
 +
 
https://www.cumulocity.com/guides/reference/smartrest
 
https://www.cumulocity.com/guides/reference/smartrest
 +
 
https://bitbucket.org/m2m/cumulocity-sdk-c/downloads
 
https://bitbucket.org/m2m/cumulocity-sdk-c/downloads
       
{{Template: trademark disclaimer}}
 
{{Template: trademark disclaimer}}
 +
 +
[[Category:IoT]]

Navigation menu