EdgeX-UI-Go 详解
EdgeX-UI-Go 是 EdgeX Foundry 的官方 Web 管理界面,基于 Go + Vue.js 开发,提供可视化设备管理、数据监控和系统配置功能。以下是核心内容解析:
1. 核心功能
模块 | 功能说明 |
---|---|
设备管理 | 添加/删除设备,配置协议属性(Modbus、MQTT等) |
数据看板 | 实时显示设备上报的指标数据(如温度、湿度),支持图表化展示 |
规则引擎 | 配置简单告警规则(如温度超过阈值触发通知) |
服务监控 | 查看 EdgeX 各微服务(Core Data、Command等)的运行状态和日志 |
API调试工具 | 内置 Swagger UI,可直接调用 EdgeX REST API |
2. 快速部署
方式1:Docker运行
docker run -d --name edgex-ui-go \
-p 4000:4000 \
-e EDGEX_SECURITY_SECRET_STORE=false \ # 关闭安全认证(测试用)
edgexfoundry/edgex-ui-go:latest
访问 http://localhost:4000
,默认账号密码:admin/admin
方式2:源码编译
git clone https://github.com/edgexfoundry/edgex-ui-go
cd edgex-ui-go
make build && ./edgex-ui-go
3.关键代码结构
edgex-ui-go/
├── backend/ # Go后端服务
│ ├── cmd/ # Main入口
│ ├── internal/ # 业务逻辑
│ │ ├── handler/ # HTTP请求处理(REST API)
│ │ └── service/ # EdgeX服务交互层
├── webapp/ # Vue.js前端项目
│ └── src/views/ # 页面组件(设备列表、仪表盘等)
└── Makefile # 构建脚本
4.自定义开发指南
(1)添加新API接口
- 在后端定义路由(
backend/internal/handler/router.go
):
router.GET("/api/v1/custom", handlers.CustomHandler)
- 实现处理逻辑(新建
backend/internal/handler/custom.go
):
func CustomHandler(w http.ResponseWriter, r *http.Request) {
response.NewSuccessResponse("Hello EdgeX").WriteTo(w)
}
(2)扩展前端页面
1.在 webapp/src/views/
下新增Vue组件:
<template>
<div>自定义设备控制面板</div>
</template>
<script>
export default {
name: 'CustomDevicePanel'
}
</script>
2.在路由中注册(webapp/src/router/index.js
):
{
path: '/custom',
component: () => import('@/views/CustomDevicePanel.vue')
}
5.配置文件说明
配置文件路径:res/configuration.toml
关键参数示例:
[Service]
Host = "0.0.0.0"
Port =4000
[EdgeX]
Server = "http://edgex-core-data:59880" # Core Data服务地址
Timeout ="30s"
6.与EdgeX微服务交互
通过Go SDK调用Core Data API获取设备事件:
import (
"github.com/edgexfoundry/go-mod-core-contracts/clients"
)
func GetEvents() {
client := clients.NewEventClient("http://edgex-core-data:59880")
events, _ := client.Events(context.Background()) //获取最近10条事件
}
7.Debug技巧
- 查看实时日志:
docker logs -f edgex-ui-go
- API调试工具:
访问http://localhost:4000/api/swagger
(内置Swagger)
如需对接特定协议(如OPC UA)或深度定制UI,可进一步讨论具体场景!
内容由零声教学AI助手提供,问题来源于学员提问