Receive data from devices in your space and publish them as part of your SpaceAPI JSON :3
Go to file
2024-03-24 16:29:50 +01:00
config Add -c flag to specify list of config files 2024-01-14 21:56:11 +01:00
handlers We don't need to write anything on successful requests actually, 200 is the default 2024-01-16 01:48:48 +01:00
types Handle sensors that don't have a name, just a location 2024-01-14 21:54:44 +01:00
util Open the persistent file just for writing when saving 2024-01-14 21:54:43 +01:00
.gitignore Add -c flag to specify list of config files 2024-01-14 21:56:11 +01:00
config-template.json Fix URLs in config template 2024-03-24 16:29:50 +01:00
go.mod Initial commit 2023-11-04 21:07:27 +01:00
LICENSE Add BSD-3-Clause LICENSE 2023-11-04 21:07:40 +01:00
main.go Print version on startup, set this via -ldflags "-X main.version=foo" 2024-01-16 02:23:39 +01:00
README.md Correct typos in README and config template 2024-01-15 15:27:08 +01:00

SpaceAPI Daemon

spaceapid serves a SpaceAPI-compatible JSON on port 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. 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 for details.

Updating values

The state of the boolean state->open property can be modified via /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.

curl -X PUT -u user:password -d 23.42 http://[::1]:8080/sensors/{temperature,humidity}/location[/name]

Building

See the go.mod file for minimum required Go version. There are currently no dependencies apart from the Go standard library.

Running

Set the environment variable to a comma-separated list of config files or pass the -c flag.

env CONFIG_PATH=config-template.json go run .
# OR
go run . -c credentials.json,dynamic.json,response.json