Module packages#
The source code and resources of a module must be within a folder and its subfolders. We’ll refer to this as the module package.
Package definition#
Details of the module package are defined by a package.json file containing a single JSON object.
For example:
{
"name": "Example module",
"description": "A demonstration of an IO module package",
"version": "1.0",
"uuid": "{84bea226-4123-4cc5-be3c-c8adee049e9c}",
"ioModuleApiVersion": "2.0",
"controllerApiVersion": 2,
"author": "Inspired Coding",
"contributors": [
{
"name":"Lady Mary",
"email":"lady.mary@inspiredcoding.com",
"url":"https://www.inspiredcoding.com"
},
{
"name":"John Smith"
}
],
"config": "config.json",
"instanceMain": "instance.lua",
"moduleMain": "module.lua",
"sources": [
"lib/example.lua"
]
}
Full details of the members of the package object are as follows:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Name of the module - will be displayed in Designer in the module library. |
|
string |
No |
A short summary of the module. |
|
string |
Yes |
The version of the module, in the format |
|
string |
Yes |
Unique ID of the module. You’ll need to generate one if writing a module from scratch. Must be in the format |
|
string |
Yes |
The IO module API version required to run this module. Must be in the format |
|
number |
Yes |
The controller API version required to run this module. Must be one of the released Designer Controller API versions. |
|
string |
Yes |
The name of the company or individual who wrote the module. |
|
array |
No |
Array of people who contributed to the module (see Module contributor). |
|
string |
Yes |
Relative path of the configuration JSON file. |
|
string |
Yes |
Relative path of the Lua file executed for each module instance. |
|
string |
No |
Relative path of the Lua file executed before any of a module’s instances are initialised. |
|
array |
No |
Array of additional Lua source files, which may be required from the main Lua file or from other source files in the module. |
Module contributor#
A contributor in the contributors array in the package.json file is a JSON object with the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Name of the contributor. |
|
string |
No |
Email address of the contributor. |
|
string |
No |
A url relating to the contributor, e.g. a personal website or social media profile. |
Configuration#
The configuration JSON file within the module package defines the user interface elements added to Designer when the module is imported into a project, including:
Triggers
Conditions
Actions
Module properties
Module instance properties
Module instance status variables
For example:
{
"shortName":"Projector",
"triggers": [
{
"name": "Connected",
"icon": "icons/connected.svg"
}
],
"conditions": [
{
"name": "Lamp State",
"icon": "icons/lamp_state.svg",
"properties": [
{
"name": "State",
"type": "int",
"editor": {
"type": "dropdown",
"items": [
{
"text": "Off",
"value": 0
},
{
"text": "On",
"value": 1
},
{
"text": "Blown",
"value": 2
}
],
"default": 2
}
}
]
}
],
"actions": [
{
"icon": "icons/lamp_control.svg",
"name": "Lamp Control",
"properties": [
{
"name": "State",
"type": "bool",
"editor": {
"type": "dropdown",
"items": [
{
"text": "On",
"value": true
},
{
"text": "Off",
"value": false
}
],
"default": 1
}
}
]
}
],
"instanceStatusVariables": [
{
"key": "lampState",
"label": "Lamp State",
"type": "string"
}
],
"instanceProperties": [
{
"name": "IP address",
"type": "ipAddress",
"editor": {
"type": "ipAddress",
"default": "0.0.0.0"
}
}
]
}
Full details of the members of the configuration object are as follows:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
If provided, this string will prepended to the names of all triggers, conditions and actions defined by the module when displayed in Designer. In the example above, the trigger named “Connected” will be shown in Designer as “Projector: Connected”. In Lua source, you can still refer to the trigger as “Connected”. |
|
array |
No |
An array of trigger objects (see below). |
|
array |
No |
An array of condition objects (see below). |
|
array |
No |
An array of action objects (see below). |
|
array |
No |
An array of status variables. This can have at most 50 entries. |
|
array |
No |
An array of user properties to be set for each module instance (see User property). |
|
array |
No |
An array of user properties common to every module instance. |
Status Variable#
The instanceStatusVariables array in the configuration JSON object comprises objects with the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
The key of the status variable when accessed from instance scripts. This can only contain characters in the set |
|
string |
No |
The name of the status variable when displayed outside of instance scripts. This may not exceed 120 characters in length. If not specified, |
|
string |
No |
The |
Trigger/Condition/Action object#
The triggers, conditions and actions arrays in the configuration JSON object comprise objects with the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
User-friendly name (will be prepended with configuration |
|
array |
No |
An array of strings, in addition to |
|
string |
No |
Relative path to an image in the module package to be used as an icon for this trigger/condition/action in Designer and on the controller web interface. |
|
array |
No |
An array of user properties to be exposed in the Designer (see User property). |
User property#
The properties array in the configuration JSON object and the trigger/condition/action JSON object comprise objects with the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
User-friendly name that will be displayed next to the property editor in Designer. |
|
array |
No |
An array of strings, in addition to |
|
string |
Yes |
Value type of the property. Supported basic types are: |
|
object |
No |
An editor object for the given |
|
bool |
No |
Whether this property may be set from a trigger variable. Only applies to action and condition (since Designer 2.12.1) properties. Default is true if not specified. |
User property editor#
The editor object in user properties always has the following type member:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Type of the user interface control to be used for the editor. Supported types are: |
Depending on the type, the editor object has additional members as detailed in the following sections.
Drop down editor#
An editor of type dropdown has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
array |
Yes |
Items to populate the drop down editor (see below). |
|
number |
No |
Index into the |
The items array of a dropdown editor comprises objects with the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
User-friendly text that will be displayed in the drop down editor for this item. |
|
Must match the |
Yes, unless the parent property is of |
Value that will be set on the property when this item is chosen by the user. |
Multiselect Drop down editor#
Similar to dropdown, a multidropdown can have multiple items selected. The result is returned as a Lua table of value.
An editor of type multidropdown has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
array |
Yes |
Items to populate the drop down editor (see below). |
|
array of numbers |
No |
Indexes into the |
|
string |
No |
Placeholder text for the editor when no items are selected. |
|
bool |
No |
Adds the special Any item to the top of the list. Selecting this item will automatically select all other items. |
The items array of a multidropdown editor comprises objects with the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
User-friendly text that will be displayed in the drop down editor for this item. |
|
Must match the |
Yes, unless the parent property is of |
Value that will be set on the property when this item is chosen by the user. |
Spin box editor#
An editor of type spinbox has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
number |
No |
Minimum value of the property; default is 0. |
|
number |
No |
Maximum value of the property; default is 255. |
|
number |
No |
Increment/decrement for up/down arrows of the spin box editor; default is 1. |
|
string |
No |
Text to display after the value in the editor. |
|
number |
No |
Default value of the property for new instances; default is 0. |
|
string |
No |
Text to display in the property editor instead of a numeric value when the current value is equal to |
|
integer |
No |
The numerical base in which to display the value, e.g. Base-16 would be Hex; default is 10. |
Double spin box editor#
An editor of type doubleSpinbox has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
number |
No |
Minimum value of the property; default is 0.0. |
|
number |
No |
Maximum value of the property; default is 1.0. |
|
number |
No |
Increment/decrement for up/down arrows of the spin box editor; default is 0.1. |
|
string |
No |
Text to display after the value in the editor. |
|
number |
No |
Precision of the spin box - how many decimals the editor will use to display and interpret values; default is 2. |
|
number |
No |
Default value of the property for new instances; default is 0.0. |
|
string |
No |
Text to display in the property editor instead of a numeric value when the current value is equal to |
IP address editor#
An editor of type ipAddress has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
Default IP address for new instances; editor will be blank (invalid) if default not specified. |
Toggle editor#
An editor of type toggle (a check box) has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
bool |
No |
Default state of the check box for new instances; default is false (unchecked). |
Line editor#
An editor of type lineEdit has the following members:
Name |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
Placeholder text for the editor when its string value is empty. |
|
string |
No |
Regular expression to match for a valid user input. See the note on regular expressions below. |
|
string |
No |
Default string value of the property for new instances. |
Regular expressions#
Good references about regular expressions include the Perl regular expression documentation and the Perl regular expression tutorial.
Note that you must escape all backslashes in a pattern string with another backslash. For example, to match two digits followed by a space and a word:
"validator": "\\d\\d \\w+"
Resource property types#
Where IO modules need to interact with finite resources on the controller, such as a serial port, the property type should be set to a special resource type. This allows Designer to track the use of these resources to avoid conflicts with other modules and with other triggers and actions.
Resource types do not support custom editors - a standard editor will be presented to the user for these property types.
Digital input#
Set user property type to value digitalIn.
Digital inputs are available on controllers and remote devices. To listen for changes in the state of a digital input, you must have at least one of these properties in the configuration.
Digital output#
Set user property type to value digitalOut.
Digital outputs are available on some remote devices. To control the state of a digital output, you must have at least one of these properties in the configuration.
Analog input#
Set user property type to value analogIn.
Analog inputs are available on controllers and remote devices. To listen for changes in the level of an analog input, you must have at least one of these properties in the configuration.
Serial interface#
Set user property type to value serial.
Serial interfaces are available on controllers and remote devices. To send/receive data on a serial interface in an IO module, you must have at least one of these properties in the configuration.
Universe key#
Set user property type to value universeKey.
UniverseKey are available on controllers and remote devices.
Icons#
Image files referenced by the configuration JSON file for module triggers, conditions and actions need to be included in the module package. They may be in a subfolder, as long as the configuration JSON file has the correct relative paths.
We recommend using SVG images for your module icons - they scale well for use on high DPI monitors. IO modules also support PNG and JPEG images as icons — we recommend you generate them with dimension 64 pixels.
Lua sources#
IO module functionality is written in Lua. Two specified Lua sources act as entry points. The instanceMain file is executed for each module instance, and is a required part of the package. The optional moduleMain file is executed for each module and can manage data common to all instances of a module. These files may require other Lua files within the module package. All Lua files included through require must be listed in the sources array in package.json.
For example, in package.json, you might have:
{
"moduleMain": "module_main.lua",
"instanceMain": "instance_main.lua",
"sources": [
"lib/example.lua"
]
...
Then in instance_main.lua or module_main.lua you can write:
require('example')
The string passed to require may be a file base name, as shown above, or a path to a Lua file within the module package, e.g. lib/example.lua.
Documentation#
A module may include a single readme.md file in the same folder as package.json, written in CommonMark. This will be displayed to the user in the module management user interface in Designer.