Delete types/v14.go, replace with v15.go.
Rename internal types to not include message version.
I don't currently see the need to support multiple message
versions that have incompatible layouts.
v15 is backwards compatible with v14, so the config example now
specifies both.
Rename the "response" field in the config file to "static" as
dynamic/static makes more sense from the user's perspective.
(Internally it's still SpaceapidConfig.{Dynamic,Response}
to align with type names and usage.)
78 lines
2.4 KiB
Markdown
78 lines
2.4 KiB
Markdown
# SpaceAPI Daemon
|
|
|
|
`spaceapid` serves a [SpaceAPI](https://spaceapi.io)-compatible JSON on port 8080:
|
|
|
|
```shell
|
|
$ curl http://localhost:8080 | jq
|
|
{
|
|
"api_compatibility": [
|
|
"14",
|
|
"15"
|
|
],
|
|
"space": "CCCHH",
|
|
...
|
|
}
|
|
```
|
|
|
|
## 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 dynamic parts of the message
|
|
- `"static"`
|
|
- The static (pre-filled) parts of the message
|
|
|
|
See [Running](#Running) for details.
|
|
|
|
## Building
|
|
|
|
See the `go.mod` file for minimum required Go version.
|
|
There are currently no dependencies apart from the Go standard library.
|
|
|
|
``` shell
|
|
go build -ldflags '-X main.version=v420.69-rc23' .
|
|
```
|
|
|
|
## Running
|
|
|
|
Set the environment variable to a comma-separated list of config files or pass the `-c` flag.
|
|
|
|
```shell
|
|
env SPACEAPID_CONFIG_PATH=config-template.json go run .
|
|
# OR
|
|
go run . -c config-credentials.json,config-dynamic.json,config-response.json
|
|
```
|
|
|
|
## Updating values
|
|
|
|
The state of the boolean `state->open` and `state->message` property can be modified via `/state/{open,message}`:
|
|
|
|
```shell
|
|
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
|
|
```
|
|
|
|
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"`.
|
|
Currently only the sensors with the `value/unit/location/name/description` schema are implemented.
|
|
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.
|
|
|
|
```shell
|
|
curl -X PUT -u user:password -d 23.42 http://localhost:8080/sensors/{temperature,humidity,...}[/location[/name]]
|
|
```
|
|
|
|
As can be seen in the example, the http urls are generated from sensor type and optionally `location` and `name`.
|
|
Depending on sensor type, `location` might be required for your sensors, see the schema for details.
|