Skip to content

Commit 460996b

Browse files
lucaamph1p
authored andcommitted
docs: Update API docs
1 parent e89ef53 commit 460996b

File tree

1 file changed

+232
-49
lines changed

1 file changed

+232
-49
lines changed

README.md

Lines changed: 232 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ Connect them like this and remember to set them in `include/constants.h` accordi
153153
### Alternate Button Wiring
154154
155155
Thanks to [RBEGamer](https://github.com/RBEGamer) who is showing in this [issue](https://github.com/ph1p/ikea-led-obegraensad/issues/79) how to use the original button wiring. With this solution you won't need the "BUTTON one end" and "BUTTON other end" soldering from the table above.
156-
157156
# HTTP API Endpoints
158157
159158
## Get Information
@@ -164,15 +163,55 @@ Get current values and the (fixed) metadata, like number of rows and columns and
164163
GET http://your-server/api/info
165164
```
166165

166+
### Example `curl` Command:
167+
168+
```bash
169+
curl http://your-server/api/info
170+
```
171+
172+
### Response
173+
174+
```json
175+
{
176+
"rows": 16,
177+
"cols": 16,
178+
"status": "active",
179+
"plugin": 3,
180+
"rotation": 90,
181+
"brightness": 255,
182+
"scheduleActive": true,
183+
"schedule": [
184+
{
185+
"pluginId": 2,
186+
"duration": 60
187+
},
188+
{
189+
"pluginId": 4,
190+
"duration": 120
191+
}
192+
],
193+
"plugins": [
194+
{"id": 1, "name": "Plugin One"},
195+
{"id": 2, "name": "Plugin Two"},
196+
{"id": 3, "name": "Plugin Three"}
197+
]
198+
}
199+
```
200+
201+
---
202+
167203
## Set Active Plugin by ID
168204

169205
To set an active plugin by ID, make an HTTP PATCH request to the following endpoint, passing the parameter as a query string:
170206

171207
```
172208
PATCH http://your-server/api/plugin
173209
```
174-
```
175-
e.g. curl -X PATCH "http://your-server/api/plugin?id=7"
210+
211+
#### Example `curl` Command:
212+
213+
```bash
214+
curl -X PATCH "http://your-server/api/plugin?id=7"
176215
```
177216

178217
### Parameters
@@ -181,127 +220,271 @@ e.g. curl -X PATCH "http://your-server/api/plugin?id=7"
181220

182221
### Response
183222

184-
- Success: `200 OK` with the message "Plugin Set".
185-
- Not Found: `404 Not Found` with the message "Plugin not found".
223+
- **Success:**
224+
225+
```json
226+
{
227+
"status": "success",
228+
"message": "Plugin set successfully"
229+
}
230+
```
231+
232+
- **Error (Plugin not found):**
233+
234+
```json
235+
{
236+
"error": true,
237+
"errormessage": "Could not set plugin to id 7"
238+
}
239+
```
240+
241+
---
186242

187243
## Set Brightness
188244

189-
To set the brightness of the LED display, make an HTTP GET request to the following endpoint, passing the parameter as a query string:
245+
To set the brightness of the LED display, make an HTTP PATCH request to the following endpoint, passing the parameter as a query string:
190246

191247
```
192248
PATCH http://your-server/api/brightness
193249
```
250+
251+
#### Example `curl` Command:
252+
253+
```bash
254+
curl -X PATCH "http://your-server/api/brightness?value=100"
194255
```
195-
e.g. curl -X PATCH "http://your-server/api/brightness?value=100"
196-
```
256+
197257
### Parameters
198258

199259
- `value` (required): The brightness value (0..255).
200260

201261
### Response
202262

203-
- Success: `200 OK` with the message "Ok".
204-
- Invalid Value: `404 Not Found` with the message "Invalid Brightness Value".
263+
- **Success:**
264+
265+
```json
266+
{
267+
"status": "success",
268+
"message": "Brightness set successfully"
269+
}
270+
```
271+
272+
- **Error (Invalid Brightness Value):**
205273

206-
## Get current display data
274+
```json
275+
{
276+
"error": true,
277+
"errormessage": "Invalid brightness value: 300 - must be between 0 and 255."
278+
}
279+
```
280+
281+
---
207282

208-
To get the current displayed data as an byte-array, each byte representing the brightness value.
209-
Be aware that the global brightness value gets applied AFTER these values, so if you set the global brightness to 16, you will still get values of 255 this way.
283+
## Get Current Display Data
284+
285+
To get the current displayed data as a byte-array, each byte representing the brightness value. Be aware that the global brightness value gets applied AFTER these values.
210286

211287
```
212288
GET http://your-server/api/data
213289
```
214290

291+
#### Example `curl` Command:
292+
293+
```bash
294+
curl http://your-server/api/data
295+
```
296+
297+
### Response (Raw Byte-Array Example)
298+
299+
```json
300+
[255, 255, 255, 0, 128, 255, 255, 0, ...]
301+
```
302+
303+
---
304+
215305
# Plugin Scheduler
216306

217-
It is possible to switch between plugins automatically.
307+
It is possible to switch between plugins automatically.
218308
You can define your schedule in the Web UI or just send an API call.
219309

310+
### Set Schedule
311+
312+
To define a schedule for switching between plugins automatically, make a POST request with your schedule data:
313+
220314
```bash
221-
### set your plugins and duration in seconds
222-
curl -X POST http://x.x.x.x/api/schedule -d 'schedule=[{"pluginId":10,"duration":2},{"pluginId":8,"duration": 5}'
315+
curl -X POST http://your-server/api/schedule -d 'schedule=[{"pluginId":10,"duration":2},{"pluginId":8,"duration":5}]'
316+
```
223317

224-
### clear the schedule
225-
curl http://x.x.x.x/api/schedule/clear
318+
#### Example Response
319+
320+
```json
321+
{
322+
"status": "success",
323+
"message": "Schedule updated"
324+
}
325+
```
226326

227-
### start the schedule
228-
curl http://x.x.x.x/api/schedule/start
327+
### Clear Schedule
229328

230-
### stop the schedule
231-
curl http://x.x.x.x/api/schedule/stop
329+
To clear the existing schedule, make a GET request:
330+
331+
```bash
332+
curl http://your-server/api/schedule/clear
232333
```
233334

234-
# DDP (Distributed Display Protocol)
335+
#### Example Response
336+
337+
```json
338+
{
339+
"status": "success",
340+
"message": "Schedule cleared"
341+
}
342+
```
343+
344+
### Start Schedule
345+
346+
To start the current schedule, make a GET request:
235347

236-
You can set the panel to DDP using the button or via the web interface.
237-
This Protocol uses **UDP** and listens on Port **4048**.
348+
```bash
349+
curl http://your-server/api/schedule/start
350+
```
238351

239-
**Info**: The DDP Header is 10 Bytes!
352+
#### Example Response
240353

241-
In the repository you will find an `ddp.py` as an example.
354+
```json
355+
{
356+
"status": "success",
357+
"message": "Schedule started"
358+
}
359+
```
242360

243-
Change the plugin to `DDP` and run following command with your IP:
361+
### Stop Schedule
362+
363+
To stop the current schedule, make a GET request:
244364

245365
```bash
246-
./ddp.py --ip x.x.x.x --pixel 2 2 200 --pixel 0 0 255
366+
curl http://your-server/api/schedule/stop
247367
```
248368

249-
### Helpful Links
369+
#### Example Response
250370

251-
- https://kno.wled.ge/interfaces/ddp/
252-
- http://www.3waylabs.com/ddp/
371+
```json
372+
{
373+
"status": "success",
374+
"message": "Schedule stopped"
375+
}
376+
```
253377

254378
---
255379

256-
# Messages HTTP API
380+
## Get Display Data
257381

258-
The LED Display service provides HTTP API to display messages and graphs on a 16x16 LED display. This functionality can be accessed through HTTP calls to the service endpoint.
382+
To retrieve the current display data as a byte-array, each byte representing the brightness value. The global brightness is applied after these values.
383+
384+
```
385+
GET http://your-server/api/data
386+
```
387+
388+
#### Example `curl` Command:
389+
390+
```bash
391+
curl http://your-server/api/data
392+
```
393+
394+
### Response (Raw Byte-Array Example)
395+
396+
```json
397+
[255, 255, 255, 0, 128, 255, 255, 0, ...]
398+
```
399+
400+
---
259401

260402
## Message Display
261403

262404
To display a message on the LED display, users can make an HTTP GET request to the following endpoint:
263405

264406
```
265-
http://your-server/api/message
407+
GET http://your-server/api/message
266408
```
267409

268410
### Parameters
269411

270412
- `text` (optional): The text message to be displayed on the LED display.
271-
- `graph` (optional): A comma-separated list of integers representing a graph. The values should be in the range of 0 to 15 and will be visualized as a graph on the LED display.
272-
- `miny` (optional): scaling for lower end of the graph, defaults to 0
273-
- `maxy` (optional): scaling for upper end of the graph, defaults to 15
274-
- `repeat` (optional): The number of times the message should be repeated. If not provided, the default is 1. Set this value to -1 to repeat infinitely. While messages ar pending for display an indicator led in the upper left corner will flash.
275-
- `id` (optional): A unique identifier for the message. This can be used for later removal or modification of the message.
276-
- `delay` (optional): The number of ms of delay between every scroll move. Default is 50 ms.
413+
- `graph` (optional): A comma-separated list of integers representing a graph (0-15).
414+
- `miny` (optional): Scaling for the lower end of the graph, defaults to 0.
415+
- `maxy` (optional): Scaling for the upper end of the graph, defaults to 15.
416+
- `repeat` (optional): Number of times the message should be repeated. Default is 1. Set to `-1` for infinite.
417+
- `id` (optional): A unique identifier for the message.
418+
- `delay` (optional): Delay in ms between every scroll movement. Default is 50ms.
277419

278-
#### Example
420+
#### Example `curl` Command:
279421

422+
```bash
423+
curl "http://your-server/api/message?text=Hello&graph=8,5,2,1,0,0,1,4,7,10,13,14,15,15,14,11&repeat=3&id=1&delay=60"
280424
```
281-
GET http://your-server/api/message?text=Hello&graph=8,5,2,1,0,0,1,4,7,10,13,14,15,15,14,11&repeat=3&id=1&delay=60
425+
426+
### Response
427+
428+
```json
429+
{
430+
"status": "success",
431+
"message": "Message received"
432+
}
282433
```
283434

284-
This example will display the message "Hello" on the LED display with a corresponding graph, repeat it three times, and assign it the identifier 1, waits 60ms while scrolling.
435+
---
285436

286-
### Message Removal
437+
## Message Removal
287438

288439
To remove a message from the display, users can make an HTTP GET request to the following endpoint:
289440

290441
```
291-
http://your-server/api/removemessage
442+
GET http://your-server/api/removemessage
292443
```
293444

294445
### Parameters
295446

296447
- `id` (required): The unique identifier of the message to be removed.
297448

298-
#### Example
449+
#### Example `curl` Command:
450+
451+
```bash
452+
curl "http://your-server/api/removemessage?id=1"
453+
```
454+
455+
### Response
456+
457+
```json
458+
{
459+
"status": "success",
460+
"message": "Message removed"
461+
}
462+
```
463+
464+
---
465+
466+
## Clear Storage
467+
468+
To clear the data storage:
299469

300470
```
301-
GET http://your-server/api/removemessage?id=1
471+
GET http://your-server/api/clearstorage
302472
```
303473

304-
This example will remove the message with the identifier 1 from the LED display.
474+
#### Example `curl` Command:
475+
476+
```bash
477+
curl http://your-server/api/clearstorage
478+
```
479+
480+
### Response
481+
482+
```json
483+
{
484+
"status": "success",
485+
"message": "Storage cleared"
486+
}
487+
```
305488

306489
# Development
307490

0 commit comments

Comments
 (0)