基于PackML通过MQTT接口的生产线模拟器
PackML MQTT Simulator是一个虚拟生产线,通过MQTT实现PackML接口,适用于工业4.0软件解决方案的开发。该模拟器实现PackML状态模型,并通过环境变量定义的MQTT主题进行通信,支持基本MQTT主题结构或SparkPlugB协议。
!https://github.com/Spruik/PackML-MQTT-Simulator/raw/master/docs/PackML-StateModel.png
模拟器支持以下主题和负载定义:
该模拟器提供虚拟生产线环境,用于测试和开发工业4.0软件解决方案。它实现完整的PackML状态模型,通过MQTT协议进行通信,可模拟生产线的状态转换、速度变化、计数器数据等关键指标,支持基本MQTT或SparkPlugB协议,帮助开发人员在无需实际硬件的情况下验证工业软件的功能。
需运行并可访问MQTT服务器,推荐使用Docker方式运行模拟器,通过环境变量控制MQTT连接、站点、区域和生产线配置。
基本MQTT结构
shell$ docker run -it -e SITE=Site -e AREA=Area -e LINE=Line -e MQTT_URL=mqtt://broker.hivemq.com -m 30m spruiktec/packml-simulator 2020-06-22T03:13:49.301Z | info: Initializing 2020-06-22T03:13:49.817Z | info: Connected to mqtt://broker.hivemq.com:1883 2020-06-22T03:13:49.819Z | info: Site/Area/Line/Status/UnitModeCurrent : Production
启动后,使用MQTT客户端发布命令至Site/Area/Line/Command/Reset和Site/Area/Line/Command/Start,使模拟机器进入执行状态。
SparkPlugB
shell$ docker run -it -e CLIENT_TYPE=sparkplugb -e SITE=Site -e AREA=Area -e LINE=Line -e MQTT_URL=mqtt://broker.hivemq.com -m 30m spruiktec/packml-simulator 2020-06-22T03:13:49.301Z | info: Initializing 2020-06-22T03:13:49.817Z | info: Connected to mqtt://broker.hivemq.com:1883 2020-06-22T03:13:49.819Z | info: Site/Area/Line/Status/UnitModeCurrent : Production
启动后,使用Sparkplug B设备命令发布Command.Reset和Command.Start指标,使模拟机器进入执行状态。
基本MQTT结构
shell$ npm i ... added 421 packages from 213 contributors and audited 421 packages in 12.337s found 0 vulnerabilities $ export LINE=Line $ node --max-old-space-size=20 ./src/index.js 2020-06-22T03:13:49.301Z | info: Initializing 2020-06-22T03:13:49.817Z | info: Connected to mqtt://broker.hivemq.com:1883 2020-06-22T03:13:49.819Z | info: Site/Area/Line/Status/UnitModeCurrent : Production
SparkPlugB
shell$ npm i ... added 421 packages from 213 contributors and audited 421 packages in 12.337s found 0 vulnerabilities $ export LINE=Line $ export CLIENT_TYPE=sparkplugb $ node --max-old-space-size=20 ./src/index.js 2021-06-01T20:05:30.841Z | info: Initializing 2021-06-01T20:05:31.141Z | info: Connected to mqtt://broker.hivemq.com:1883 2021-06-01T20:05:31.142Z | info: Site/Area/Line/Status/UnitModeCurrentStr : Production
发送命令时请间隔一定时间,使机器在发出Start命令前进入Idle状态:
shell# 发送Reset命令 $ docker run --init -it --rm efrecon/mqtt-client pub -h broker.hivemq.com -u USERNAME -P PASSWORD -t "Site/Area/Line/Command/Reset" -m 1 # 发送Start命令 $ docker run --init -it --rm efrecon/mqtt-client pub -h broker.hivemq.com -u USERNAME -P PASSWORD -t "Site/Area/Line/Command/Start" -m 1
虚拟生产线通过基本MQTT结构进行接口交互,订阅<SITE>/<AREA>/<LINE>/Command/*主题(见下文),并发布信息至<SITE>/<AREA>/<LINE>/Status和<SITE>/<AREA>/<LINE>/Admin。<SITE>、<AREA>和<LINE>通过环境变量设置。
命令主题
可用命令如下:
| 主题 | 取值 | 功能 |
|---|---|---|
<SITE>/<AREA>/<LINE>/Command/Clear | 1, 0 | 清除命令 |
<SITE>/<AREA>/<LINE>/Command/Reset | 1, 0 | 重置命令 |
<SITE>/<AREA>/<LINE>/Command/Start | 1, 0 | 启动命令 |
<SITE>/<AREA>/<LINE>/Command/Hold | 1, 0 | 暂停命令 |
<SITE>/<AREA>/<LINE>/Command/Unhold | 1, 0 | 恢复命令 |
<SITE>/<AREA>/<LINE>/Command/Complete | 1, 0 | 完成命令 |
<SITE>/<AREA>/<LINE>/Command/Stop | 1, 0 | 停止命令 |
<SITE>/<AREA>/<LINE>/Command/Abort | 1, 0 | 中止命令 |
<SITE>/<AREA>/<LINE>/Command/UnitMode | String | 模式命令(Production生产, Manual手动, Maintenance维护) |
<SITE>/<AREA>/<LINE>/Command/MachSpeed | Decimal | 机器速度命令 |
<SITE>/<AREA>/<LINE>/Command/Parameter/*n*/ID | Integer | 参数n ID |
<SITE>/<AREA>/<LINE>/Command/Parameter/*n*/Name | String | 参数n 名称 |
<SITE>/<AREA>/<LINE>/Command/Parameter/*n*/Unit | String | 参数n 单位 |
<SITE>/<AREA>/<LINE>/Command/Parameter/*n*/Value | Decimal | 参数n 值 |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/ID | Integer | 产品i ID |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/ProcessParameter/*j*/ID | Integer | 产品i 工艺参数j ID |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/ProcessParameter/*j*/Name | Integer | 产品i 工艺参数j 名称 |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/ProcessParameter/*j*/Unit | Integer | 产品i 工艺参数j 单位 |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/ProcessParameter/*j*/Value | Integer | 产品i 工艺参数j 值 |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/Ingredient/*j*/ID | Integer | 产品i 原料j ID |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/Ingredient/*j*/Parameter/*k*/ID | Integer | 产品i 原料j 参数k ID |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/Ingredient/*j*/Parameter/*k*/Name | Integer | 产品i 原料j 参数k 名称 |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/Ingredient/*j*/Parameter/*k*/Unit | Integer | 产品i 原料j 参数k 单位 |
<SITE>/<AREA>/<LINE>/Command/Product/*i*/Ingredient/*j*/Parameter/*k*/Value | Integer | 产品i 原料j 参数k 值 |
状态主题
可用状态如下:
| 主题 | 取值 | 功能 |
|---|---|---|
<SITE>/<AREA>/<LINE>/Status/StateCurrent | String | 当前PackML状态(字符串) |
<SITE>/<AREA>/<LINE>/Status/StateCurrentStr | Integer | 当前PackML状态 |
<SITE>/<AREA>/<LINE>/Status/UnitMode | Integer | 当前PackML模式 |
<SITE>/<AREA>/<LINE>/Status/UnitModeStr | String | 当前PackML模式(字符串) |
<SITE>/<AREA>/<LINE>/Status/CurMachSpeed | Decimal | 当前机器速度 |
<SITE>/<AREA>/<LINE>/Status/MachSpeed | Decimal | 当前机器速度设定值 |
<SITE>/<AREA>/<LINE>/Status/Parameter/*n*/ID | Integer | 参数n ID |
<SITE>/<AREA>/<LINE>/Status/Parameter/*n*/Name | String | 参数n 名称 |
<SITE>/<AREA>/<LINE>/Status/Parameter/*n*/Unit | String | 参数n 单位 |
<SITE>/<AREA>/<LINE>/Status/Parameter/*n*/Value | Decimal | 参数n 值 |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/ID | Integer | 产品i ID |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/ProcessParameter/*j*/ID | Integer | 产品i 工艺参数j ID |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/ProcessParameter/*j*/Name | Integer | 产品i 工艺参数j 名称 |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/ProcessParameter/*j*/Unit | Integer | 产品i 工艺参数j 单位 |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/ProcessParameter/*j*/Value | Integer | 产品i 工艺参数j 值 |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/Ingredient/*j*/ID | Integer | 产品i 原料j ID |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/Ingredient/*j*/Parameter/*k*/ID | Integer | 产品i 原料j 参数k ID |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/Ingredient/*j*/Parameter/*k*/Name | Integer | 产品i 原料j 参数k 名称 |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/Ingredient/*j*/Parameter/*k*/Unit | Integer | 产品i 原料j 参数k 单位 |
<SITE>/<AREA>/<LINE>/Status/Product/*i*/Ingredient/*j*/Parameter/*k*/Value | Integer | 产品i 原料j 参数k 值 |
管理主题
可用管理状态如下:
| 主题 | 取值 | 功能 |
|---|---|---|
<SITE>/<AREA>/<LINE>/Admin/MachDesignSpeed | String | 当前PackML状态 |
<SITE>/<AREA>/<LINE>/Admin/ProdConsumedCount/*i*/ID | String | 消耗计数器ID |
<SITE>/<AREA>/<LINE>/Admin/ProdConsumedCount/*i*/Name | String | 消耗计数器名称 |
<SITE>/<AREA>/<LINE>/Admin/ProdConsumedCount/*i*/Unit | String | 消耗计数器单位 |
<SITE>/<AREA>/<LINE>/Admin/ProdConsumedCount/*i*/Count | String | 消耗计数器自重置后计数 |
<SITE>/<AREA>/<LINE>/Admin/ProdConsumedCount/*i*/AccCount | String | 消耗计数器累计计数 |
<SITE>/<AREA>/<LINE>/Admin/ProdProcessedCount/*i*/ID | String | 加工计数器ID |
<SITE>/<AREA>/<LINE>/Admin/ProdProcessedCount/*i*/Name | String | 加工计数器名称 |
<SITE>/<AREA>/<LINE>/Admin/ProdProcessedCount/*i*/Unit | String | 加工计数器单位 |
<SITE>/<AREA>/<LINE>/Admin/ProdProcessedCount/*i*/Count | String | 加工计数器自重置后计数 |
<SITE>/<AREA>/<LINE>/Admin/ProdProcessedCount/*i*/AccCount | String | 加工计数器累计计数 |
<SITE>/<AREA>/<LINE>/Admin/ProdDefectiveCount/*i*/ID | String | 缺陷计数器ID |
<SITE>/<AREA>/<LINE>/Admin/ProdDefectiveCount/*i*/Name | String | 缺陷计数器名称 |
<SITE>/<AREA>/<LINE>/Admin/ProdDefectiveCount/*i*/Unit | String | 缺陷计数器单位 |
<SITE>/<AREA>/<LINE>/Admin/ProdDefectiveCount/*i*/Count | String | 缺陷计数器自重置后计数 |
<SITE>/<AREA>/<LINE>/Admin/ProdDefectiveCount/*i*/AccCount | String | 缺陷计数器累计计数 |
请参考Sparkplug B负载和主题负载定义规范。
以下是发布至Ignition v8.1.5 SCADA(带Cirrus Link模块)的示例。MQTT引擎配置了与模拟
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。



探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
不支持 push
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务