Line 250: |
Line 250: |
| 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_NAME = 'TLT-RUT955 Router' |
− | local DEVICE_TYPE = 'Router' | + | local DEVICE_TYPE = 'Router' |
| | | |
− | function restart(r) | + | function restart(r) |
− | local deviceId = r:value(2)
| + | local deviceId = r:value(2) |
− | c8y:send('108,'..deviceId..',SUCCESSFUL')
| + | c8y:send('108,'..deviceId..',SUCCESSFUL') |
− | sys.exec("reboot")
| + | sys.exec("reboot") |
− | end | + | end |
| | | |
| 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') |
− | return 0
| + | return 0 |
− | end | + | end |
| | | |
− | function mobileDataStream() | + | function mobileDataStream() |
− | local imei = utl.trim(sys.exec("gsmctl -i"))
| + | local imei = utl.trim(sys.exec("gsmctl -i")) |
− | local cell = utl.trim(sys.exec("gsmctl -C"))
| + | local cell = utl.trim(sys.exec("gsmctl -C")) |
− | local icc = utl.trim(sys.exec("gsmctl -J"))
| + | local icc = utl.trim(sys.exec("gsmctl -J")) |
− | local type = utl.trim(sys.exec("gsmctl -t"))
| + | local type = utl.trim(sys.exec("gsmctl -t")) |
− | 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 |
− | req = req..','..cell
| + | req = req..','..cell |
− | req = req..','..icc
| + | req = req..','..icc |
− | req = req..','..type
| + | req = req..','..type |
− | 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) |
− | end | + | end |
| | | |
| | | |