1
0
Fork 0
spaceapi-tuerpie-nix/README.md

82 lines
1.9 KiB
Markdown
Raw Normal View History

# Spaceapi Tuerpi
2024-01-05 16:02:03 +00:00
Feeding our SpaceAPI with data from our entrance door.
2024-01-05 16:02:03 +00:00
## Usage
2024-01-05 16:02:03 +00:00
To run the client, please change `DOOR_PIN` accordingly to your setup. `DOOR_PIN` defaults to a closed door, when `HIGH`.
2024-01-05 16:02:03 +00:00
You need to provide the environment variables `SPACEAPI_URL` and `API_KEY` to send the status to the SpaceAPI server. Details of the server can be found on the [project page](https://github.com/dezentrale/spaceapi-rs).
2024-01-05 14:01:24 +00:00
## Build
[Install stable version of rust](https://rustup.rs/) and run a regular cargo build:
```sh
cargo build
```
### Cross compile
Install arm toolchain and *libmusl* for static linked binaries:
```sh
apt-get install gcc-arm-linux-gnueabihf musl-dev musl-tools
```
Build the application for raspberry pi:
```sh
cargo build --target=armv7-unknown-linux-musleabihf
```
2024-01-05 15:30:28 +00:00
## Install
2024-01-05 16:02:03 +00:00
Build the project as release and place `pi` binary under `/usr/local/bin/spaceapi-tuerpi`
2024-01-05 15:30:28 +00:00
```sh
2024-01-05 16:02:03 +00:00
sudo install -m 755 -o root -g root \
2024-01-05 15:30:28 +00:00
target/release/pi \
/usr/local/bin/spaceapi-tuerpi
```
Configure the spaceapi systemd service by placing the service description under `/etc/systemd/system/spaceapi.service`:
```
[Unit]
Description=SpaceAPI tuerpi client
After=network.target
[Service]
Type=simple
Restart=always
EnvironmentFile=/etc/spaceapi-tuerpi.env
ExecStart=/usr/local/bin/spaceapi-tuerpi
[Install]
WantedBy=multi-user.target
```
Place the environment configuration with URL and API-Key under `/etc/spaceapi-tuerpi.env`:
```
SPACEAPI_URL=<your SpaceAPI server endpoint>
API_KEY=<your secret API key>
2024-01-05 16:02:03 +00:00
#DOOR_PIN=27 # Set the door pin
#RUST_LOG=ERROR # Set debug level
2024-01-05 15:30:28 +00:00
```
Ensure the `/etc/spaceapi-tuerpi.env` can be read only by root by executing:
2024-01-05 16:02:03 +00:00
```sh
sudo chmod 600 /etc/spaceapi-tuerpi.env
sudo chown root:root /etc/spaceapi-tuerpi.env
2024-01-05 15:30:28 +00:00
```
Apply changes to systemd to enable and start the service
```sh
2024-01-05 16:02:03 +00:00
sudo systemctl daemon-reload
sudo systemctl enable --now spaceapi
2024-01-05 15:30:28 +00:00
```