如何使用 Node-RED 和郁金香标签从边缘设备向机器发送数据
  • 04 Nov 2023
  • 2 阅读时间
  • 贡献者

如何使用 Node-RED 和郁金香标签从边缘设备向机器发送数据


文章摘要

了解如何在 Node-RED 中使用 Tulip 标签从边缘设备向 Tulip 机器本机发送数据

从 OS 50.1 开始,Tulip 原生支持将 Tulip 边缘设备用作机器数据源。

使用 Node RED,你可以用新的tulip-tag节点创建任意 "标签",并向这些标签发送数据。在映射机器属性时,这些标签将作为数据源自动出现在特定的边缘设备下。

**建议在新流程中使用郁金香标签而不是机器 API。**郁金香标签允许您使用可重复使用的流程报告机器数据,这些流程可跨设备共享,无需对特定设备进行任何修改,也无需将机器属性信息复制粘贴到机器 API 节点中。

概述

本文将介绍如何使用预装在 Tulip Edge 设备上的新 Tulip Tag 节点从 Node-RED 向 Tulip 机器发送数据。

本指南将介绍以下步骤:

要求

要创建 Tulip 标签,您必须拥有符合以下条件的 Tulip Edge 设备:

  • 支持 Node-RED(边缘 MC 或边缘 IO)
  • 已启用 Node-RED
  • 固件版本 >= OS50

用户指南

本指南将介绍在 Node-RED 中创建标签、向标签发送数据的工作流程,然后演示如何将标签映射到 Tulip 中的机器属性。我们还将介绍如何同时向多个标签写入数据(仅限 OS 51 及更高版本)。

在 Node-RED 中创建标签

  1. 在 Tulip Edge 设备上打开 Node-RED 并登录。

    1. *供访问 Node-RED 时参考:在 Edge IO 上使用 Node-RED
    2. 如果你使用的是 OS50 或更高版本,你会在 Node-RED 编辑器的左侧边栏看到 Tulip 标签节点。

  1. 郁金香标签节点拖放到编辑器中,然后双击打开节点编辑器。你会看到 "标签列表 "属性是必需的--你需要创建一个标签列表,其中包含此边缘设备的所有标签。**每个边缘设备只能创建一个标签列表。**单击 "编辑"创建新的标签列表,如下图所示。

  1. 在标签列表节点中,您可以创建任意数量的标签。单击**+add**创建标签。

  1. 每个标签有三个部分:ID、标签和类型。

    1. 标签**ID:**这是一个类似代码的标识符,用于识别标签。一旦创建,就不能更改。有效字符包括字母、数字(不能以数字开头)和下划线。例如:part_countmyState1
    2. 标签标签:这是可分配给标签的人类可读标签。要重命名标签,只需更新标签(而不是 ID)。例如"部件计数"。
    3. 类型:数据类型 - 字符串、整数、浮点数或布尔。必须与映射的机器属性类型相匹配。

  1. 完成添加标记后,单击添加确认更改并返回上一个节点编辑器。确保无误后再保存。

:::(Info) (注意)"Unmapped(未映射)"不是错误,只是一个警告,说明您尚未将标签映射到郁金香中的机器属性:

在 Node-RED 中向标签发送数据

创建标签列表后,"选择标签"(Select Tag)下拉菜单会自动填充所有标签(按人类可读标签)。

  1. 选择该节点的标签。

  1. 要向该标签写入数据,现在需要向郁金香标签节点发送信息。发送到节点的任何信息的有效载荷(即msg.payload)都将写入标签。

例如,下面我们连接了一个msg.payload=0的注入节点,它将把整数 0 写入标签 "部件计数"。

将标签映射到机器属性

