Connection & Authentication
A Lixel device runs a built-in MQTT broker and RTSP service. Real-time control and the real-time point cloud go over MQTT; the real-time video goes over RTSP. The device supports both wired and wireless networking with other devices: wired over a USB cable, wireless over Wi-Fi.
Connection parameters
Each product model supports only one of the connection protocols (not both):
| Protocol | Port | Username | Password | Product model |
|---|---|---|---|---|
| MQTT | 1883 | — | — | K1 / L2PRO |
| MQTTS | 8883 | Provided by the vendor | Provided by the vendor | All models other than K1 / L2PRO, e.g. K2, L3, H1, F1, Porcam |
- MQTT version: V3.1.1
- Wired networking uses the fixed IP
192.168.55.1; for wireless networking the IP is obtained over Bluetooth. - In Quick Connect mode the device IP is fixed at
192.168.56.1.
Note: MQTTS uses TLS; when MQTTS is selected, pass the vendor-provided username and password. Certificate verification depends on the client:
- The Python client and OpenAPI-XPanel do not verify the device certificate. The client cannot confirm it is really talking to the device; a man-in-the-middle on the same network can impersonate the device and read the MQTT username and password, the
openapi_keyif one is set, and all the data.- The C++ client verifies the device certificate by default. The K2 and L3 device certificate is issued by the CA certificate
certs/lixel_mqtts_ca.crtin the example project; connect with--ca-file certs/lixel_mqtts_ca.crt --no-verify-hostname. See C++ · TLS certificate checks.For production, use the C++ client with the CA check on.
USB connection
Devices running Linux, Windows, or Android share the network with the Lixel device over RNDIS; iOS devices use USB Tethering.
Lixel device (192.168.55.1) other device
+---------+ +---------+
| USB | <----- RNDIS / USB Tethering ----> | USB |
+---------+ +---------+
Wi-Fi connection
The device supports three wireless modes:
- Normal mode: another device acts as the hotspot.
- Quick Connect mode: the Lixel device acts as the hotspot.
- Bridge mode: a router is used.
All modes require network provisioning over Bluetooth first. The device accepts a Bluetooth connection to configure Wi-Fi so it can join a given network.
The device's Bluetooth name has 10 characters: most models use the fixed prefix XGR- plus the last 6 digits of the SN, e.g. XGR-A12345; some ODM models use a different prefix (e.g. PCAM). Follow the name you actually scan.
Lixel device other device
+---------+ +---------+
| BT | <----- Bluetooth (provisioning) --> | BT |
| WiFi | <----- WiFi (data) ---------------> | WiFi |
+---------+ +---------+
Provisioning flow
The BLE provisioning flow between the device and the client: the client, as the master, searches for and connects to the device (the slave); after connecting, the device first sends its current Wi-Fi status; if Wi-Fi is not connected, the client sends the Wi-Fi info (SSID and password) and the device joins the target network.
Lixel device client
+----------------------+ +----------------------+
| BLE slave mode | | BLE master mode |
+----------+-----------+ +----------+-----------+
| |
v <---- connecting ----> v
+----------------------+ +----------------------+
| send WiFi status | ------------------> | get WiFi status |
+----------+-----------+ +----+------------+----+
| | |
| WiFi not | | WiFi
| connected | | connected
| <------ send WiFi info ----------- | |
v v v
+----------------------+ +----------------------+
| connect to WiFi | | end |
+----------------------+ +----------------------+
OpenAPI authorization and key
openapi_key is an optional field of the request header. A device that holds an active OpenAPI authorization (state active) needs no key: leave openapi_key empty (the default) and the client sends none. The authorization is granted by XGRIDS; this SDK cannot grant or install it. The authorization state can be read from the heartbeat, and the authorization code and the remaining recording minutes with openapi_license; see Interface Catalog · Query the OpenAPI authorization.
Other devices still need a valid key: a device that is not authorized, one whose authorization is used up, and one still on the earlier key-based scheme (the scheme of 1.x). A valid key is accepted by every kind of device, so the same program can talk to all of them; set the key only for a device that needs it.
How the device handles a request
For each request the device decides in this order:
- The header carries a valid
openapi_key, and on a device that checksdevice_idthedevice_idmatches: the request is executed as in 1.x. It is not metered and does not depend on the authorization state. - The header carries a valid
openapi_key, but thedevice_iddoes not match:error.codeisEC_ProtoErroranderror.descisdevice auth error. - The header carries no
openapi_key, or a wrong one (a wrong key is treated like no key): the authorization state of the device decides, as in the table below.
| Device | Without a key (or with a wrong key) | With a valid key |
|---|---|---|
Authorized (active) | Executed | Executed (not metered) |
Authorization used up (expired) | EC_ProtoError, desc is openapi license exhausted | Executed |
Supports authorization but not authorized (none) | EC_ProtoError, desc is openapi auth error | Executed |
Earlier key-based scheme (the heartbeat has no Features) | EC_ProtoError, desc is openapi auth error | Executed |
EC_ProtoError is 0x32040001. In every error case above the device still replies, the response carries no business data, and request() returns normally without a timeout. The heartbeat is a report you subscribe to and does not depend on the key.
All 13 request/response interfaces in the Interface Catalog other than openapi_license behave this way, device_info included. The Lixel L2Pro has no data_unpack topic and does not respond to it, with or without a key, so on a Lixel L2Pro the interfaces that work without a key are the other 12.
openapi_license does not check the key: it can be queried in every authorization state, with or without a key, and with a wrong one, and it is not metered. A device on the earlier key-based scheme has no such topic, and a request to it times out.
Telling which kind of device it is
Subscribe to the heartbeat (lixel/application/report/heartbeat) and look at two fields:
Featurescontains"openapi_license": the firmware supports OpenAPI authorization.OpenapiLicenseStateis thennone,active, orexpired. The field is left out while the device cannot read its own authorization state.- The heartbeat has no
Features, orFeaturesdoes not contain"openapi_license": a device on the earlier key-based scheme.
ProtocolVersion is "3.0.0" on both kinds of device and cannot tell them apart. For the field descriptions, see Interface Catalog · Status monitoring.
Metering
Only a recording started without a key is metered:
- A recording started by a
modelingrequest (AC_START) without a key uses up recording minutes of the authorization. A recording started with a valid key uses none. - Only the time the device spends scanning is counted. Timing starts when the device state becomes scanning (
EC_ScanModeling) and ends when it becomes stopping (EC_ScanStopping). The start phase afterAC_START(starting scan, usually ten to twenty seconds) and the stop phase afterAC_STOP(stopping scan and returning to standby) are not counted. A recording that ends without reaching scanning is not metered. - Each full 60 seconds uses 1 minute, and the part of less than 60 seconds left when the recording ends uses 1 more minute. For example, a recording that stays in scanning for 150 seconds uses 3 minutes.
- When the minutes run out, the device stops that recording through the normal stop procedure, the data already recorded is saved as usual, and the authorization state becomes
expired. From then on a request without a key is answered withopenapi license exhausted, while a request with a valid key still works. - A permanent authorization never runs out.
- Query the remaining recording minutes with
openapi_license; they decrease in real time while recording. See Interface Catalog · Query the OpenAPI authorization.
Requesting an OpenAPI Key
For a device that needs a key, the OpenAPI Key is distributed by XGRIDS and cannot be generated by yourself. To obtain one:
- Request it through the XGRIDS business or technical support channel, stating the device model and intended use.
- XGRIDS checks and issues a key string.
- Fill it into the connection configuration; no extra activation step is needed.
Note: the key is bound to a specific device / authorization. Keep it safe; do not hard-code it into a public repository or share it with third parties.
Using it in code
Set ClientOptions.openapi_key only when a key is needed. When it is set, request() / publish() fill it into the header automatically; when it is not set, nothing is written.
from example.core import ClientOptions, OpenApiClient
# A device that holds an active OpenAPI authorization: no key
with OpenApiClient(ClientOptions(host="192.168.55.1")) as client:
...
# A device on the earlier key-based scheme, or one whose authorization is missing or used up: set the key
opts = ClientOptions(host="192.168.55.1", openapi_key="<provided by XGRIDS>")
with OpenApiClient(opts) as client:
... # header.openapi_key is filled automatically
The C++ client works the same way with ClientOptions::openapi_key; see the C++ Quick Start.
Upgrading from 1.x
Programs written for 1.x need no change: a request with a valid key is handled exactly as in 1.x and is not metered. To go without a key, the device must already hold an OpenAPI authorization; then stop passing a key (remove openapi_key= or --key).
Header fields
The first field of every request/response/report message is usually a Header:
| Field | Type | Description |
|---|---|---|
seq | uint32 | Frame sequence number |
stamp | sint64 | Frame timestamp. Device-reported frames are in microseconds, with the Unix epoch as the time base |
scaler | sint64 | Scale factor (used by point cloud, etc.) |
device_id | string | Device ID (generated by the device) |
session_id | string | Session ID (generated by the request/report side) |
openapi_key | string | API key, optional. Not needed by a device with an active OpenAPI authorization; see OpenAPI authorization and key |
The corresponding proto definition:
message Header {
uint32 seq = 1; // frame sequence number
sint64 stamp = 2; // frame timestamp
sint64 scaler = 3; // scale factor (positive: magnify, negative: shrink, 0: disable scaling)
string device_id = 4; // device ID (generated by the device)
string session_id = 5; // session ID (generated by the request/report side)
optional string openapi_key = 6; // API key, optional (not needed by a device with an active OpenAPI authorization)
}
Appendix: low-level provisioning interface
Note: this section is only for reference when you implement Bluetooth provisioning yourself (without an existing app). In most cases provisioning is done with the bundled tool or app, and you do not need these low-level definitions.
Provisioning reads and writes characteristics over the BLE GATT service. Android and iOS use different UUIDs:
/* Android GATT Characteristic Types */
#define UUID_GATT 0x1801
#define GATT_CHARAC_WIFI_INFO_SET 0x2AB0
#define GATT_CHARAC_WIFI_STATUS_GET 0x2AB1
/* iOS GATT Characteristic Types */
#define IOS_UUID_GATT 0x7F00
#define IOS_GATT_CHARAC_WIFI_INFO_SET 0x7F01
#define IOS_GATT_CHARAC_WIFI_STATUS_GET 0x7F02
The data structures for writing the Wi-Fi config and reading the Wi-Fi status:
#pragma pack(1)
/***********************************************************
* WiFi status information (device -> Android)
* ssid_len : 0 means WiFi is disconnected
* ssid : WiFi access point name
* ip_len : 0 means WiFi has no assigned IP
* ip : WiFi IP address
* auth_mode: Not used yet
* wifi_mode: 0 - STA mode 1 - AP mode (Quick Connect mode) 255 - ignore WiFi mode
**********************************************************/
typedef struct wifi_info_s {
uint8 ssid_len;
uint8 ssid[32];
uint8 passwd_len;
uint8 passwd[64];
uint8 auth_mode;
uint8 wifi_mode; // 0: Normal mode 1: Quick Connect mode 255: Only configure country code
uint8 country_code[2]; // Country code (ISO2)
} wifi_info_t;
typedef struct wifi_status_s {
uint8 ssid_len;
uint8 ssid[32];
uint8 ip_len;
uint8 ip[16];
uint8 connect_state; // 0 - Not connected 1 - Connected successfully 2 - Connecting 3 - Device scanning
uint8 wifi_mode; // 0: Normal mode 1: Quick Connect mode
uint8 country_code[2]; // Country code (ISO2)
} wifi_status_t;
#pragma pack()