Search the docs
Menu
Updated Edit on GitHub

How CDAP works

Copy as Markdown

CDAP stands for Connected Device Access Protocol. It is NeoDesk's protocol for devices that can't run NeoDesk Desktop: sensors, controllers, cameras, network devices, SCADA systems and agents. Such a device connects to the server, and CDAP gives the console access to it: its values, its controls, and for some devices a terminal, its screen, a video stream or its files.

This page explains the parts and how they work together. The messages themselves are on CDAP protocol, the ready-made clients on CDAP SDKs and bridges, and running the gateway and using the devices in the console on CDAP devices.

What it is for

A computer with NeoDesk Desktop connects over the RustDesk protocol, and you control it like a desktop. A temperature sensor has no desktop, and a PLC only speaks Modbus. CDAP covers those devices without the console knowing anything about them in advance: the device describes itself, and the console builds its page from that description. Adding a new kind of device means writing a small program for the device, not changing the server.

The parts

sensor ---- Modbus --> Modbus bridge ---+
switch ---- SNMP ----> SNMP bridge -----+
agent on a server ----------------------+
camera with the SDK --------------------+
                                        |
                 WebSocket, port 21122  |
                                        v
                                   CDAP gateway
                                        |
                                        v
                                console, API, CLI
  • Device: a program that speaks CDAP itself, usually written with the Python or Node.js SDK. It runs on the device or next to it.
  • Bridge: a program that speaks CDAP to the server and another protocol to the hardware, such as Modbus, SNMP or HTTP. To the server a bridge is a device like any other. The repository has three reference bridges.
  • Gateway: the part of the NeoDesk server that devices connect to. It listens on port 21122 at the path /cdap, separately from the console.
  • Console, API and CLI: show the devices and send them commands. The console has the IoT devices page and a page per device, the API has the routes under /api/cdap, and the CLI has neodesk cdap.

A connection from start to end

  1. The device opens a WebSocket to ws://<server>:21122/cdap, or wss:// when the gateway has TLS on.
  2. It signs in with an API key, a console account or a device token. An API key or account lets the device join the server under the ID it gives, so its role needs Approve join requests.
  3. It registers by sending its manifest: its name and type, what it can do (its capabilities), its values and controls (widgets) and its alerts.
  4. The server adds it to the device list and shows it on the IoT devices page.
  5. While it is connected, the device sends a heartbeat every 15 seconds by default, with its current values, and sends a value on its own when it changes. The server checks the device's alerts each time a value changes.
  6. When the device closes the connection, or sends no heartbeat for three intervals and at least 60 seconds, the server marks it offline and drops its manifest and open alerts. The device signs in and registers again when it comes back.

The manifest

The manifest doesn't say how the page should look. It lists widgets, and the console draws each type in its own way:

Widget Is
gauge, text, led, chart, table Values the device reports
toggle, slider, select, button Controls a user can change or press
terminal, desktop, video_stream, file_browser, audio Sessions with the device

A greenhouse controller, for example, sends a gauge for the temperature and a toggle for the heater. Each widget can also say which role may read it, change it or run it; see Widget permissions. Alerts are conditions on widget values, such as temp < 2, which show on the device's page while they hold.

Commands

When a user flips the heater toggle on the device's page:

  1. The server checks that the account has Send commands to CDAP devices and that its role may control the widget.
  2. The gateway sends the device a command with the widget ID, the action set and the new value.
  3. The device switches the heater and answers with a command_response that says whether it worked.
  4. The device sends the heater's new value. The console shows a control's state from the device's values, not from the command, so the page only changes once the device confirms.

Every command and its answer go to the audit log. Commands can also come from the API and the CLI.

Sessions

Terminal, file, desktop, video and audio sessions run over the same WebSocket as everything else, so a device needs no second port or connection for them.

  1. The browser opens a socket to the console, such as /api/cdap/devices/<id>/terminal.
  2. The console checks the account's permission for that kind of session (Terminal on CDAP devices for the terminal and the screen, Files on CDAP devices for files) and that the account may see the device.
  3. The gateway sends the device a start message, such as terminal_start, with a new session ID. It only does that when the manifest has the capability for the session.
  4. From then on the gateway passes the messages of the session both ways, each tagged with its session ID.

When the console runs on several instances, a device's WebSocket is held by one of them. A request that reaches another instance is passed to the one that holds the device.

Security

  • Encryption: the gateway takes plain connections unless CDAP_TLS=Y adds TLS with the server's certificate. CDAP_TLS_REQUIRED=Y refuses plain connections. See The gateway.
  • Sign-in: a device has to sign in within 30 seconds. A device token works only for the one device it is bound to. Connections and sign-ins per address are limited by CDAP_RATE_LIMIT.
  • IDs: an ID that another account or API key registered is refused, and so is a banned device. A second connection with the same ID replaces the first.
  • Permissions in the console: View CDAP devices to see the devices, Send commands to CDAP devices for controls, Terminal on CDAP devices and Files on CDAP devices for sessions. See What each role can do.
  • Desktop consent: for an OS agent (type os_agent, or tagged support-agent), the desktop start carries a grant signed by the server, which the agent checks before it asks the person at the device for consent.

Type to search pages, sections, commands and settings.