You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This folder contains the **network API layer** that exposes Rio hardware control and telemetry over HTTP/REST and WebSockets. It is designed to run alongside the existing Flask UI (`../rio-webapp/`) and provides a machine-readable interface for Jupyter notebooks, scripts, and external applications.
4
4
5
-
**⚠️ Important:** The API currently uses **plain FastAPI**(standard REST endpoints). It is **NOT Web of Things (WoT) compatible**.
5
+
**✅ Web of Things (WoT) Compatible:** The API uses **LabThings FastAPI**to expose controllers as WoT-compliant Things.
6
6
7
-
-`labthings-fastapi` is installed as a dependency but **not used** in the code
8
-
- The API uses standard FastAPI routes (`@app.get`, `@app.post`, etc.)
9
-
- No LabThings "Things", "Properties", "Actions", or "Events" are exposed
10
-
- WoT compatibility is planned as a future enhancement (see "Future enhancements" section)
7
+
- Controllers are wrapped as LabThings Things (FlowThing, HeaterThing, CameraThing, etc.)
8
+
- Auto-generated Thing Descriptions (TD) for each Thing
@@ -53,6 +63,11 @@ This folder contains the **network API layer** that exposes Rio hardware control
53
63
export RIO_SIMULATION=false
54
64
python3 -m api.main
55
65
```
66
+
Optional pump enable (USB serial):
67
+
```bash
68
+
export RIO_PUMP_ENABLED=true
69
+
# export RIO_PUMP_PORT=/dev/ttyUSB0
70
+
```
56
71
57
72
3.**Test from Pi:**
58
73
```bash
@@ -75,12 +90,11 @@ This folder contains the **network API layer** that exposes Rio hardware control
75
90
76
91
**For detailed Pi installation and Jupyter access guide, see:**`../../docs/api_pi_testing_guide.md`
77
92
78
-
Note: the API client library and notebooks are not included in the deployment bundle.
79
-
See the source repo at `software/api/client/README.md` for the client and examples.
93
+
See `client/README.md` for the Python client library and example notebooks.
80
94
81
95
## What belongs here / what does not
82
96
83
-
-**Belongs here**: FastAPI routes, WebSocket handlers, request/response schemas (Pydantic models), API configuration, and streaming aggregators.
97
+
-**Belongs here**: LabThings Thing classes, ThingServer setup, WebSocket handlers, request/response schemas (Pydantic models), API configuration, and streaming aggregators.
84
98
-**Does not belong here**: Hardware drivers (belongs in `../drivers/`), device controllers (belongs in `../controllers/`), Flask routes (belongs in `../rio-webapp/`), and browser JavaScript (belongs in `../rio-webapp/static/`).
85
99
86
100
## Architecture and integration
@@ -93,10 +107,12 @@ The API layer sits **above** the device controllers (`../controllers/`) and **be
93
107
└──────────────┬──────────────────────┘
94
108
│ HTTP/REST + WebSocket
95
109
┌──────────────▼──────────────────────┐
96
-
│ software/api/ (this folder) │
97
-
│ - FastAPI routes │
110
+
│ software/api/ (this folder) │
111
+
│ - LabThings ThingServer (WoT) │
112
+
│ - Thing classes (FlowThing, etc.) │
98
113
│ - WebSocket aggregator │
99
114
│ - Request/response schemas │
115
+
│ - Legacy /api/control/* routes │
100
116
└──────────────┬──────────────────────┘
101
117
│ Controller methods
102
118
┌──────────────▼──────────────────────┐
@@ -114,28 +130,47 @@ The API **does not** call drivers directly; it calls into the controller layer,
114
130
115
131
## Key components
116
132
117
-
### `main.py` — FastAPI application and routes
133
+
### `main.py` — LabThings ThingServer and routes
118
134
119
-
-**Entry point**: `create_app()` returns a FastAPI instance with all routes registered.
135
+
-**Entry point**: `create_app()` returns a FastAPI instance with LabThings ThingServer integration.
120
136
-**Controller initialization**: Controllers are instantiated at import time (similar to `software/main.py`) so capabilities reflect actual hardware availability.
121
-
-**REST endpoints**:
137
+
-**WoT Things** (auto-generated routes by LabThings):
138
+
-`/flow/` — FlowThing (flow/pressure control)
139
+
-`/heater/` — HeaterThing (heater control)
140
+
-`/camera/` — CameraThing (camera and strobe control)
141
+
-`/droplet/` — DropletThing (droplet detection)
142
+
-`/pump/` — PumpThing (placeholder for future pump support)
- Flow, pressure, and heater controllers will use simulated hardware
416
+
- Camera will use simulated frames (synthetic droplets)
417
+
- All API endpoints are available and functional
418
+
419
+
**Note**: Keep the API server running in the terminal while using the notebook. If you stop the server, restart it and the notebook will reconnect automatically.
420
+
421
+
**Troubleshooting**:
422
+
- **Connection refused**: Make sure the API server is running (`python -m api.main`)
423
+
- **Module not found**: Make sure `software/` is in your Python path (see step 4)
- `pydantic>=2.10.0`— Data validation (Pydantic 2.x, required by LabThings)
456
+
- `pyyaml>=6.0`— Config file loading
343
457
344
-
**Current status:** The API uses standard FastAPI routes and does not expose LabThings "Things", "Properties", "Actions", or "Events". The `labthings-fastapi` package is included for future migration to WoT-compliant endpoints.
458
+
**Current status:** The API uses LabThings ThingServer to expose controllers as WoT-compliant Things. Each controller is wrapped in a Thing class that exposes properties and actions according to the Web of Things standard.
0 commit comments