Edge Client
In IoT Open Lynx rules and other logic are executed in edge clients. Edge clients are runtime environments connected to the backend but run separately from the backend.
The edge client is always serving one installation and has an updated list of functions and devices. When a function or device changes this is signaled to the edge client and the list is automatically updated. The Edge Apps running are also notified.
What is an edge client?
Technically, the edge client is the collection of software that runs in the edge: a local MQTT broker and the edge daemon (edged). When this software runs on some hardware, for example a Raspberry Pi or a gateway, the whole unit is usually also called an edge client.
An edge client can:
- Authenticate itself to the backend
- Run a local MQTT broker bridged to the backend MQTT broker
- Download and run Edge Apps and their configuration
The edge client runs in a Linux environment. If there is enough CPU, memory and storage it is also possible to run other software on it, for example Node-RED for local logic.
Ways to run an edge client
| Variant | Description |
|---|---|
| Docker | The easiest way to get started. Runs on any Docker host (amd64 and arm64). |
| Linux | A native installation on Debian. |
| Raspberry Pi | The IoT Open Raspberry Pi image. |
| Gateways | Some gateways, for example Inteno/Genexis, come with an edge client. |
Credentials
The edge client authenticates to the backend with credentials generated on the installation in Lynx:
- Open the installation and click
Settings. - Open the
Edge Clienttab and clickCreate new credentials. - Copy the complete file using the copy symbol at the top.
There can only be one set of credentials per installation. Creating new credentials invalidates the old ones, so any running edge client has to be updated with the new file.
The file is saved as /etc/iot-open/iotopen.json on the edge client and looks like this:
{
"client_id": 9,
"installation_id": 9,
"api": "https://lynx.iotopen.se",
"mqtt_broker": "lynx.iotopen.se:8883",
"mqtt_username": "box:9",
"mqtt_password": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"mqtt_client_id": "edge-9",
"timezone": "Europe/Stockholm"
}
| Key | Description |
|---|---|
client_id | Client ID of the installation |
installation_id | ID of the installation |
api | URL to the Lynx API |
mqtt_broker | Host and port of the backend MQTT broker |
mqtt_username | box:<client_id> |
mqtt_password | The generated password |
mqtt_client_id | MQTT client ID, must be unique |
timezone | Time zone of the edge client |
The registration is done with iotopen-verify. It verifies the credentials and creates the configuration for the local MQTT bridge.
MQTT
The edge client runs a local MQTT broker that is bridged to the backend. Only topics starting with obj/, set/, cmd/ and evt/ are sent between the edge client and the backend.
On the local broker the topics are not prefixed with the client ID, they start directly with for example obj/test/.... The client ID is added automatically when a message is sent to the backend and removed when a message is received from the backend. An Edge App therefore doesn't have to care about which installation it runs on.
| Local topic | Topic in the backend |
|---|---|
obj/test/hello | <client_id>/obj/test/hello |
set/obj/zwave/1/switch | <client_id>/set/obj/zwave/1/switch |
The only exception is the status topic <client_id>/box/event/status, which has the client ID on both sides.
Status
The status of the MQTT bridge is published on <client_id>/box/event/status. The value 1 means that the bridge is connected and 0 that it is not. This status is shown as the green "Edge Client" box on the overview page of the installation and on the "Edge App instances" tab.
The status can also be checked with mosquitto_sub, either on the edge client:
mosquitto_sub -t '#' -v
or against the backend, using an API key:
mosquitto_sub -h lynx.iotopen.se -p 8883 -u token -P '<API key>' -t '<client_id>/#' -v
If the status is 0, check that mosquitto is running on the edge client and that it uses the latest credentials. If the bridge is down edged still syncs the apps, but no MQTT traffic flows to or from the backend.
Upgrading
The edge client is more or less stateless. When it starts it automatically downloads its apps and configuration and starts executing them. The only file that needs to be kept is /etc/iot-open/iotopen.json, and even if that is lost a new one can easily be generated from the installation.
Please observe that Edge Apps might store state of their own, even though stateless apps are best practice.
Schedules
Schedules with the executor edge_client are executed by the edge client. Currently this is only supported on some gateways, for example Inteno/Genexis. The Docker and Linux edge clients do not execute schedules. Use the executor server for those.