Skip to content

pass parent id to provision constrained ubus call #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions src/cgi-bin/provision_constrained.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function provision_constrained()
local selected_device_id_array = cgilua.POST.device_id
local tempTable = {}
local timeout = 60000
local fcap_string, fcap_code, fcap_found, ret, constrained_dev_id,
local key_string, fcap_code, key_found, device_id, licensee_code, ret, constrained_dev_id,
provision_status_code, constrained_dev_type = "Unknown device"

if type(selected_device_id_array) == "string"
Expand All @@ -20,7 +20,7 @@ function provision_constrained()
return 254
end

-- Get fcap from flow_access.cfg
-- Get fcap and device id from flow_access.cfg
local file = io.open("/etc/lwm2m/flow_access.cfg", "r")
if not file then
conn:close()
Expand All @@ -32,13 +32,39 @@ function provision_constrained()

if line == nil then break end

fcap_found = string.find(line, "FCAP")
if fcap_found ~= nil then
fcap_string = line:match('%b\"\"')
fcap_code = fcap_string:gsub("\"", "")
key_found = string.find(line, "FCAP")
if key_found ~= nil then
key_string = line:match('%b\"\"')
fcap_code = key_string:gsub("\"", "")
end

key_found = string.find(line, "DeviceID")
if key_found ~= nil then
key_string = line:match('%b\"\"')
device_id = key_string:gsub("\"", "")
end
end

-- Get licensee id from provision.cfg
local file = io.open("/etc/lwm2m/provision.cfg", "r")
if not file then
conn:close()
return 1
end

while true do
local line = file:read("*l")

if line == nil then break end

key_found = string.find(line, "LicenseeId")
if key_found ~= nil then
key_string = line:match('%b\"\"')
licensee_code = key_string:gsub("\"", "")
end
end

licensee_code = tonumber(licensee_code);

local count = table.getn(selected_device_id_array)
for i = 1, count do
Expand All @@ -57,7 +83,8 @@ function provision_constrained()

-- Call provision constrained device function registered on ubus
ret = conn:call("flow_device_manager", "provision_constrained_device", {fcap = fcap_code,
licensee_id = 7, device_type = constrained_dev_type, client_id = constrained_dev_id})
licensee_id = licensee_code, device_type = constrained_dev_type,
client_id = constrained_dev_id, parent_id = device_id})

if ret ~= nil then
provision_status_code = ret["status"]
Expand Down