Crates.io | kpal |
lib.rs | kpal |
version | 0.2.2 |
source | src |
created_at | 2019-12-14 10:34:33.357203 |
updated_at | 2020-03-08 07:33:08.244941 |
description | An extensible and RESTful control system for physical computing |
homepage | |
repository | https://github.com/kmdouglass/kpal |
max_upload_size | |
id | 189327 |
size | 244,824 |
KPAL is an extensible control system for physical computing.
KPAL is under development. The API will not be considered stable until 1.0 is released.
KPAL allows you to control and read data from peripherals attached to a computer such as your desktop or Raspberry Pi. It acts as an interface between users and individual peripherals through two application programming interfaces (APIs):
mkdir -p ~/.kpal/libraries
libbasic-plugin.so
from the archive into the ~/.kpal/libraries
folder. This is
an example plugin that is used for demonstrations and testing; it does not control any actual
hardware.kpald
to start the daemon. If you want to see the logs, set the RUST_LOG
environment variable to info
, error
, or debug
, depending on the desired log level:RUST_LOG=info ./kpald
You may now make HTTP requests to the daemon. The following examples use the UNIX curl
command
line utility to make the requests, but you may use the HTTP client of your choice.
# Get the libraries that are available to the daemon
curl -s localhost:8000/api/v0/libraries
# Get the library with ID 0
curl -s localhost:8000/api/v0/libraries/0
# Create a new peripheral from the library with ID 0
curl -s \
--request POST \
localhost:8000/api/v0/peripherals \
--header "Content-Type: application/json" \
--data '{"name":"foo","library_id":0}'
# Create a new peripheral and override the default value of a pre-init attribute
curl -s \
--request POST \
localhost:8000/api/v0/peripherals \
--header "Content-Type: application/json" \
--data '{
"name": "foo",
"library_id": 0,
"attributes": {
"0": {"id":0, "variant":"double", "value": 999.99}
}
}'
# Get all the peripherals currently managed by the daemon
curl -s localhost:8000/api/v0/peripherals
# Get the peripheral with ID 0
curl -s localhost:8000/api/v0/peripherals/0
# Get the attributes of the peripheral with ID 0
curl -s localhost:8000/api/v0/peripherals/0/attributes
# Get the attribute with ID 0 from the peripheral with ID 0
curl -s localhost:8000/api/v0/peripherals/0/attributes/0
# Set the value of the attribute with ID 0 of the peripheral with ID 0
curl -s \
--request PATCH \
localhost:8000/api/v0/peripherals/0/attributes/0 \
--header "Content-Type: application/json" \
--data '{"variant":"double","value":42}'
The object model is the set of resources with which users interact. Currently, these resources include:
The KPAL daemon, or kpald
, is a web server that runs on the computer to which the peripherals are
connected. Users directly interact with the daemon through the user API. Each peripheral runs
inside its own thread which is spawned by a POST request to the user API. The daemon forwards other
user requests to each thread through the thread's dedicated channel. The threads interpret the
incoming requests and, in response, read and write data to individual plugins through the plugin
API using shared libraries.
Plugins are the means by which peripherals are integrated into KPAL. A plugin uses a shared library
(a .so
file on Linux) to communicate with the daemon. The common set of functions that the
library provides is the plugin API. Any programming language that can provide a C language
interface can be used to write a plugin library.
A plugin combines the data that represents a peripheral's state with the functionality for controlling the hardware device that is modeled by the peripheral.