ARIZON USB APIServer
An APIServer for ARIZON USB force sensors.
Installation
Clone & cd into this repository then:
python setup.py install
Or download from PyPI:
python -m pip install arizon-usb-apiserver
Get Started
The apiserver operates in two modes: RESTful and gRPC. They share the same configuration schema.
Basics
To read the sensor locally, use this snippet:
from serial import Serial
from arizon_usb_apiserver import Sensor
if __name__ == '__main__':
conn = Serial("COM16", 115200)
sensor = Sensor(conn)
sensor.reset()
while True:
print(sensor.read_once())
To generate configuration from command line interaction run:
python -m arizon_usb_apiserver configure
RESTful
To launch the apiserver in RESTful mode, set the API_SERVER_RESTFUL to 1 before run apiserver command:
export API_SERVER_RESTFUL=1
Or run with variable
API_SERVER_RESTFUL=1 python -m arizon_usb_apiserver apiserver
Powershell:
Set-Item -Path Env:API_SERVER_RESTFUL -Value 1
Or you can directely run apiserver.restful
python -m arizon_usb_apiserver apiserver.restful
Here are some examples to test the apiserver using curl
-
Init sensor
curl -X 'PUT' \ 'http://127.0.0.1:8080/v1/arizon/force?flag=true' \ -H 'accept: application/json'
-
Read sensor
curl -X 'GET' \ 'http://127.0.0.1:8080/v1/arizon/force' \ -H 'accept: application/json'
-
Shutdown sensor
curl -X 'PUT' \ 'http://127.0.0.1:8080/v1/arizon/force?flag=false' \ -H 'accept: application/json'
gRPC
Run this command
python -m arizon_usb_apiserver apiserver
Or you can directely run apiserver.grpc
python -m arizon_usb_apiserver apiserver.grpc
Testing with cli tools
To test RESTful API, run:
python -m arizon_usb_apiserver test.restful
You will be asked to input API endpoint.
To test gRPC API, run:
python -m arizon_usb_apiserver test.grpc
You will be asked to input API endpoint.
Generate Client
Restful
First launch the apiserver, then run openapi-python-client:
openapi-python-client generate --url http://127.0.0.1:8080/openapi.json
rm -rf ./arizon_usb_driver/client/restful
mv fast-api-client/fast_api_client ./arizon_usb_driver/client/restful
rm -rf ./fast-api-client
GRPC
First cd arizon_usb_apiserver/grpc, then run:
python -m grpc_tools.protoc -I../../manifests/protos --python_out=. --pyi_out=. --grpc_python_out=. ../../manifests/protos/force_packet.proto
You might need to replace import force_packet_pb2 as force__packet__pb2 with import arizon_usb_apiserver.grpc.force_packet_pb2 as force__packet__pb2
Serial Protocol
| Field | Content |
|---|---|
| Head | 0xFE |
| Status | 1 Byte |
| Data | 3 Byte |
| XOR checksum | 1 Byte |
- Status: 4 bits of address + 4 bits represents number of digits
- Data: 3 bytes of signed integers, no digit, big-endian.
- Checksum: xor() of first 5 bytes
Configuration
Here is an template of configuration
arizon_usb_apiserver: # Key
api: # Control API settings
interface: 0.0.0.0 # Listen interface
port: 8080 # Listen port
debug: false # Enable debug
serials: # Serial connections, can be a list
- baudrate: 115200 # Baudrate, default is 115200, no need to change
port: COM8 # Port name
addr: "dev1" # Friendly name
data_path: ./arizon_data # Path to save data
Metadata
Release files for arizon-usb-apiserver 0.4.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| arizon-usb-apiserver-0.4.7.tar.gz | 14.6 kB | Without provenance | Details for arizon-usb-apiserver-0.4.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| arizon_usb_apiserver-0.4.7-py3-none-any.whl | Python 3 | none | any | Details for arizon_usb_apiserver-0.4.7-py3-none-any.whl |
Total release size: 34.2 kB
Release files / arizon-usb-apiserver-0.4.7.tar.gz
| Download URL | arizon-usb-apiserver-0.4.7.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
495b0f7a9bb6171c6b79d8d7bd167f061c91f59b5c5c6a0756dea872a2c3d390
|
|
BLAKE2b-256 checksum How to use checksums |
3a375f09dc73e65bd7af51387fc922cf6114cbb10451d96128d24672f5d58b2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / arizon_usb_apiserver-0.4.7-py3-none-any.whl
| Download URL | arizon_usb_apiserver-0.4.7-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7abefa21f337a60f639739b60a63d9a86b9f6f5ab07af433b0be0f4c91b3cf14
|
|
BLAKE2b-256 checksum How to use checksums |
895e9bf8d28ecc9241746b9f08cef6c26ef8bb1658134bde7eb088302529f458
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for arizon-usb-apiserver 0.4.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.