2023-11-04 22:42:37 +01:00
|
|
|
# SpaceAPI Daemon
|
|
|
|
|
2023-11-04 23:30:26 +01:00
|
|
|
`spaceapid` serves a [SpaceAPI](https://spaceapi.io)-compatible JSON on port 8080:
|
2023-11-04 22:42:37 +01:00
|
|
|
|
|
|
|
```shell
|
2024-08-03 21:02:44 +02:00
|
|
|
$ curl http://localhost:8080 | jq
|
2024-01-14 23:19:45 +01:00
|
|
|
{
|
|
|
|
"api_compatibility": [
|
|
|
|
"14"
|
|
|
|
],
|
|
|
|
"space": "CCCHH",
|
|
|
|
...
|
|
|
|
}
|
2023-11-04 22:42:37 +01:00
|
|
|
```
|
|
|
|
|
2024-01-14 23:19:45 +01:00
|
|
|
## Configuring
|
|
|
|
|
|
|
|
spaceapid has to be configured via one or multiple json files.
|
|
|
|
A sample configuration is provided as [config-template.json](./config-template.json).
|
|
|
|
The config consists of three parts:
|
|
|
|
|
|
|
|
- `"credentials"`
|
|
|
|
- List of Username/Password credentials for HTTP BasicAuth
|
|
|
|
- `"dynamic"`
|
|
|
|
- The configuration for the dynamic parts of the message
|
|
|
|
- `"response"`
|
|
|
|
- The static (pre-filled) parts of the response
|
|
|
|
|
2024-02-13 19:48:18 +01:00
|
|
|
See [Running](#Running) for details.
|
2024-01-14 23:19:45 +01:00
|
|
|
|
2024-08-03 21:02:44 +02:00
|
|
|
## Building
|
|
|
|
|
|
|
|
See the `go.mod` file for minimum required Go version.
|
|
|
|
There are currently no dependencies apart from the Go standard library.
|
|
|
|
|
2024-08-03 21:55:05 +02:00
|
|
|
``` shell
|
|
|
|
go build -ldflags '-X main.version=v420.69-rc23' .
|
|
|
|
```
|
|
|
|
|
2024-08-03 21:02:44 +02:00
|
|
|
## Running
|
|
|
|
|
|
|
|
Set the environment variable to a comma-separated list of config files or pass the `-c` flag.
|
|
|
|
|
|
|
|
```shell
|
2024-08-03 21:56:26 +02:00
|
|
|
env SPACEAPID_CONFIG_PATH=config-template.json go run .
|
2024-08-03 21:02:44 +02:00
|
|
|
# OR
|
|
|
|
go run . -c config-credentials.json,config-dynamic.json,config-response.json
|
|
|
|
```
|
|
|
|
|
2024-01-14 23:19:45 +01:00
|
|
|
## Updating values
|
|
|
|
|
2024-08-03 21:02:44 +02:00
|
|
|
The state of the boolean `state->open` and `state->message` property can be modified via `/state/{open,message}`:
|
2023-11-04 22:42:37 +01:00
|
|
|
|
|
|
|
```shell
|
2024-08-03 21:02:44 +02:00
|
|
|
curl -X PUT -u user:password -d true http://localhost:8080/state/open
|
|
|
|
curl -X PUT -u user:password -d "Nur mit Passierschein A38 :3" http://localhost:8080/state/message
|
2023-11-04 22:42:37 +01:00
|
|
|
```
|
|
|
|
|
2024-08-03 21:02:44 +02:00
|
|
|
As `state->message` is optional, its value can be deleted by using the `PUT` method with an empty payload, or by using `DELETE`:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
curl -X PUT -u user:password -d "" http://localhost:8080/state/message
|
|
|
|
# OR
|
|
|
|
curl -X DELETE -u user:password http://localhost:8080/state/message
|
|
|
|
```
|
|
|
|
|
|
|
|
The same updating procedure applies for the endpoints for sensors configured under `"dynamic"`.
|
2024-02-13 19:48:18 +01:00
|
|
|
Currently only the sensors with the `value/unit/location/name/description` schema are implemented.
|
2024-08-03 15:15:31 +02:00
|
|
|
At the time of writing this includes `temperature`, `barometer`, `humidity`, `beverage_supply`, `power_consumption`, and `account_balance`.
|
|
|
|
Out-of-spec sensors may be used as well, as long as they share the same schema.
|
2023-11-04 22:42:37 +01:00
|
|
|
|
|
|
|
```shell
|
2024-08-03 21:02:44 +02:00
|
|
|
curl -X PUT -u user:password -d 23.42 http://localhost:8080/sensors/{temperature,humidity,...}[/location[/name]]
|
2023-11-04 22:42:37 +01:00
|
|
|
```
|
|
|
|
|
2024-02-13 19:48:18 +01:00
|
|
|
As can be seen in the example, the http urls are generated from sensor type and optionally `location` and `name`.
|
2024-08-03 15:15:31 +02:00
|
|
|
Depending on sensor type, `location` might be required for your sensors, see the schema for details.
|