spruiktec/packml-simulator基于PackML通过MQTT接口的生产线模拟器
PackML MQTT Simulator是一个虚拟生产线,通过MQTT实现PackML接口,适用于工业4.0软件解决方案的开发。该模拟器实现PackML状态模型,并通过环境变量定义的MQTT主题进行通信,支持基本MQTT主题结构或SparkPlugB协议。
!PackML状态模型
模拟器支持以下主题和负载定义:
该模拟器提供虚拟生产线环境,用于测试和开发工业4.0软件解决方案。它实现完整的PackML状态模型,通过MQTT协议进行通信,可模拟生产线的状态转换、速度变化、计数器数据等关键指标,支持基本MQTT或SparkPlugB协议,帮助开发人员在无需实际硬件的情况下验证工业软件的功能。
需运行并可访问MQTT服务器,推荐使用Docker方式运行模拟器,通过环境变量控制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,使模拟机器进入执行状态。
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指标,使模拟机器进入执行状态。
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
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引擎配置了与模拟



manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务