快速开始
欢迎使用 driver-box!这是一款轻量级、配置化的物联网边缘平台。本指南将帮助您在5分钟内完成安装和第一个设备的接入。
工作流程概述
Section titled “工作流程概述”driver-box 的核心工作流程如下:
flowchart LR
A[安装driver-box] --> B[配置设备接入]
B --> C[启动服务]
C --> D[验证数据收集]
D --> E[配置数据导出]
在开始之前,请确保您的环境满足以下要求:
- Go 1.18+:编译和运行driver-box
- Git:下载源码
- 最低配置:128MB RAM
- 推荐配置:256MB RAM以上
- 支持平台:Linux、Windows、macOS
步骤1:获取driver-box
Section titled “步骤1:获取driver-box”# 1. 获取源码# 方式一:从本地项目目录(推荐)cd /path/to/your/driver-box/project
# 方式二:从Git仓库(如果需要)# git clone https://github.com/iBUILDING-X/driver-box.git# cd driver-box
# 2. 下载依赖go mod tidygo mod vendor
# 3. 编译go build -o driver-box main.go
# 4. 运行./driver-box步骤2:设备接入配置
Section titled “步骤2:设备接入配置”driver-box采用JSON配置的方式接入设备。下面以一个Modbus温湿度传感器为例:
创建配置目录
Section titled “创建配置目录”mkdir -p res/driver/modbus{ "deviceModels": [ { "name": "温湿度传感器", "description": "Modbus温湿度传感器", "devicePoints": [ { "name": "temperature", "description": "温度", "valueType": "float", "readWrite": "R", "primaryTable": "HOLDING_REGISTER", "startAddress": "40001", "rawType": "uint16", "scale": 0.1, "unit": "℃" }, { "name": "humidity", "description": "湿度", "valueType": "float", "readWrite": "R", "primaryTable": "HOLDING_REGISTER", "startAddress": "40002", "rawType": "uint16", "scale": 0.1, "unit": "%" } ], "devices": [ { "id": "sensor-001", "description": "会议室温湿度传感器", "connectionKey": "modbus-tcp-01", "ttl": "30s" } ] } ], "connections": { "modbus-tcp-01": { "host": "192.168.1.100", "port": 502, "mode": "tcp", "timeout": 5000, "slaveId": 1 } }, "protocolName": "modbus"}res/└── driver/ └── modbus/ └── config.json步骤3:验证接入效果
Section titled “步骤3:验证接入效果”查看设备影子
Section titled “查看设备影子”启动driver-box后,打开浏览器访问:http://localhost:8080/api/v1/shadow/all
[ { "id": "sensor-001", "points": { "temperature": { "value": 25.5, "updated_at": "2024-01-22T15:30:00Z" }, "humidity": { "value": 65.2, "updated_at": "2024-01-22T15:30:00Z" } }, "online": true, "ttl": "30s" }]注意:API直接返回JSON数组,没有外层包装结构。实际响应格式基于设备影子的内部结构定义。
通过API控制设备
Section titled “通过API控制设备”curl http://localhost:8080/api/v1/device/readPoint?id=sensor-001&point=temperaturecurl "http://localhost:8080/api/v1/device/writePoint?id=device-001&point=switch&value=1"