Skip to content

Commit 64db4b6

Browse files
committed
Technical review of Device Connect D2D LP
1 parent 4f63fd9 commit 64db4b6

4 files changed

Lines changed: 26 additions & 28 deletions

File tree

content/learning-paths/embedded-and-microcontrollers/device-connect-d2d/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ cascade:
1010
who_is_this_for: This is an introductory topic for developers wiring up heterogeneous edge fleets, where devices need a shared way to find each other and a shared way to be controlled by agents. Device Connect provides this communication protocol between agents and devices, and standardizes how devices from different vendors advertise themselves and exchange structured messages, so both peer devices and AI agents can discover and invoke them through the same driver model. You'll use it to stand up peer-to-peer communication between two devices, with no broker or cloud service in between.
1111

1212
learning_objectives:
13-
- Understand Device Connect Edge SDK primitives and use them to build a device driver that exposes capabilities like discovery, RPC, events, and status to other peers on the mesh
13+
- Understand Device Connect Edge SDK primitives
1414
- Set up a Python environment for Device Connect with no hardware required
15-
- Build two cooperating drivers, a simulated sensor that exposes an RPC method and emits readings on a schedule, and a threshold monitor that subscribes to those events with `@on` and emits its own alerts in response
16-
- Run both devices as independent runtimes and watch them discover and invoke each other on the same network
15+
- Build two simulated devices
1716
- Use the Device Connect agent tools to discover both devices on the mesh and invoke their RPCs
1817

1918
prerequisites:
@@ -31,6 +30,7 @@ armips:
3130
operatingsystems:
3231
- Linux
3332
- macOS
33+
- Windows
3434
tools_software_languages:
3535
- Python
3636

content/learning-paths/embedded-and-microcontrollers/device-connect-d2d/background.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,4 @@ In D2D mode, every participant is a peer. Each device runtime joins the same pub
5151

5252
No central server sits between the sensor and the monitor. They advertise themselves, find each other by event name, and exchange typed payloads directly.
5353

54-
## What you'll learn
55-
56-
By the end of this Learning Path you will:
57-
58-
- set up a Python project with uv, the Device Connect runtime, and the agent tools
59-
- write two cooperating drivers: a simulated sensor and a threshold monitor that reacts to it
60-
- run both as independent device runtimes on one machine
61-
- use the Device Connect agent tools to discover both peers and invoke their RPCs
62-
63-
The next section covers the developer model.
54+
Move on to the next section to have a look at the developer model.

content/learning-paths/embedded-and-microcontrollers/device-connect-d2d/d2d-setup.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ This mirrors a real edge scenario, a room supervisor watching environmental sens
1717

