Changes

51 bytes added ,  13:47, 2 May 2018
Line 168: Line 168:  
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 253: Line 253:  
   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_NAME = 'TLT-RUT955 Router'
 
   local DEVICE_TYPE = 'Router'
 
   local DEVICE_TYPE = 'Router'
Line 265: Line 264:  
   function init()
 
   function init()
 
       srInfo('*** Stream Init ***')
 
       srInfo('*** Stream Init ***')
   
       -- set device name and type
 
       -- set device name and type
 
       c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)
 
       c8y:send('103,'..c8y.ID..','..DEVICE_NAME..','..DEVICE_TYPE)
   
       -- set restart as supported operation
 
       -- set restart as supported operation
 
       c8y:send('107,'..c8y.ID..',c8y_Restart')
 
       c8y:send('107,'..c8y.ID..',c8y_Restart')
   
       -- set imei, cellid and iccid first time
 
       -- set imei, cellid and iccid first time
 
       mobileDataStream()
 
       mobileDataStream()
   
       -- create timer which will stream mobile info data
 
       -- create timer which will stream mobile info data
 
       local m_timer = c8y:addTimer(10 * 1000, 'mobileDataStream')
 
       local m_timer = c8y:addTimer(10 * 1000, 'mobileDataStream')
 
       m_timer:start()   
 
       m_timer:start()   
   
       -- register restart handler
 
       -- register restart handler
 
       c8y:addMsgHandler(502, 'restart')
 
       c8y:addMsgHandler(502, 'restart')
Line 291: Line 285:  
       local oper = utl.trim(sys.exec("gsmctl -o"))
 
       local oper = utl.trim(sys.exec("gsmctl -o"))
 
       local sign = utl.trim(sys.exec("gsmctl -q"))..' dBm'
 
       local sign = utl.trim(sys.exec("gsmctl -q"))..' dBm'
   
       local req = '105,'..c8y.ID
 
       local req = '105,'..c8y.ID
 
       req = req..','..imei
 
       req = req..','..imei
Line 299: Line 292:  
       req = req..','..oper
 
       req = req..','..oper
 
       req = req..','..sign
 
       req = req..','..sign
   
       -- send mobile info
 
       -- send mobile info
 
       c8y:send(req)
 
       c8y:send(req)
   
       local wantype = utl.trim(sys.exec("uci get -q network.wan.ifname"))
 
       local wantype = utl.trim(sys.exec("uci get -q network.wan.ifname"))
 
       local wanip = utl.trim(sys.exec("curl -s http://whatismyip.akamai.com"))
 
       local wanip = utl.trim(sys.exec("curl -s http://whatismyip.akamai.com"))
 
   
       -- send wan info
 
       -- send wan info
 
       c8y:send('106,'..c8y.ID..','..wanip..','..wantype)
 
       c8y:send('106,'..c8y.ID..','..wanip..','..wantype)
0

edits

Navigation menu