最后,要在 Tulip 中查看数据,必须访问 Tulip 网站并将标签映射到机器属性。

  1. 导航到机器页面,选择要发送数据的机器,然后打开 "配置 "选项卡。你会看到一个机器属性列表;点击一个属性进行映射。您将看到边缘设备(按序列号)作为数据源。您无需创建此数据源,它将在您部署带有标签列表的流程时自动创建。
  2. 单击右侧边栏中的边缘设备并展开Node-RED文件夹。你应该能看到与属性类型相同的所有属性。单击相关属性旁边的链接按钮,对其进行映射。

  1. 属性现在显示为映射,映射标签的标签标签为信号。

  1. 此外,在 Node-RED 中,郁金香标签节点的状态应从 "未映射 "变为 "已连接"。

  1. 向标签写入数据(即在本例中点击 "注入 "节点),现在会导致映射属性的数据出现。

向多个标记发送数据(高级)

:::(Info) (注)此功能仅适用于 OS51 及更高版本:

可以一次向多个标记批量写入数据。

  1. 在 Node-RED 中,创建一个郁金香标记节点,并取消选中从列表中选择标记选项。

  1. 现在,该节点的输入信息有效载荷应包含标签 ID 与要写入值的映射。 例如,如果要将部件数 0 写入 id 为part_count 的整数标签,并将状态"Running "写入 id 为state 的字符串标签,则信息应为

