Receive data from devices in your space and publish them as part of your SpaceAPI JSON :3
Find a file
2024-08-03 15:15:31 +02:00
config Rename module 2024-05-26 20:52:15 +02:00
handlers Rename module 2024-05-26 20:52:15 +02:00
persistence Move persistence stuff to own package 2024-05-26 20:52:21 +02:00
types Location is optional for beverage_supply so make it omitempty 2024-05-26 20:52:22 +02:00
util Refactor environment sensor URL path generation 2024-05-26 20:52:23 +02:00
.gitignore Rename config shards in .gitignore 2024-05-26 20:52:18 +02:00
config-template.json Location is optional for beverage_supply so make it omitempty 2024-05-26 20:52:22 +02:00
go.mod Rename module 2024-05-26 20:52:15 +02:00
LICENSE Add BSD-3-Clause LICENSE 2023-11-04 21:07:40 +01:00
main.go docs: Fix typos 2024-08-03 15:15:31 +02:00
README.md docs: Fix typos 2024-08-03 15:15:31 +02:00

SpaceAPI Daemon

spaceapid serves a SpaceAPI-compatible JSON on port 8080:

$ curl 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 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.

curl -X PUT -u user:password -d 23.42 http://[::1]: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.

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 config-credentials.json,config-dynamic.json,config-response.json