MQTT API
Device Registration
In order for a Gumband Hardware device to become fully registered in the system the following sequence must be followed. The definitions for the endpoints and payloads are defined in the sections below.
API Endpoint Summary
<ID>: componentId of the device<source>:system,appendpoint/<CMD>replaced by value referenced "->" e.g. ->set,get
Note: endpoints with
<CMD>are sent to the device, the endpoints without are sent from the device.
Info
<ID>/<source>/<CMD>->get<ID>/<source>/info<ID>/<source>/info/<CMD>->set,get
Log
<ID>/<source>/log
Registration
<ID>/<source>/register/prop<ID>/<source>/register/prop/<CMD>->get<ID>/<source>/register/prop/<CMD>/<property path>->get
Connections (System only)
<ID>/system/connections<ID>/system/connections/<CMD>→set,get<ID>/system/connections/<index>/<CMD>→set,get
Prop
<ID>/<source>/prop/<CMD>→set,get<ID>/<source>/prop/pub/<array range>/<property path><ID>/<source>/prop/<CMD>/<array range>/<property path>->set,get
Source Information Endpoint
<ID>/<source>/get
This endpoint will request information from several child endpoints
See individual source docs for specific payloads & sequences
Information Endpoint
<ID>/<source>/info
Each info message will be published to a connection once it is available, and can be requested anytime.
See individual source docs for specific payloads & sequences
Request Information
<ID>/<source>/info/get
Information can be requested by publishing an empty payload to the get endpoint. The hardware will publish the information to the base <ID>/<source>/info endpoint in response.
Edit Information
<ID>/<source>/info/set
Some information can be changed by publishing to the set endpoint. The hardware will publish the updated information to the base <ID>/<source>/info endpoint as confirmation.
Log Endpoint
<ID>/<source>/log
Logs will be published as they occur, and include both severity and text fields.
severity: debug, error, warning
{
"severity": "debug",
"text": "<log text>"
}
Property Registration Endpoint
<ID>/<source>/register/prop
Properties are dynamic endpoints that can be interacted with. Property registration is sent after the information message (<ID>/<source>/info). Each
property will publish to this prop endpoint in succession. The number of property registration payloads published should equal that listed in the "num_props"
field in listed the information message (<ID>/<source>/info). The property registration can be requested anytime by requesting the information message;
the property registration will be republished with it.
{
"path": "power", // Can be "Group Name/Prop Name" like "motor/power".
"desc": "More about what the property is", // Description that can be used for hover-over text. Blank if not used.
"index": ##, // Index of the property, can be used to validate expected count listed in information registration
"type": "gmbnd_primitive",
"format": "i", // Packed data format via pickling, predefined types have a set format.
"length": 1, // Length is 0 for gmbnd_trigger
"settable": true,
"gettable": true,
"min": 0, // (Optional) range. We don't provide this for string, color, trigger, and LED types.
"max": 100, // (Optional) ^^
"step": 10, // (Optional) Step for range. Can be used for setting intervals for a slider in the UI.
"ui_hidden": true // (Optional) UI-specific stuff
}
Property paths cannot be empty/blank. They cannot start or end with a forward-slash '/'. They cannot include wildcard symbols '$', '#', or '+'. They cannot include non-printable characters.
Ex: The property "" is invalid The properties "/position" and "position/" are invalid The property "x+y corrdinates" is invalid
Request Property Registration
<ID>/<source>/register/prop/get
Gets all of the registered properties for the source. This is equivalent to what gets sent during property registration.
Request Individual Property Registration
<ID>/<source>/register/prop/get/<property path>
Get a property registration based on its property path.
Property Endpoints
<ID>/<source>/prop/<action>/<array range>/<property path>
Once a property's information has been registered with the register/prop endpoint, it can be interacted through its unique property endpoint. A property's
"path" field from from its registration is appended onto the base prop/<action>/<array range> endpoint to build its unique property endpoint.
Ex: The "temperature" property has the endpoint
<ID>/<source>/prop/<action>/<array range>/temperature
Currently, the only syntax that is supported for the array range is ":", meaning "the whole array"
The hardware can publish to the property pub endpoint either when the value changes, on a pre-determined interval, or on-demand though logic in the user
application code. The source of truth for these values lives on the hardware, but they can be edited or requested anytime using the set and get endpoints (see below).
A property's "path" field can be multi-level, separated by forward-slashes "/". This can be helpful for organizing properties into features or hardware components. The last level of the hierarchy is considered the property’s name and each level before it are considered groups.
Property Types
Property data payloads are packed according to the format and length listed in its property information, based on Python struct packing.
Anything that can be described solely from the format considered gmbnd_primitive type.
Ex: gmbnd_int in user code is registered as a gmbnd_primitive type with format "i". It represents a signed integer value. gmbnd_text in user code is registered as a gmbnd_primitive type with format "s". It represents a UTF-8 encoded string.
Note that the trigger type has an empty format. It sends and receives only empty payload messages so it can trigger events.
Ex: gmbnd_trigger in user code is registered as a gmbnd_primitive type with empty format "".
Special-cases will be given a pre-determined type where extra context is needed.
Ex: gmbnd_color in user code is registered as a gmbnd_color type with format “4B”. It represents 4 values: white, red, green, and blue. (It’s a hex color code! 0xRRGGBB)
Property Types: Payload Formats
Trigger gmbnd_primitive
- Format:
"" - Bytes:
0 - Array Support: No (array length is always 0)
- Min/Max/Step Support: No
The trigger type is a data-less type that "triggers" the property, similar to an interrupt or event. There is no data payload format associated with the trigger type because it does not use one. The payload message body should be empty.
Note: if the payload isn't empty, it should just be ignored (and not ocnsidered an error).
Bool gmbnd_primitive
- Format:
"?" - Bytes:
1 - Array Support: Yes
- Min/Max/Step Support: No
The bool type is a Boolean type with two states: true or false.
Example Payloads:
Single: [0x01] -> [True]
Array: [0x01,
0x00,
0x01] -> [True, False, True]
Byte gmbnd_primitive
- Format:
"B" - Bytes:
1 - Array Support: Yes
- Min/Max/Step Support: Yes
The byte type is an 8-bit number, ranging from 0 to 255.
Example Payloads:
Single: [0xFF] -> [255]
Array: [0x0B,
0x0A,
0x0D] -> [11, 10, 13]
Integer gmbnd_primitive
- Format:
"i" - Bytes:
4 - Array Support: Yes
- Min/Max/Step Support: Yes
The integer type is a 32-bit integer type that support signed numbers.
Example Payloads:
Single: [0xFF, 0xFF 0xFF 0xFF] -> [-1]
Array: [0x00, 0x00, 0x0B, 0xB8,
0xFF, 0xFF, 0xF4, 0x48] -> [3000, -3000]
Floating Point gmbnd_primitive
- Format:
"d" - Bytes:
8 - Array Support: Yes
- Min/Max/Step Support: Yes
The floating point type is a 64-bit IEEE 754 double-precision floating-point formatted type that supports decimal and exponential numbers.
Example Payloads:
Single: [0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB, 0x85, 0x1F] -> [3.14]
Array: [0xBF, 0xBF, 0x97, 0x24, 0x74, 0x53, 0x8E, 0xF3,
0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB, 0x85, 0x1F] -> [-0.1234, 3.14]
Text gmbnd_primitive
- Format:
"s" - Bytes: Uses the array length for max text length
- Array Support: No
- Min/Max/Step Support: No
The text type is a string (UTF-8 encoded). The maximum number of characters the property supports is the array length sent during registration.
Example Payloads:
Single: [0x67] -> ["g"]
Array: [0x48, 0x65, 0x6C, 0x6C, 0x6F] -> ["Hello"]
UTF8: [0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD] -> ["你好"]
Color gmbnd_color
- Format:
"4B"or"BBBB" - Bytes:
4 - Array Support: Yes
- Min/Max/Step Support: No
The color type is an RGB hex color code with ARGB32 byte ordering. While compatible with 3 and 6 length RGB CSS color codes, it is NOT compatible with 8 length RGBA codes because of the position of the alpha value.
Example Payloads:
Single: [0x12, 0x34, 0x56, 0x78] -> {
alpha: 0x12, (or white)
red: 0x34,
green: 0x56,
blue: 0x78
}
Array: [0x12, 0x34, 0x56, 0x78,
0x9A, 0xBC, 0xDE, 0xF0] -> [
{
alpha: 0x12, (or white)
ret: 0x34,
green: 0x56,
blue: 0x78
},
{
alpha: 0x9A, (or white)
ret: 0xBC,
green: 0xDE,
blue: 0xF0
}
]
Publish Property Value
<ID>/<source>/prop/pub/<array range>/<property path>
The base property endpoint where properties are published.
Get Property Value
<ID>/<source>/prop/get/<array range>/<property path>
The current value of a property can be requested by publishing an empty payload to its get endpoint. The hardware will publish the value to its base
<ID>/<source>/prop/pub/<property path> endpoint in response.
Set Property Value
<ID>/<source>/prop/set/<array range>/<property path>
Some properties can be written to by publishing a formatted payload to its set endpoint. The hardware won’t publish any response.
System
System can be treated as the “operating system” layer of the hardware. Its information and interactions should happen regardless of whether there is a user application loaded or not.
System Get
<ID>/system/get
Gets the same response as if the following commands were called one after another:
<ID>/system/info/get<ID>/system/register/prop/get<ID>/system/connections/get
System Information
<ID>/system/info
This is sent immediately as the first message of registration. It contains the device name, capabilities, and most importantly the API version it’s using to communicate.
See general info endpoint
{
// Gumband-Library Information
"api_ver": ##, // Gumband HW Message API version
"gb_lib_ver": "##.##.##", // (Optional) Gumband Library version. Just for displaying in the UI.
// Hardware-Component Information
"name": "My Device", // Device HW name
"type": "presence", // generic, presence, temp, etc.
"capabilites": [ "OTA", "filesystem" ], // Device capabilties
"num_props": ##, // Number of system props (heartbeat, temperature, voltage, etc.)
"platform": // Physical board/platform information (Not currently used. Just for display purposed in the UI. Can be used for OTA fw update file type hinting)
{
"name": "PSoC", // Clipboard, Bundle, EPS32, PicoW, etc.
"variant": "module", // (Optional) Module, breakout, or ESP32-S2-SOLO, etc.
"ver": "0.0", // (Optional) Some board version, etc.
"gb_pkg_ver": "##.##.##", // (Optional) Gumband Library Support Package version. Just for displaying in the UI.
"bootloader_ver": "##.##", // (Optional) Bootloader version if device supports it
},
// Network info
"mac": "MAC_ADDRESS",
"ip": "IP_ADDR"
}
Example: Editing the Device Name
Publish a message to the
<ID>/system/info/setendpoint with the edit to the device name. The value will be the new device name. If successful, the hardware should re-send its system info to all active connections to inform them of the name change.Note: if the name provided is too long, it will be truncated. The length limit on the names is platform/hardware dependent.
{
// Hardware-Component Information
"name": "My hardware device", // new device name
}