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-01-14 23:19:45 +01:00
|
|
|
$ curl -X GET http://[::1]:8080 | jq
|
|
|
|
{
|
|
|
|
"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
|
|
|
|
|
|
|
|
See [Running](#running) for details.
|
|
|
|
|
|
|
|
## Updating values
|
|
|
|
|
2023-11-04 23:30:26 +01:00
|
|
|
The state of the boolean `state->open` property can be modified via `/state/open`:
|
2023-11-04 22:42:37 +01:00
|
|
|
|
|
|
|
```shell
|
2024-01-14 23:19:45 +01:00
|
|
|
curl -X PUT -u user:password -d true http://[::1]:8080/state/open
|
2023-11-04 22:42:37 +01:00
|
|
|
```
|
|
|
|
|
2024-01-14 23:19:45 +01:00
|
|
|
The same is true for the endpoints for sensors configured under `"dynamic"`.
|
|
|
|
Currently only `temperature` and `humidity` are implemented.
|
2023-11-04 22:42:37 +01:00
|
|
|
|
|
|
|
```shell
|
2024-01-15 15:27:08 +01:00
|
|
|
curl -X PUT -u user:password -d 23.42 http://[::1]:8080/sensors/{temperature,humidity}/location[/name]
|
2023-11-04 22:42:37 +01:00
|
|
|
```
|
|
|
|
|
2024-01-14 23:19:45 +01:00
|
|
|
## Building
|
|
|
|
|
|
|
|
See the `go.mod` file for minimum required Go version.
|
|
|
|
There are currently no dependencies apart from the Go standard library.
|
|
|
|
|
2023-11-04 22:42:37 +01:00
|
|
|
## Running
|
|
|
|
|
2024-01-14 23:19:45 +01:00
|
|
|
Set the environment variable to a comma-separated list of config files or pass the `-c` flag.
|
2023-11-04 22:42:37 +01:00
|
|
|
|
|
|
|
```shell
|
2024-01-14 23:19:45 +01:00
|
|
|
env CONFIG_PATH=config-template.json go run .
|
|
|
|
# OR
|
2024-01-31 18:16:48 +01:00
|
|
|
go run . -c config-credentials.json,config-dynamic.json,config-response.json
|
2023-11-04 22:42:37 +01:00
|
|
|
```
|