# AICVSHUB **Repository Path**: Lin-carp/aicvshub ## Basic Information - **Project Name**: AICVSHUB - **Description**: 调用GopherHub 进行设备管理,包括文件上传,ssh服务,设备端口代理等实用功能,也支持批量执行命令 - **Primary Language**: Go - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-26 - **Last Updated**: 2026-04-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # aicvshub (plugin skeleton) This is a runnable Go skeleton for a plugin-based service framework. ## What you get - `core/`: minimal plugin framework + in-process pub/sub event bus - `plugins/httpserver`: HTTP service plugin (receives HTTP requests and publishes events) - `plugins/httpconsumer`: subscriber plugin (subscribes to HTTP events and processes request data) - `plugins/mqttclient`: optional MQTT client plugin (connects to an external broker per `config.yaml`) - `plugins/deviceauth`: Device authentication plugin (manages device registration and activation using SQLite) - `cmd/server`: bootstrap that loads plugins and handles graceful shutdown ## Run ```bash go run ./cmd/server ``` The server will start: - HTTP API server (see `config.yaml` `server.port`, default 8081) - Optional `mqtt_client` plugin if enabled (connects to **your** external broker; see `config.yaml`) - SQLite database for device authentication (`devices.db`) ### Test HTTP API Send a request: ```bash curl -X POST "http://localhost:8080/ingest?source=demo" -H "Content-Type: application/json" -d "{\"hello\":\"world\"}" ``` Watch the server logs: the `httpconsumer` plugin will print the received request details. ### MQTT Run your own MQTT broker (e.g. Mosquitto, EMQX). Point `config.yaml` → `mqtt.broker_host` / `mqtt.tcp_port` for the HTTP debug TCP client, and `mqtt_client` if you enable the in-process device demo client. #### Using Command Line Tools (mosquitto) **Publish device telemetry:** ```bash mosquitto_pub -h localhost -p 1883 -t "devices/device123/telemetry" -m '{"temperature":25.5,"humidity":60}' ``` **Publish device status:** ```bash mosquitto_pub -h localhost -p 1883 -t "devices/device123/status" -m '{"online":true}' ``` **Subscribe to device commands:** ```bash mosquitto_sub -h localhost -p 1883 -t "devices/device123/command" ``` #### Using Go Test Demo Run the comprehensive test demo: ```bash go run examples/mqtt_test_demo.go ``` This demo will connect to the broker address in the example, subscribe to commands, and publish telemetry every 5 seconds. See `examples/README.md` for more details and other examples. ### Device Authentication The system includes a complete device registration and activation flow: 1. **Device Registration**: When a device first connects, it's automatically registered in the `pending_devices` table 2. **Device Activation**: Administrators can view pending devices and activate them via HTTP API 3. **Communication Control**: Only activated devices can send telemetry data **API Endpoints:** - `GET /api/devices/pending` - List pending devices - `GET /api/devices/activated` - List activated devices - `POST /api/devices/activate` - Activate a device **Example:** ```bash # View pending devices curl http://localhost:8080/api/devices/pending # Activate a device curl -X POST http://localhost:8080/api/devices/activate \ -H "Content-Type: application/json" \ -d '{"device_id": "device123", "activated_by": "admin"}' ``` See `docs/DEVICE_AUTH.md` for detailed documentation. #### Using Python Client (paho-mqtt) ```python import paho.mqtt.client as mqtt broker = "localhost" port = 1883 client_id = "python-client-001" def on_connect(client, userdata, flags, rc): print(f"Connected with result code {rc}") client.subscribe("devices/+/command") def on_message(client, userdata, msg): print(f"Received: {msg.topic} -> {msg.payload.decode()}") client = mqtt.Client(client_id) client.on_connect = on_connect client.on_message = on_message client.connect(broker, port, 60) client.loop_forever() ``` #### Topic Structure - **Device Telemetry**: `devices/{deviceId}/telemetry` - 设备上报遥测数据 - **Device Status**: `devices/{deviceId}/status` - 设备状态更新 - **Device Commands**: `devices/{deviceId}/command` - 服务器下发命令到设备 The MQTT plugin will automatically: - Subscribe to `devices/+/telemetry` and `devices/+/status` topics - Convert MQTT messages to EventBus events - Publish commands from EventBus to MQTT topics