Update README #14

Merged
june merged 1 commit from Bendodroid-newReadme into main 2024-01-14 23:33:19 +01:00

View file

@ -3,28 +3,58 @@
`spaceapid` serves a [SpaceAPI](https://spaceapi.io)-compatible JSON on port 8080: `spaceapid` serves a [SpaceAPI](https://spaceapi.io)-compatible JSON on port 8080:
```shell ```shell
curl -X GET http://localhost:8080 $ curl -X GET http://[::1]:8080 | jq
{
"api_compatibility": [
"14"
],
"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 configuration for the dynamic parts of the message
- `"response"`
- The static (pre-filled) parts of the response
See [Running](#running) for details.
## Updating values
The state of the boolean `state->open` property can be modified via `/state/open`: The state of the boolean `state->open` property can be modified via `/state/open`:
```shell ```shell
curl -X PUT -u user:password -d true http://localhost:8080/state/open curl -X PUT -u user:password -d true http://[::1]:8080/state/open
```
The same is true for the endpoints for sensors configured under `"dynamic"`.
Currently only `temperature` and `humidity` are implemented.
```shell
curl -X PUT -u user:password -d 23.42 http://[::1]:8080/{temperature,humidity}/location[/name]
``` ```
## Building ## Building
See the `go.mod` file for minimum required Go version. There are currently no dependencies apart from the Go See the `go.mod` file for minimum required Go version.
standard library. There are currently no dependencies apart from the Go standard library.
```shell
go build .
```
## Running ## Running
Substitute the environment variables with appropriate custom values. Set the environment variable to a comma-separated list of config files or pass the `-c` flag.
```shell ```shell
env BA_USERNAME=user BA_PASSWORD=password JSON_TEMPLATE_PATH=ccchh-template.json go run . env CONFIG_PATH=config-template.json go run .
# OR
go run . -c credentials.json,dynamic.json,response.json
``` ```