MOS350 GPIO Integration
Version 1.0
The MOS350 GPIO Config file is a JSON file that defines GPIO pin integration settings. This document covers all elements of the GPIO configuration definition file and their usage. Configuration files use the extension .cf.
MOS350 includes a built-in Blockly visual editor that simplifies building config files without writing JSON by hand. The editor provides drag-and-drop blocks for all config elements and generates the .cf file automatically. Manual JSON editing is only needed for advanced or custom use cases.
Top-Level Elements
| Element | Type | Description |
|---|---|---|
VER | string | File version |
TYP | integer | Integration type. 1 = GPIO |
FLG | integer | Global flags. 1 = Auto Load |
MAP | array | Array of GPIO pin definitions |
Example
{
"VER": "1.0",
"TYP": 1,
"FLG": 1,
"MAP": []
}
MAP — GPIO Pin Definitions
MAP is an array of pin objects. Each object maps a named pin to its hardware configuration.
| Element | Type | Description |
|---|---|---|
NM | string | Pin name used to reference this pin in automation |
TYP | integer | GPIO access type. See GPIO Access Types |
PIN | string | Pin number or offset, depending on access type |
DIR | integer | Pin direction. 1 = Output, 0 = Input |
CHIP | integer | Chip number. Required when TYP is 3 (GPIO Device), ignored otherwise |
ALOW | integer | Active low. 1 = active low, 0 = active high (default) |
GPIO Access Types
| Value | Description |
|---|---|
1 | Sys Class — uses sys/class/gpio |
2 | Kernel Driver — uses sys/class/<pin> |
3 | GPIO Device — uses gpioget / gpioset with a chip number and pin offset |
4 | Custom |
Example
{
"VER": "1.0",
"TYP": 1,
"FLG": 1,
"MAP": [
{
"NM": "GRID_SENSE",
"TYP": 1,
"PIN": "17",
"DIR": 0,
"CHIP": 0,
"ALOW": 0
},
{
"NM": "RELAY_OUT",
"TYP": 3,
"PIN": "4",
"DIR": 1,
"CHIP": 0,
"ALOW": 0
}
]
}
Example — InHand Gateway (4 Digital Outputs, Active Low)
{
"VER": "1.0",
"TYP": 1,
"FLG": 1,
"MAP": [
{ "NM": "DO1", "TYP": 1, "PIN": "491", "DIR": 1, "CHIP": 0, "ALOW": 1 },
{ "NM": "DO2", "TYP": 1, "PIN": "492", "DIR": 1, "CHIP": 0, "ALOW": 1 },
{ "NM": "DO3", "TYP": 1, "PIN": "493", "DIR": 1, "CHIP": 0, "ALOW": 1 },
{ "NM": "DO4", "TYP": 1, "PIN": "494", "DIR": 1, "CHIP": 0, "ALOW": 1 }
]
}
Four digital output pins accessed via Sys Class (TYP: 1), mapped to sequential pin numbers starting at 491. All outputs are active low (ALOW: 1), meaning a logical 1 drives the pin low.
Using GPIO in Lua Scripts
Once configured, GPIO pins are accessible in Lua automation scripts via getDeviceState() and setDeviceState(). Reference the device by its user variable name (e.g. "_GPIO1") or device ID.
-- Read an input pin
local status, value = getDeviceState("_GPIO1")
if status then
print("GPIO state:", value)
end
-- Write to an output pin
setDeviceState("_GPIO1", 1)
See the Lua Scripting documentation for the full getDeviceState() and setDeviceState() API reference.