Skip to content

Add C implementations of device-connect-edge and -agent-tools#53

Open
atsyplikhin wants to merge 1 commit into
arm:mainfrom
atsyplikhin:device-connect-c
Open

Add C implementations of device-connect-edge and -agent-tools#53
atsyplikhin wants to merge 1 commit into
arm:mainfrom
atsyplikhin:device-connect-c

Conversation

@atsyplikhin

Copy link
Copy Markdown
Collaborator

Summary

Two new packages porting Device Connect to C — the device side and the external-agent side — mirroring the Python device-connect-edge / device-connect-agent-tools. Built in the same spirit as the MHP C SDK wire node, reusing its proven JSON / JSON-RPC / NATS-transport / security modules.

packages/device-connect-edge-c/ (libdc_edge.a)

  • driver (dc/driver.h): register @rpc-style functions by name, advertise events, set identity/status. DC RPC semantics — method is the function name, params are the args, the reply carries the raw return value as result.
  • runtime (dc/runtime.h): connect over NATS (cnats), serve device-connect.{tenant}.{id}.cmd, registerDevice to the registry, heartbeat every device_ttl/3 to hold the lease (device shows online), answer requestRegistration, re-register on reconnect, plus invoke_remote (D2D) and emit (events).
  • credentials: consumes the portal's native *.creds.json directly (auto-converts to nsc-chained for cnats; auto-detects device_id/tenant) or an nsc *.creds.
  • example: temp_sensor.c (get_reading/set_target + a reading_changed event).

packages/device-connect-agent-tools-c/ (libdc_agent_tools.a)

  • the four meta-tools over the portal HTTP API (libcurl): describe_fleet, list_devices, get_device_functions, invoke_device; responses parsed to JSON.
  • example: dc_agent CLI (fleet/list/functions/invoke).

Testing

  • Unit: edge 4/4 (driver capabilities/identity/status, dispatch, JSON-RPC shapes), agent-tools 3/3 (env resolution, portal-response parsing). make test in each package.
  • Live end-to-end against a real DC portal (tenant alpha): 3 C edge devices provisioned → registered → devices_online: 3 sustained by heartbeat → discovered by the C agent-tools (fleet/list/functions) → invoked C→C (set_target{"ok":true}, get_reading{"temp_c":…} across all three, ~170 ms), with -32601/-32602 device errors propagating through the portal envelope.
  • CI (.github/workflows/c-sdk.yml): builds + unit-tests both packages on Linux and macOS (cnats from source on Linux / brew on macOS; libcurl).

Dependencies

  • edge-c: the NATS C client (cnats). agent-tools-c: libcurl. Both C11, ASCII-only, Apache-2.0 with per-file SPDX headers.

Scope / not yet

  • edge transport is NATS (the dc/transport.h vtable leaves room for MQTT/Zenoh); @periodic/@on/D2D presence-collector and a few niceties are not yet wired (portal-mode register+heartbeat+cmd+invoke_remote is complete).
  • agent-tools covers the four core tools; event streaming and the Strands/LangChain/MCP adapters from the Python package are not ported.

🤖 Generated with Claude Code

Two new packages porting the device side and the external-agent side of
Device Connect to C, mirroring the Python packages and built in the same
spirit as the MHP C SDK wire node (reusing its proven JSON / JSON-RPC /
NATS-transport / security modules).

packages/device-connect-edge-c/ (libdc_edge.a):
- driver: register @rpc-style functions by name, advertise events, set
  identity/status. DC RPC semantics -- method is the function name, params
  are the args, the reply carries the raw return value.
- runtime: connect over NATS (cnats), serve device-connect.{tenant}.{id}.cmd,
  registerDevice to the registry, heartbeat every device_ttl/3 to hold the
  lease (device shows online), answer requestRegistration, re-register on
  reconnect, plus invoke_remote (D2D) and emit (events). Consumes the portal's
  native *.creds.json directly (auto-converts for cnats; auto-detects
  device_id/tenant) or an nsc-chained *.creds.
- example: temp_sensor.c (get_reading/set_target + reading_changed).

packages/device-connect-agent-tools-c/ (libdc_agent_tools.a):
- the four meta-tools over the portal HTTP API (libcurl): describe_fleet,
  list_devices, get_device_functions, invoke_device; results parsed to JSON.
- example: dc_agent CLI (fleet/list/functions/invoke).

Each package has a Makefile, unit tests (edge 4, agent-tools 3), and a README.
A c-sdk CI workflow builds + tests both on Linux and macOS (cnats from source
on Linux / brew on macOS; libcurl).

Verified end-to-end against a live DC portal (tenant alpha): 3 C edge devices
provisioned, registered, online (sustained by heartbeat), then discovered and
invoked by the C agent-tools (get_reading/set_target across all three), with
-32601/-32602 error semantics propagating through the portal envelope.

Apache-2.0, per-file SPDX headers (matches the repo).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant