From 6017bf86f981c3d44ccd463f323db5fb444d5b1b Mon Sep 17 00:00:00 2001 From: 0x1d Date: Tue, 6 May 2025 10:03:16 +0200 Subject: [PATCH] docs: update docs, add examples --- .gitignore | 1 + Makefile | 2 +- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ api/rcond.yaml | 4 +++- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c5e82d7..d220594 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.vscode bin \ No newline at end of file diff --git a/Makefile b/Makefile index 682d2f7..3d79a7e 100644 --- a/Makefile +++ b/Makefile @@ -17,4 +17,4 @@ dev: RCOND_API_TOKEN=1234567890 go run cmd/rcond/main.go upload: - scp rcond-${ARCH} pi@rpi-40ac:/home/pi/rcond + scp bin/rcond-${ARCH} pi@rpi-test:/home/pi/rcond diff --git a/README.md b/README.md index decff9d..d714e36 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,13 @@ A simple daemon and REST API to manage: - system hostname through the hostname1 service - authorized SSH keys through the user's authorized_keys file +## Requirements +- Make +- Go 1.19 or later +- NetworkManager +- systemd +- Linux operating system + ## Build and Run ```bash @@ -49,3 +56,46 @@ All endpoints use JSON for request and response payloads. |----------------------|-----------------------------------------|---------------| | RCOND_ADDR | Address to bind the HTTP server to. | 0.0.0.0:8080 | | RCOND_API_TOKEN | API token to use for authentication. | N/A | + +## Examples + +### Setup an Access Point + +```bash +#!/usr/bin/env bash +set -euo pipefail + +# Example script to create and activate a WiFi access point +# Requires: +# - RCOND_ADDR (default: http://0.0.0.0:8080) +# - RCOND_API_TOKEN (your API token) + +API_URL="${RCOND_ADDR:-http://0.0.0.0:8080}" +API_TOKEN="${RCOND_API_TOKEN:-your_api_token}" +INTERFACE="wlan0" +SSID="MyAccessPoint" +PASSWORD="StrongPassword" + +echo "Creating access point '$SSID' on interface '$INTERFACE'..." +ap_response=$(curl -sSf -X POST "$API_URL/network/ap" \ + -H "Content-Type: application/json" \ + -H "X-API-Token: $API_TOKEN" \ + -d '{ + "interface": "'"$INTERFACE"'", + "ssid": "'"$SSID"'", + "password": "'"$PASSWORD"'" + }') + +# Extract the UUID from the JSON response +AP_UUID=$(echo "$ap_response" | jq -r '.uuid') + +echo "Activating connection with UUID '$AP_UUID' on interface '$INTERFACE'..." +curl -sSf -X PUT "$API_URL/network/interface/$INTERFACE" \ + -H "Content-Type: application/json" \ + -H "X-API-Token: $API_TOKEN" \ + -d '{ + "uuid": "'"$AP_UUID"'" + }' + +echo "Access point '$SSID' is now up and running on $INTERFACE." +``` \ No newline at end of file diff --git a/api/rcond.yaml b/api/rcond.yaml index b84a084..7a54dc0 100644 --- a/api/rcond.yaml +++ b/api/rcond.yaml @@ -7,7 +7,9 @@ info: servers: - url: http://localhost:8080 description: Local development server - + - url: http://rpi-test:8080 + description: Raspberry Pi test server + components: securitySchemes: ApiKeyAuth: