mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
- The General/ level is gone: its 109 files moved up into the folders of the same name, and its topic table is the "Shared topics" section of Features.md. - Accessibility is one folder, docs/Features/Accessibility/, with the Admin Panel's accessibility page in it. - Every folder's main page is README.md (110 X/X.md pages renamed with git mv, five merged with an existing README.md, 26 index pages added for folders that had none), so a folder opened on GitHub shows its page. - The 73 "# Moved" forwarding pages are deleted, with the folders that held only them; every link that went to one goes to its final page. - docs/Features/README.md has the website's "Features in WeKan" overview, each feature linking to its page here. 1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose, snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when General/ or a "# Moved" page comes back, a folder has no README.md, or a relative link in the docs or README.md does not resolve. Thanks to xet7 !
76 lines
3.2 KiB
Markdown
76 lines
3.2 KiB
Markdown
# RFID tags with WeKan's REST API
|
|
|
|
[#1126](https://github.com/wekan/wekan/issues/1126). WeKan has no RFID support
|
|
of its own, and needs none. A reader next to a door, a workbench or a shelf,
|
|
and a short script, can use the [REST API](REST-API.md) to move a card when a
|
|
tagged thing is scanned. Examples: a tool going out moves its card to *In
|
|
use*, a parcel arriving moves to *Received*, a person checking in adds a
|
|
comment.
|
|
|
|
## What you need
|
|
|
|
- WeKan with the REST API on (`WITH_API=true`) and a WeKan user for the
|
|
reader, member of the board with write access. That user's rights are all
|
|
the script has.
|
|
- An RFID reader. Most USB readers type the tag's number like a keyboard and
|
|
press Enter, so a script reads it from standard input. Serial readers (e.g.
|
|
RC522 or PN532 on a Raspberry Pi) are read with their own library; only
|
|
the line `tag = ...` below changes.
|
|
- On the board, a [custom field](../Features/Cards/CustomFields) called
|
|
*RFID*, holding each card's tag number.
|
|
|
|
## Find a card by its tag, move it
|
|
|
|
`GET /api/boards/{board}/cardsByCustomField/{field}/{value}` finds the cards
|
|
whose *RFID* field holds the tag, and `PUT
|
|
/api/boards/{board}/lists/{list}/cards/{card}` with `{ "listId": ... }` moves
|
|
one to another list of the board.
|
|
|
|
```python
|
|
#!/usr/bin/env python3
|
|
# Moves the card whose RFID custom field holds the scanned tag to TARGET_LIST.
|
|
import json, sys, urllib.request
|
|
|
|
WEKAN = "https://wekan.example.com"
|
|
USER, PASSWORD = "rfid-reader", "a long password"
|
|
BOARD, RFID_FIELD, TARGET_LIST = "<board id>", "<RFID custom field id>", "<list id>"
|
|
|
|
def call(method, path, body=None, token=None):
|
|
req = urllib.request.Request(WEKAN + path, method=method,
|
|
data=None if body is None else json.dumps(body).encode(),
|
|
headers={"Content-Type": "application/json",
|
|
**({"Authorization": "Bearer " + token} if token else {})})
|
|
with urllib.request.urlopen(req) as res:
|
|
return json.load(res)
|
|
|
|
token = call("POST", "/users/login", {"username": USER, "password": PASSWORD})["token"]
|
|
for line in sys.stdin: # a USB reader types the tag + Enter
|
|
tag = line.strip()
|
|
if not tag:
|
|
continue
|
|
cards = call("GET", f"/api/boards/{BOARD}/cardsByCustomField/{RFID_FIELD}/{tag}", token=token)
|
|
for card in cards:
|
|
call("PUT", f"/api/boards/{BOARD}/lists/{card['listId']}/cards/{card['_id']}",
|
|
{"listId": TARGET_LIST}, token=token)
|
|
print(f"{tag}: moved {card['title']}")
|
|
if not cards:
|
|
print(f"{tag}: no card has this tag")
|
|
```
|
|
|
|
The ids are in the board's URL and in `GET /api/boards/{board}/lists` and
|
|
`GET /api/boards/{board}/custom-fields`.
|
|
|
|
## Other actions
|
|
|
|
- Add a comment instead: `POST /api/boards/{board}/cards/{card}/comments`
|
|
with `{ "comment": "Checked in at the workshop" }`.
|
|
- Create a card for an unknown tag: `POST
|
|
/api/boards/{board}/lists/{list}/cards` with `{ "title": tag, "swimlaneId":
|
|
... }`, then set its *RFID* field.
|
|
- Let a [Rule](../Features/Rules/Rules/README.md) do the rest: "when a card
|
|
is moved to *In use*, set the due date to 7 days later".
|
|
|
|
Keep the reader's WeKan password out of the script in shared places, for
|
|
example in an environment variable, and give that user only the boards it
|
|
needs.
|