msg.payload = { "part_count":0, "state":"运行中 }

示例使用边缘 IO 和 Node-RED 管理机器状态和部件计数

本示例是本文所述 Node RED 库流程的更新版本,硬件设置请参考本文:使用 Edge IO 和 Node-RED 管理机器状态和部件计数

下面对流程进行了更新,以使用郁金香标签节点代替机器属性节点。此流程无需修改即可部署到多个边缘设备上。

  1. 在 Node-RED 中,导入并部署以下流程:


## 65CCB8", "icon": "font-awesome/fa-arrows-v"},{"id": "d99ec5b3.e9dfb8", "type": "function", "z": "85d16074.518e2", "name": "Convert values with scale/offset", "func": "const scale = env.get('SCALE');//nconst offset = env.get('OFFSET');//nconst prop = env.get('PROPERTY');//nif (Array.isArray(msg[prop])){n msg[prop] = msg[prop].map((x) => (scale \* x + offset));\n} else {\n msg[prop] = scale \* msg[prop] + offset;\n}\nreturn msg;", "outputs":1, "noerr":0, "initialize":", "finalize":", "x":250, "y":60, "wires":[[]]},{"id": "71c9f8f2.7adf08", "type": "tab", "label": "Machine Visibility with Current Clamp and Breakbeam", "disabled":false, "info": "This library flow is a basic machine monitoring application to gain visibility into the machine's state and part count using a current clamp and breakbeam.它跟踪以下两个 Edge IO 输入:\n\n \***零件计数**:从 0 开始,每当 GPIO 引脚 1 被触发为高电平时(例如,当断光束被触发时)就向上计数。可通过 "重置部件计数 "节点重置为 0。当部件数发生变化时,将当前部件数发送至郁金香机器属性。**\机器状态**:将 CR-3111 电流钳监测的机器有效值电流发送到 Edge IO 差分 ADC。RMS 读数是以 1kHz 频率采集的 1 秒钟缓冲数据,每 5 秒采样一次。可在 Node-RED 或 Tulip 中设置阈值,以确定机器的开/关状态。"},{"id":"256235b9.3bb72a","type":"subflow:85d16074.518e2","z":"71c9f8f2.7adf08","name":"CR-3111 Scaling","env":[{"name":"PROPERTY","value":"data","type":"str"},{"name":"SCALE","value":"3000","type":"num"},{"name":"OFFSET","value":"0","type":"num"}],"x":800,"y":360,"wires":[["88390763.49ad58", "b594a80b.7f3f18"]]},{"id":"daf59f31.d1ec8","type":"tulip-high-speed-analog","z":"71c9f8f2.7adf08","name":"Differential ADC Readings","analogConfig":"71b68226.a6568c","dataTypeIdx":"2","inputs":0,"mode":"continuous","dataMsgProperty":"data","refreshRate":"1","refreshFrames":"all","x":150,"y":380,"wires":[["96ef65ab.afba78"]]},{"id":"82a0d2e1.62cec","type":"inject","z":"71c9f8f2.7adf08","name":"Reset Part Count","props":[],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":130,"y":100,"wires":[["25bb1de8.b3e502"]]},{"id":"579dcfa3.596ad","type":"tulip-digital-input","z":"71c9f8f2.7adf08", "name": "Monitor Pin 1", "runMode": "continuous", "configMode": "static", "outputMode": "object", "refreshRate":1, "enabledPins":[true,false,false,false,false,false,false], "x":110, "y":160, "wires":[["27e78fe6.8e08c"]]},{"id":"27e78fe6.8e08c","type":"switch","z":"71c9f8f2.7adf08","name":"Filter for pinUp","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":300,"y":160,"wires":[["f1b02903.a2f2b8"]]},{"id":"f1b02903.a2f2b8","type":"change","z":"71c9f8f2.7adf08", "name": "Increment Part Count", "rules":[{"t": "set", "p": "partCount", "pt": "flow", "to":"$flowContext('partCount') + 1", "tot": "jsonata"},{"t":"set","p":"payload","pt":"msg","to":"partCount","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":160,"wires":[["eed4e051.7bc12"]]},{"id":"25bb1de8.b3e502","type":"change","z":"71c9f8f2.7adf08", "name": "Set Part Count = 0", "rules":[{"t": "set", "p": "partCount", "pt": "flow", "to": "0", "tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":100,"wires":[[]]},{"id":"dcb54611.9f7ca8", "type": "comment", "z": "71c9f8f2.7adf08", "name": "Monitor Part Count", "info": "Starts with Part Count = 0 and counts up whenever GPIO Pin 1 is toggled high.单击 "重置部件计数 "节点可将部件计数重置为 0。当部件计数发生变化时,将当前部件计数发送至配置的郁金香机器属性。", "x":130, "y":40, "wires":[]},{"id": "9ff956ce.4ee9b8", "type": "comment", "z": "71c9f8f2.7adf08", "name": "Monitor RMS Current(监控有效值电流)", "info": "向 Edge IO 差分 ADC 发送 CR-3111 电流钳监控的机器有效值电流。RMS 读数是以 1kHz 频率采集的 1 秒缓冲数据,每 5 秒采样一次。可在 Node-RED 或 Tulip 中设置阈值,以确定机器的开/关状态。","x":140,"y":320,"wires":[]},{"id":"96ef65ab.afba78","type":"switch","z":"71c9f8f2.7adf08", "name": "Filter 1/5 readings", "property": "numReadings", "propertyType": "flow", "rules":[{"t": "eq", "v":"4","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":390,"y":380,"wires":[["41bac391.9beffc"],["78eb2b71.a4c2c4"]]},{"id":"41bac391.9beffc","type":"change","z":"71c9f8f2.7adf08","name":"Pass message","rules":[{"t":"set","p":"numReadings","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":360,"wires":[["256235b9.3bb72a"]]},{"id":"78eb2b71.a4c2c4","type":"change","z":"71c9f8f2.7adf08", "name": "Drop message & increment", "rules":[{"t": "set", "p": "numReadings", "pt": "flow", "to":"$flowContext('numReadings') + 1", "tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":400,"wires":[[]]},{"id":"88390763.49ad58","type":"switch","z":"71c9f8f2.7adf08","name":"Is Current > 100mA?","property":"data","propertyType":"msg","rules":[{"t":"gt","v":"0.1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":620,"wires":[["b0fc9af.9e90c68"],["b271da6d.f05098"]]},{"id":"53f44746.f831e8","type":"comment","z":"71c9f8f2.7adf08", "name": "计算机器状态的子流程", "info": "启用该子流程后,可根据配置的阈值计算出机器是开还是关。该机器属性需要在 Tulip 中配置为文本属性,并将属性 deviceInfo 复制粘贴到 Tulip 机器属性节点中。", "x":240, "y":620, "wires":[]},{"id": "b0fc9af.9e90c68","type":"change","z":"71c9f8f2.7adf08","name":"State = ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":600,"wires":[["a197e7f6.0d6c58"]]},{"id":"b271da6d.f05098","type":"change","z":"71c9f8f2.7adf08","name":"State = OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":640,"wires":[["a197e7f6.0d6c58"]]},{"id":"eed4e051.7bc12","type":"tulip-tag","z":"71c9f8f2.7adf08","name":"","tagList":"58dfe1ff.615b","staticTag":true,"tagId":"part\_count","x":730,"y":160,"wires":[[]]},{"id":"b594a80b.7f3f18","type":"tulip-tag","z":"71c9f8f2.7adf08","name":"","tagList":"58dfe1ff.615b","staticTag":true,"tagId":"current","x":1020,"y":360,"wires":[[]]},{"id":"a197e7f6.0d6c58","type":"tulip-tag","z":"71c9f8f2.7adf08","name":"","tagList":"58dfe1ff.615b","staticTag":true,"tagId":"state","x":930,"y":620,"wires":[[]]},{"id":"80b0c03.326c84","type":"inject","z":"71c9f8f2.7adf08", "name": "Initialization", "props":[], "repeat":"", "crontab":"", "once":true, "onceDelay":0.1,"topic":"","x":110,"y":440,"wires":[["81df5e3e.f5126"]]},{"id":"81df5e3e.f5126","type":"change","z":"71c9f8f2.7adf08","name":"Initialize numReadings = 0","rules":[{"t":"set","p":"numReadings","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":440,"wires":[[]]},{"id":"71b68226.a6568c", "type": "tulip-high-speed-analog-config", "name": "Differential ADC RMS @ 1kHZ", "bufferSize": "1000", "frequency": "1000", "adcId":"0", "diffAdcResistor": "200", "enableTime":false, "enableFreq":false, "enableRMS":true, "enablePowerSpec":false},{"id": "58dfe1ff.615b", "type": "tulip-tag-list", "name": "Part-Making Machine Tags", "tags":[{"id": "part\_count", "label": "Part Count", "type": "integer"},{"id": "current", "label": "Current (RMS)", "type": "float"},{"id": "state", "label": "State", "type": "string"}]}]].


``` 2.流程显示如下:


![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Send%20Data%20to%20Machines%20from%20Edge%20Devices%20using%20Node-RED%20and%20Tulip%20Tags_566767267.png){height="" width="550"}


该流程还有以下 Tulip 标记列表:


![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Send%20Data%20to%20Machines%20from%20Edge%20Devices%20using%20Node-RED%20and%20Tulip%20Tags_566767339.png){height="" width="350"}


1. 此边缘设备作为数据源出现在 Tulip 中,带有三个标记:


	1. 部件计数:每当 GPIO 输入引脚 1 变为高电平时递增。假定断路器光束插入该引脚。
	2. 电流 (有效值): 每 5 秒写入 CR3111-3000 的有效值电流读数(单位为安培)。假设该电流传感器插入差分 ADC。
	3. 状态:如果电流大于 100mA,则报告 "ON";如果电流小于 100mA,则报告 "OFF":


![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Send%20Data%20to%20Machines%20from%20Edge%20Devices%20using%20Node-RED%20and%20Tulip%20Tags_566767591.png){height="" width="350"}


1. 当断光束切换或电流读数每 5 秒更新一次时,您将看到数据出现:


![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Send%20Data%20to%20Machines%20from%20Edge%20Devices%20using%20Node-RED%20and%20Tulip%20Tags_566767660.png){height="" width=""}




---


您找到想要的东西了吗?


您还可以前往[community.tulip.co](https://community.tulip.co/?utm_source=intercom&utm_medium=article-link&utm_campaign=all)发布您的问题,或查看其他人是否遇到过类似问题! 


本文对您有帮助吗?