Page cover

Scripts

Automate your workflow with tasks based on events, jobs, schedules, and more. Limitless capabilities with custom resources to fit your needs.

Introduction

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.

LUA 5.1 Manual

How It Works

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.

Diagram of Lua Scripts

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:

  1. Serial Number [string]

    The CPE unique identifier.

  2. 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:

  • In the case of a successful transaction each key of the table will correspond to one of the parameters requested in the payload.

Example:

send_cwmp_message()

Params:

  1. Serial Number [string]

    The CPE unique identifier.

  2. XML payload [string]

    Request body to be sent to the CPE.

  3. Message Type [integer]

    CWMP message type. 0 = getParameterValues 1 = setParameterValues 2 = addObject 3 = deleteObject 4 = getParameterNames

Return:

The data returned depends on the TR-069 message type:

  • If the CWMP message generates an error:

  • If it is a read or add operation the function will return a table.

  • If it is a delete or set operation the data returned will be a boolean indicating if the result was a success or failure.

Example:

send_cwmp_async_message()

Works the same way as the send_cwmp_message() function, but does not use the CWMP Connection Request mechanism, which means this RPC will only reach the CPE in the next Inform event of it. This allows to reach CPEs behind NAT, although it takes longer for the RPC to reach and be processed by the device.

listen_to_cwmp_event()

Listen to TR-069 events as defined in the standard.

Params:

  1. Event [string] (optional) Possible events:

    If no value is set or the value is "*", than it listens to all events.

  2. Serial Number [string] (optional) CPE unique identifier. If it's not set or the value is "*", then it listens to all CPEs event(s).

  3. Callback function (required)

  4. Number of events to process in parallel [integer] (optional)

Return:

Example:

get_device()

Get device attributes from its unique identifier.

Params:

  1. 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:

Example:

listen_to_new_device()

Receive all new device attributes that connect to Oktopus, independent of the protocol.

Params:

  1. Callback function with new device data

Example:

sleep()

Blocks the code execution for certain time.

Params:

  1. Time duration [integer] Seconds of blocking the code execution.

Example:

create_or_update_device_credential()

Params:

  1. Username [string]

  2. Password [string]

Return:

Bool value indicating true if the operation was successfull or false if there was an error.

Example:

generate_random_string()

Params:

  1. Length [int] Size of the string to be generated

Example:

delete_device()

Remove device from database.

Params:

  1. Serial Number [string]

    The unique identifier of the CPE to be removed.

Return:

Bool value indicating true if the operation was successfull and the device was removed from database or false if there was an error.

Example:

get_all_devices()

Retrieve all devices saved on the database.

Return:

List of device objects.

Example:

refresh_device_parameters()

Sync device saved parameters, as PPPoE user, IP address and WAN MAC.

Params:

  1. Serial number / USP agent endpoint id [string] The unique identifier of the CPE to be removed.

Return: Bool value indicating f the operation was successfully executed ot not.

Example:

Last updated

Was this helpful?