Files
towerd/README.md
2026-06-18 14:09:14 -04:00

152 lines
3.2 KiB
Markdown

# TowerD
I wrote this to control the "hardware" on KW1FOX-1 tower.
its.. not really intended for use anywhere else but, if anything inspires you go ahead and grab it!
## Install
```shell
sudo git clone https://git.kitsunehosting.net/Kenwood/towerd.git /opt/towerd
cd /opt/towerd
cargo build --release
sudo cp systemd/towerd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now towerd
```
## Usage
```shell
./target/release/towerd --verbose
# systemd
sudo systemctl status towerd
sudo journalctl -u towerd -f
```
## Metrics
Originally I was going to write to my influxdb server over the network but I learned that influxdb can be configured
to save locally and drain when network is up, which would be pretty awesome for edge computing like the tower. So,
new architecture is to run locally and configure it to replicate.
### Local Config
Create `/opt/towerd/.env`
```shell
INFLUXDB_INIT_PASSWORD=change-me
INFLUXDB_INIT_ADMIN_TOKEN=change-me-to-a-long-random-token
INFLUXDB_INIT_ORG=tower
INFLUXDB_INIT_BUCKET=tower
```
then
```shell
cd /opt/towerd
docker compose up -d
```
Init vars only matter once
InfluxDB listens on `127.0.0.1:8086` only.
### Configure towerd
Create `/etc/towerd/env`:
```shell
TOWERD_INFLUX_URL=http://127.0.0.1:8086
TOWERD_INFLUX_ORG=tower
TOWERD_INFLUX_BUCKET=tower
TOWERD_INFLUX_TOKEN=<same as INFLUXDB_INIT_ADMIN_TOKEN>
TOWERD_INFLUX_HOST=kw1fox-1
# optional
# TOWERD_INFLUX_INTERVAL_S=30
```
Restart towerd after editing:
```shell
sudo systemctl restart towerd
```
### Replicate to remote InfluxDB
Need influx cli
```shell
# register the remote server
influx remote create \
--host http://127.0.0.1:8086 \
--token "$TOWERD_INFLUX_TOKEN" \
--name kitsune-remote \
--remote-url http://influx.kitsunehosting.net:8086 \
--remote-api-token <remote-write-token> \
--remote-org-id <remote-org-id>
# list remotes to get the ID from the previous step
influx remote list \
--host http://127.0.0.1:8086 \
--token "$TOWERD_INFLUX_TOKEN"
# replicate the local bucket to the remote bucket
influx replication create \
--host http://127.0.0.1:8086 \
--token "$TOWERD_INFLUX_TOKEN" \
--name tower-to-kitsune \
--remote-id <remote-id> \
--local-bucket-id <local-bucket-id> \
--remote-bucket <remote-bucket-name>
```
Find the local bucket ID:
```shell
influx bucket list \
--host http://127.0.0.1:8086 \
--token "$TOWERD_INFLUX_TOKEN"
```
Check replication queue health:
```shell
influx replication list \
--host http://127.0.0.1:8086 \
--token "$TOWERD_INFLUX_TOKEN"
```
## Renogy controller
Need rs232 adapter to talk modbus to renogy controller
```shell
# list adapters: ls -l /dev/serial/by-id/
TOWERD_RENOGY_SERIAL=/dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_Bridge_...
```
```shell
# optional
TOWERD_RENOGY_SLAVE=255
TOWERD_RENOGY_BAUD=9600
TOWERD_RENOGY_INTERVAL_S=10
TOWERD_RENOGY_TIMEOUT_MS=1000
```
Thank you to [ESP32ArduinoRenogy](https://github.com/wrybread/ESP32ArduinoRenogy) for doing all the hard work!
## systemd
`towerd` loads `/etc/towerd/env` via `EnvironmentFile`. If using Docker for InfluxDB, ensure Docker starts before towerd:
```ini
[Unit]
After=docker.service
Wants=docker.service
```
Add those lines to `/etc/systemd/system/towerd.service` under `[Unit]`.