edgex接入modbus设备

本文介绍edgex利用modbus-tcp协议接入模拟设备,利用kuiper根据设备名称进行筛选,然后发布到mqtt server的过程

1.下载 ModbusPal并配置

ModbusPal 下载连接https://sourceforge.net/p/modbuspal/discussion/899955/thread/72cf35ee/cd1f/attachment/ModbusPal.jarz

 寄存器地址及传感器值字段

edgex接入modbus设备_第1张图片

添加模拟设备

edgex接入modbus设备_第2张图片

添加寄存器地址及字段

edgex接入modbus设备_第3张图片 

 添加ModbusPal支持的值自动生成器,它可以绑定到寄存器:

edgex接入modbus设备_第4张图片

edgex接入modbus设备_第5张图片 

运行模拟器

edgex接入modbus设备_第6张图片 

 2.添加Device Profile及设备

edgex接入modbus设备_第7张图片

 内容如下,源文件为yml格式,此处只能用bash

startingAddress该属性定义Modbus设备从0开始的startingAddress。例如,GET命令从Modbus地址4004请求数据以获取温度数据,因此起始寄存器地址应该是4003。

RAW_TYPE:这个属性定义了从Modbus设备读取的二进制数据,然后我们可以使用值类型来指示用户想要接收的数据类型。

dbtimestamp:
  created: 1649747852301
  modified: 1649747852301
id: e37ae456-dd0b-40ba-bff8-f17be919cc2b
name: Hbfec-Temperature-Sensor
manufacturer: Audon Electronics
description: The NANO_TEMP is a Ethernet Thermometer measuring from -55°C to 125°C
  with a web interface and Modbus TCP communications.
model: Temperature
labels: [Web, Modbus TCP, SNMP]
deviceResources:
- description: Lower alarm threshold of the temperature
  name: ThermostatL
  isHidden: true
  tag: ""
  properties:
    valueType: Float32
    readWrite: RW
    units: ""
    minimum: ""
    maximum: ""
    defaultValue: ""
    mask: ""
    shift: ""
    scale: "0.1"
    offset: ""
    base: ""
    assertion: ""
    mediaType: ""
  attributes:
    primaryTable: HOLDING_REGISTERS
    rawType: Int16
    startingAddress: 3999
- description: Upper alarm threshold of the temperature
  name: ThermostatH
  isHidden: true
  tag: ""
  properties:
    valueType: Float32
    readWrite: RW
    units: ""
    minimum: ""
    maximum: ""
    defaultValue: ""
    mask: ""
    shift: ""
    scale: "0.1"
    offset: ""
    base: ""
    assertion: ""
    mediaType: ""
  attributes:
    primaryTable: HOLDING_REGISTERS
    rawType: Int16
    startingAddress: 4000
- description: 1 - OFF (disabled), 2 - Lower, 3 - Higher, 4 - Lower or Higher
  name: AlarmMode
  isHidden: true
  tag: ""
  properties:
    valueType: Int16
    readWrite: RW
    units: ""
    minimum: ""
    maximum: ""
    defaultValue: ""
    mask: ""
    shift: ""
    scale: ""
    offset: ""
    base: ""
    assertion: ""
    mediaType: ""
  attributes:
    primaryTable: HOLDING_REGISTERS
    startingAddress: 4001
- description: Temperature x 10 (np. 10,5 st.C to 105)
  name: Temperature
  isHidden: false
  tag: ""
  properties:
    valueType: Float32
    readWrite: R
    units: ""
    minimum: ""
    maximum: ""
    defaultValue: ""
    mask: ""
    shift: ""
    scale: "0.1"
    offset: ""
    base: ""
    assertion: ""
    mediaType: ""
  attributes:
    primaryTable: HOLDING_REGISTERS
    rawType: Int16
    startingAddress: 4003
deviceCommands:
- name: AlarmThreshold
  isHidden: false
  readWrite: RW
  resourceOperations:
  - deviceResource: ThermostatL
    defaultValue: ""
    mappings: {}
  - deviceResource: ThermostatH
    defaultValue: ""
    mappings: {}
- name: AlarmMode
  isHidden: false
  readWrite: RW
  resourceOperations:
  - deviceResource: AlarmMode
    defaultValue: ""
    mappings:
      "1": "OFF"
      "2": Lower
      "3": Higher
      "4": Lower or Higher

添加设备

edgex接入modbus设备_第8张图片

选择device-modbus服务

edgex接入modbus设备_第9张图片 

选择刚才添加的device profile

edgex接入modbus设备_第10张图片 

添加设备,给设备取一个名字

edgex接入modbus设备_第11张图片 

添加自动采集的数据属性及时间间隔

edgex接入modbus设备_第12张图片 

添加设备地址信息

楼主是在win10的宿主机上跑的虚拟机,在虚拟机里利用docker-compose安装的edgex套件,我的宿主机ip是192.168.100.100,虚拟机网络模式为NAT,虚拟机的IP是192.168.32.16,这里address的地址应该填写宿主机ip192.168.100.100而不是192.168.32.2.

edgex接入modbus设备_第13张图片 3.根据kuiper-manager设置kuiper

创建kerper服务 ,这里的ip地址为docker为kuiper服务分配的ip地址

edgex接入modbus设备_第14张图片

 创建流,流类型选择edgex总线

edgex接入modbus设备_第15张图片

创建规则,筛选设备名为modbus的数据

edgex接入modbus设备_第16张图片

 slink设置为mqtt server

edgex接入modbus设备_第17张图片

 获取数据

利用MQTT.fx连接上mqtt server

查看订阅主题的消息

edgex接入modbus设备_第18张图片

 

你可能感兴趣的:(EdgeX,物联网,物联网,edge,边缘计算)