Code is wrritten in Lua, which is a lightweight, high-level programming language designed for embedded use, known for its simplicity and efficiency. Created in Brazil in 1993, it features dynamic typing, first-class functions, and a powerful table data structure, making it versatile for various applications. Lua is widely used in game development for scripting game logic, as well as in embedded systems and applications due to its extensibility and small footprint, allowing developers to easily integrate it with other languages and platforms.
To extend Oktopus capabilities and adress the most diverse possible use cases we opted to use a scripting language on top of the actual code, so the gopher-lua library provides Go APIs that allows to easily embed LUA scripts to Go programs.
The Go software can interact to the LUA script and vice-versa. That way, it's possible to pass functions, parameters and events through both USP Controller/ACS and the user created automations.
Core Concepts
A "custom function", is as a function called from LUA which translates to a Go function that can interact with NATS, MongoDB, USP Controller, TR-069 ACS and all the other components of the software stack.
The "custom functions" will be detailed above in the next topics as just "functions" and separated into domain areas. We hope to provide usefull examples, and the limitation is on each person creativity.
Functions
send_usp_message()
Params:
Serial Number [string]
The CPE unique identifier.
JSON payload [string]
Request body to be sent to the CPE.
Current supported bodies are :
- Get
- Set
Return:
If the usp message generates an error:
{
"error_message": "error to set param test.software",
"error_code: "500"
}
In the case of a successful transaction each key of the table will correspond to one of the parameters requested in the payload.
Example:
local uspMsg = [[
{
"header": {
"msg_id": "b7dc38ea-aefb-4761-aa55-edaa97adb2f0",
"msg_type": 1
},
"body": {
"request": {
"get": {
"paramPaths": [
"Device.STOMP."
],
"maxDepth": 2
}
}
}
}
]]
local serial_number = "oktopus-0-stomp"
local uspMessageResult = send_usp_message(serial_number, uspMsg)
if uspMessageResult["error_message"] ~= nil then
print("SN: " .. serial_number .. " | Error Message: " .. uspMessageResult["error_message"] .. " | Code: " .. uspMessageResult["error_code"])
else
for key, value in pairs(uspMessageResult) do
print(key .. ": " .. value)
end
end
local uspMsg = [[
{
"header": {
"msg_id": "b7dc38ea-aefb-4761-aa55-edaa97adb2f0",
"msg_type": 4
},
"body": {
"request": {
"set": {
"allow_partial":true,
"update_objs":[
{
"obj_path":"Device.LocalAgent.",
"param_settings":[
{
"param":"X_VANTIVA-COM_PreConnectTimeout",
"value": "55",
"required":true
}
]
}
]
}
}
}
}
]]
local serial_number = "oktopus-0-stomp"
local uspMessageResult = send_usp_message(serial_number, uspMsg)
if uspMessageResult["error_message"] ~= nil then
print("SN: " .. serial_number .. " | Error Message: " .. uspMessageResult["error_message"] .. " | Code: " .. uspMessageResult["error_code"])
else
for key, value in pairs(uspMessageResult) do
print(key .. ": " .. value)
end
end
while true do
local cwmp_event = listen_to_cwmp_event("2")
print("CWMP event " .. cwmp_event.event .. ", triggered by device: " .. cwmp_event.serial_number)
end
get_device()
Get device attributes from its unique identifier.
Params:
Serial Number [string]
The CPE unique identifier.
Return:
If the CPE was not found in the database the function returns a boolean with false value. In case the CPE is found it returns a table with all attributes:
SERIAL_NUMBER = "HUAWNFYC-35454645"
local deviceAttributes = get_device(SERIAL_NUMBER)
if type(deviceAttributes) == "boolean" then
print("device " .. SERIAL_NUMBER .. " not found")
else
for key, value in pairs(deviceAttributes) do
print(key .. ": " .. value)
end
end
listen_to_new_device()
Receive all new device attributes that connect to Oktopus, independent of the protocol.