1818
This walkthrough uses [uv](https://docs.astral.sh/uv/) to manage the project and its Python dependencies. uv will resolve a compatible Python interpreter, create a virtual environment, and install packages for you, so no manual `venv` or `pip` steps are needed.
1919

20-
If you do not already have uv installed, run the official installer for your platform:
21-
20+
{{< tabpane code=true >}}
21+
{{< tab header="macOS or Linux" language="shell">}}
2222
```bash
23-
# macOS or Linux
2423
curl -LsSf https://astral.sh/uv/install.sh | sh
2524
```
26-
25+
{{< /tab >}}
26+
{{< tab header="Windows" language="powershell">}}
2727
```powershell
28-
# Windows PowerShell
2928
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
3029
```
30+
{{< /tab >}}
31+
{{< /tabpane >}}
3132

3233
Alternative install methods (Homebrew, pipx, and others) are listed in the [uv installation docs](https://docs.astral.sh/uv/getting-started/installation/). Verify the install with:
3334

@@ -244,7 +245,15 @@ print("recent alerts:", invoke_device(monitor_id, "get_recent_alerts"))
244245
PY
245246
```
246247

247-
The script discovers both devices, invokes `get_reading` on the sensor, and invokes `get_recent_alerts` on the monitor. The alert list should contain every breach the monitor has observed since it started.
248+
The script discovers both devices, invokes `get_reading` on the sensor, and invokes `get_recent_alerts` on the monitor. The alert list should contain every breach the monitor has observed since it started:
249+
250+
```
251+
Found 2 device(s)
252+
monitor-001 (threshold_monitor)
253+
sensor-001 (simulated_sensor)
254+
latest reading: {'success': True, 'result': {'temperature': 27.5, 'humidity': 53.5}}
255+
recent alerts: {'success': True, 'result': [{'device_id': 'sensor-001', 'temperature': 27.9}, {'device_id': 'sensor-001', 'temperature': 28.7}, {'device_id': 'sensor-001', 'temperature': 28.2}, {'device_id': 'sensor-001', 'temperature': 28.1}, {'device_id': 'sensor-001', 'temperature': 29.2}, {'device_id': 'sensor-001', 'temperature': 28.6}, {'device_id': 'sensor-001', 'temperature': 27.7}, {'device_id': 'sensor-001', 'temperature': 28.9}, {'device_id': 'sensor-001', 'temperature': 29.0}, {'device_id': 'sensor-001', 'temperature': 27.5}]}
256+
```
248257

249258
## What happened
250259

content/learning-paths/embedded-and-microcontrollers/device-connect-d2d/overview.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
---
2-
title: The developer model
2+
title: Device Connect developer model
33
weight: 3
44

55
# FIXED, DO NOT MODIFY
66
layout: learningpathall
77
---
88

9-
## Device Connect developer model
10-
11-
### Device Connect Edge SDK
9+
## Device Connect Edge SDK
1210

1311
The [`device-connect-edge`](https://pypi.org/project/device-connect-edge/) package is the Python SDK you install on every device that joins a Device Connect network. It provides the building blocks for creating a device runtime: the `DeviceDriver` base class you subclass to describe a device, the decorators used to expose its capabilities to peers and agents, and the `DeviceRuntime` that brings a driver online on the network.
1412

1513
You describe a device by subclassing `DeviceDriver` from `device_connect_edge.drivers`, then annotating methods and properties with primitives. The runtime wires them into discovery, pub/sub, and RPC for you.
1614

1715
In this Learning Path you'll use these primitives to write two cooperating drivers: a **sensor** runtime that publishes temperature and humidity readings on a schedule, and a **threshold monitor** runtime that reacts to those readings and raises alerts when a threshold is crossed. The subsections below walk through the identity, decorators, and runtime you'll use to build them, and the agent tools package you'll use to invoke them from a separate client.
1816

19-
#### Identity and status
17+
### Identity and status
2018

2119
Every driver declares who it is and how it is doing. These are properties, not decorators:
2220

2321
- `identity` returns a `DeviceIdentity` (device type, manufacturer, model, description). This is what peers see during discovery.
2422
- `status` returns a `DeviceStatus` (availability, location, optional health fields). This is the live signal other peers use to decide if the device is reachable and usable.
2523

26-
#### Behavior decorators
24+
### Behavior decorators
2725

2826
- `@rpc()`: exposes a method as a remote procedure. Other peers or agents call it by device ID and method name; the return value is serialized back to the caller.
2927
- `@emit()`: declares that the method is an event publisher. Calling it inside the driver emits the event to any peer subscribed to it.
3028
- `@periodic(interval=<seconds>)`: runs the method on a fixed schedule once the runtime starts. Useful for sampling, heartbeats, or housekeeping.
3129
- `@on(event_name=<name>, device_type=<type>)`: subscribes the method to events emitted by other devices. The runtime delivers matching events as method calls with the source device id, event name, and a payload dict.
3230

33-
#### Runtime
31+
### Runtime
3432

3533
`DeviceRuntime(driver=..., device_id=..., allow_insecure=...)` wraps your driver in a process that joins the pub/sub transport, advertises identity and status, and dispatches incoming RPCs and events to the decorated methods. You call `await runtime.run()` to keep it alive.
3634

37-
### Device Connect Agent tools
35+
## Device Connect Agent tools
3836

3937
The [`device-connect-agent-tools`](https://pypi.org/project/device-connect-agent-tools/) package is the companion SDK for the client side of a Device Connect network: anything that wants to interact with devices on the mesh, from a short script or REPL to a full AI agent. It exposes a small set of functions that mirror the core capabilities of the protocol:
4038

@@ -46,7 +44,7 @@ Any Python process that imports this package can find and drive devices without
4644

4745
## What you'll build
4846

49-
In this Learning Path you will build two cooperating simulated devices on the same local network:
47+
In the next section you will create two cooperating simulated devices on the same local network:
5048

5149
- a **sensor** driver that publishes temperature and humidity readings on a schedule using `@rpc`, `@emit`, and `@periodic`
5250
- a **threshold monitor** driver that uses `@on` to subscribe to the sensor's readings, emits its own `alert_raised` event when a reading crosses a threshold, and exposes the alert history through an `@rpc` method

0 commit comments

Comments
 (0)