方法文章

基于MQTT的聚合物挤出过程数据通信

DOI:

10.3791/63717

2022年7月15日

本文内容

摘要

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

本研究提出了一种基于消息队列遥测传输(Message Queuing Telemetry Transport,MQTT)协议的薄膜挤出系统与监控设备之间数据通信的灵活方法。

摘要

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

本研究旨在通过采用基于发布-订阅模式的消息队列遥测传输(Message Queuing Telemetry Transport, MQTT)协议,在TCP/IP之上构建一种适用于聚合物加工设备的灵活数据通信结构。即使使用传统设备,加工数据也可通过互联网通信由任意位置的多种设备进行测量和记录。基于消息的协议实现了灵活的通信方式,克服了现有客户端-服务器协议的局限性。多个设备可订阅由源设备发布的加工数据。该方法支持多个发布者与订阅者之间的数据通信。本研究实现了一个系统,可将来自设备及附加传感器的数据发布至消息代理(message broker)。订阅者可对代理转发的工艺数据进行监控和存储。该系统已部署并应用于一条薄膜挤出生产线,以验证其有效性。

引言

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

在第四次工业革命浪潮中,获取和监控各种加工数据已成为重要任务1。特别是利用工艺数据改进制造过程,并建立高效的运行计划,将成为所有制造设施的重要目标2,3。如果能够及时从工厂发出警报或实施预测性维护,则可大幅减少停机时间4。近年来,针对聚合物加工过程的数据分析已开展了大量研究工作5,6。然而,由于从现有系统中获取此类数据存在困难,开展这些工作并不容易7。控制系统与仪表的层级结构使得数据采集与通信变得复杂。

首先,无法从不同生产日期的设备上获取数据。由于需要在专有格式的不同现场总线之间实现互操作性,因此实现不同设备间的通信十分困难。这种方式使得通信方法和数据格式保持私密。虽然这有助于轻松维护数据安全,但使用户在服务和未来发展方面依赖于设备制造商。目前,连接到聚合物加工设备的现代控制计算机大多采用基于 Windows 的系统,但其运行的软件通常是在专有的开发环境中创建的。尽管可以使用不同厂商的可编程逻辑控制器(PLC)与传感器或执行器进行通信,但在许多情况下,上层的监控与数据采集(SCADA)系统仍依赖于控制计算机8。这种做法导致了大量协议、现场总线和控制系统在市场上相互竞争。尽管这种复杂性随着时间的推移已逐步缓解,但目前仍有多种现场总线和协议在广泛使用。

另一方面,控制设备与SCADA之间的通信已由开放平台通信统一架构(OPCUA)实现标准化9。此外,SCADA与制造执行系统(MES)之间的通信也主要通过OPCUA实现。在这种紧密的层级结构中,难以自由提取数据用于过程监控与分析。通常,必须从SCADA或MES中提取数据10。如前所述,这些系统具有供应商专属性,且数据格式很少开放。因此,数据提取需要原始信息技术/运营技术(IT/OT)解决方案供应商的大量支持,这可能阻碍监控与分析所需的数据获取。

在薄膜挤出生产线中,控制用PC由SCADA系统进行监控11。SCADA系统由计算机程序操作,而该程序通常难以修改。尽管该程序可能具备可编辑性,但修改过程成本高昂且耗时。为了便于远程监测和分析加工数据,这些数据应能够从任意位置访问。若需在远离现场的位置监控加工数据,计算机程序必须具备将加工数据流式传输至互联网的功能12。此外,采用开放且免费的方法可降低数据采集的成本13。该方法使得即使资金有限、无法投资商业IT解决方案的小型工厂也能够进行数据分析14

本研究采用基于发布-订阅模型的消息协议。消息队列遥测传输(MQTT)是一种开放的标准协议,可实现多个数据提供者与消费者之间的消息传递15在此,我们提出一种利用MQTT协议对现有制造设施进行数据采集、传输与监控的系统。该系统在薄膜挤出生产线上进行了测试,以验证其性能。来自原始控制器的数据被传输至边缘设备 通过 Modbus 协议。随后,数据被发布至代理服务器。与此同时,两台 Raspberry Pi 将测得的温度和照度发布至同一代理服务器。此后,互联网上的任何设备均可订阅该数据,并对其进行监控与记录,如图所示。 图1本研究中的方案展示了整个操作流程的具体实施方法。

访问受限。请登录或开始试用以查看此内容。

方案

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

1. Broker installation

NOTE: To monitor and record processing data via the Internet, a computer system that relays the data should be prepared. The system should be accessible from both the publishers and the subscribers as shown in Figure 2. Thus, it needs to have a public IP address that is known prior to any communication. An open MQTT broker called Eclipse Mosquitto is installed on the system13.

  1. Connect a computer to the Internet giving a public IP address. Give the address in the IP setting of the operating system.
  2. Install a broker software such as Eclipse Mosquitto on the computer. Download the installation file using a browser and execute it.
  3. Test the broker with a test program such as MQTT Lens. Download MQTT Lens using a browser and install it. Then, ensure published messages are subscribed.

2. Main publisher preparation

NOTE: This computer publishes the machine data via MQTT over TCP to the broker. Legacy data should be interpreted and repackaged to be sent out.This can be usually done by RS485 or Ethernet. The connection at the hardware level should be verified depending on the bus type. The extrusion machine sends out the data via Modbus through an Ethernet port.

  1. Physically place a computer in the machine site and set it up as the main publisher.
    NOTE: Although not obligatory, an industrial computer was selected in this work.
  2. Install Python3 on the computer. Download the installer file using a browser and execute it.
  3. Install PyModbus16. Download the installer file using a browser and execute it.
  4. Examine the extrusion controller with HMI controlling the machine and connect the extrusion controller to the main publisher.
  5. Fully identify the data and the corresponding address in the Modbus protocol from the machine using a Modbus tool such as ModbusPoll or QModMaster. Ensure the sent machine data are shown in the corresponding cells of the Modbus tool.
  6. Write a Python code on the publisher PC that retrieves the data from the extrusion controller.
    NOTE: Here is a code example:
    from pyModbusTCP.client import ModbusClient
    client = ModbusClient(host="192.168.1.***", port=***, unit_id=***)
    client.open()
    ExtrusionData = str(client.read_holding_registers(1000, 58))
  7. Merge additional data streams from other devices via PCIe, USB, RS232, and RS485.
    NOTE: This is straightforward. Once an additional data string is obtained, simply add the data to the existing data stream, which is done by the following code:
    ExtrusionData += AdditionalData
  8. Import the paho.mqtt.client after installing paho-mqtt by pip install paho-mqtt17.
  9. Implement the code to connect and publish data to the broker.
    NOTE: Refer to the following code example:
    url="117.xx.xxx.xx"; port = 1883; username = "****"; password = "xxxxx"; topic = "Extruder"
    mqttc = mqtt.Client()
    mqttc.username_pw_set(username,password)
    mqttc.connect(host=url, port=port)
    mqttc.loop_start()
    ExtrusionData = str(client.read_holding_registers(1000, 58))
    Pub1= mqttc.publish(topic, ExtrusionData))
    Pub1.wait_for_publish()

3. Additional publisher preparation

NOTE: This computer also publishes the machine data via MQTT over TCP to the broker. Sometimes, additional measurement that cannot be done on the main publisher is required. Internet of Things (IoT) devices such as Raspberry Pi and Arduino can take the role. In this work, Raspberry Pi was employed for temperature data and illuminance data. The procedure is similar to protocol section 2.

  1. Place a Raspberry Pi near the sensor location.
    NOTE: Since the wiring distance is limited, the Raspberry Pi cannot be placed very far from the measurement location. However, as the vicinity of the extruder is very hot, the device needs to be placed at least 1 m away from the measurement location.
  2. Install Python3 on the Raspberry Pi by the following commands in the command line:
    sudo apt update
    sudo apt install Python3 idle3
  3. Implement the code to acquire the sensor data. The sensor data can be transmitted via I2C or GPIO.
    NOTE: Refer to the following code example for additional temperature data via GPIO:
    from max6675 import MAX6675
    cs_pin1 = 24; clock_pin1 = 25; data_pin1 = 18
    cs_pin2 = 9; clock_pin2 = 11; data_pin2 = 19
    units = "C"
    thermocouple1 = MAX6675(cs_pin1, clock_pin1, data_pin1, units)
    thermocouple2 = MAX6675(cs_pin2, clock_pin2, data_pin2, units)
    T1 = thermocouple1.get()
    T2 = thermocouple2.get()
  4. Import paho.mqtt.client.
  5. Reuse the code in section 2 to connect and publish data to the broker.

4. Subscriber's setup

NOTE: Any devices on Internet may receive the processing data via the broker. The data is processed and visualized also by a Python code. In case the development is difficult, available applications such as MQTT Client in Google Play and MQT Tool in the App Store can be employed. Since the implementation of the user interface is quite lengthy, the details are not described here. Also note that existing applications such as MQT Tool in App Store can receive the data.

  1. Engage a device for subscription to the Internet. Ensure a physical cable connection and then execute a ping to the broker IP on the command line (e.g., ping 117.xx.xxx.xx).
  2. Install a suitable Python environment depending on the device and the OS. For example, install Pydroid3 on an android device instead of Python3 from the Google Play.
  3. Import both paho.mqtt.client and paho.mqtt.subscribe to connect to and receive data from the broker.
    NOTE: Refer to the following code example:
    import paho.mqtt.client as mqtt
    import paho.mqtt.subscribe as subscribe
    url="117.xx.xxx.xx"; port = 1883; username = "****"; password = "xxxxx"; topic = "Extruder"
    mqttc.username_pw_set(username, password)
    mqttc.connect(host=url, port=port)
    mqttc.subscribe(topic, 0)
    mqttc.loop_start()
    Sub1 = subscribe.simple(topic, hostname=url)
    ExtruderData = Sub1.payload.decode("utf-8")
  4. Build a user interface as required using PyQT5.
    NOTE: This part is very lengthy and focuses on graphical representation of the received data rather than communication. The corresponding code is provided as supplementary data.
  5. Display the incoming data on the GUI by executing the built code.

5. Data logging

NOTE: The processing data can be written in a database while monitoring. In this work, a lab-scale database was chosen. The data are connected onto a Microsoft Access file to easily write and retrieve from a user computer. In addition, a table can be instantly built by a query to analyze data in a spreadsheet such as Microsoft Excel.

  1. Select a subscriber device to record the data.
  2. Import pyodbc by executing "pip install pyodbc" on the command line for the Python code to access the database as shown in Figure 318.
  3. Send a query to the database by the Python code for recording the processing data. Refer to the Python code in Figure 3 for the method.
  4. Send a query to the database for retrieval of the recorded data.
    NOTE: A code example for data retrieval is given below:
    import pyodbc
    x for x in pyodbc.drivers() if x.startswith('Microsoft Access Driver')]
    conn_str = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=C:\Users\data_analysis\db1.accdb;'
    )
    cnxn = pyodbc.connect(conn_str)
    crsr = cnxn.cursor()
    for table_info in crsr.tables(tableType='TABLE'):
    print(table_info.table_name)
    sql = """\
    SELECT * FROM Process_Condition
    """
    crsr = cnxn.execute(sql)
    for row in crsr:
    RetrievedData = pd.read_sql(sql, cnxn)
    crsr.close()
    cnxn.close()

6. Deployment

NOTE: If all the devices can be connected to the Internet, the setup is simple. However, to secure the machine side data, the publishers can be in the intranet only. In this case, the broker can be a gateway to the Internet. To be so, the broker should be equipped with two ethernet adaptors, one of which must have a public IP address. After all the items are developed, the codes should be deployed onto each device as shown in Figure 4. The mode of connection, wired or wireless, is not important, but it has to be secured so that each device should be able to access the broker. This means the broker can act as a gateway on the border between the intranet and the Internet for security purposes. Of course, even if all the devices are exposed to the Internet, there is no problem from a communication point of view.

  1. Connect the extrusion controller, the main publisher, and the additional publishers to the Intranet port via ethernet.
  2. Connect one ethernet port of the broker to the intranet and the other to the Internet.
  3. Connect subscribers to the Internet by repeating step 4.1 for all of them.

7. Execution

NOTE: To test the whole system, we started the extrusion line and ran all the Python codes and Mosquitto.

  1. Start the extrusion process. On the HMI of the machine, set the temperatures and turn on the heater by touching the button on the HMI screen. Once the required temperature is reached, start the screw rotation to extrude the polymer melt.
  2. Turn on all the computers, start the broker software on the broker device by the command "net start mosquitto", and then run the Python codes to monitor and record the processing data as needed.
    NOTE: The order of step 7.1 and step 7.2 can be reversed. The Python codes can be executed simply by typing "python3 xxxxx.py" on the command line followed by pressing Enter. Add this command to the start-up programs to avoid typing the command every time the device reboots.

访问受限。请登录或开始试用以查看此内容。

结果

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

研究发现,HMI 上显示的数据以及由树莓派测量的数据已在订阅者端被监控和记录,如图5所示。如视频中所示,处理后的数据已记录到数据库中。

使用代理、发布者、树莓派和传感器构建的用于数据通信系统的MQTT网络示意图
图1:使用MQTT协议进行数据传输的示意图。 代理负责将消息从发布者转发给订阅者。本图中的发布者包括主发布者和附加发布者(树莓派)。主发布者直接连接至挤出机以接收数据。只要网络容量允许,订阅者的数量不受限制。订阅者可将数据重新发布给其他订阅者,以便将其记录到数据库中,例如 Microsoft ...

访问受限。请登录或开始试用以查看此内容。

讨论

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

通过遵循本方案,无需使用制造执行系统(MES)等昂贵的IT解决方案,即可对加工数据进行监控和记录。物联网(IoT)技术可更便捷地从传统设备中获取并传输数据。研究表明,基于消息的协议MQTT可成功作为聚合物加工生产线数据通信的平台。此外,其他附加数据也可灵活地同步测量和传输。本研究中使用的附加发布者为树莓派(Raspberry Pi)。值得注意的是,可通过将树莓派安装在工业级防护外壳中,进一步增强其在恶劣环境下的稳定运行能力。订阅者可以是任何位置、任何操作系统的任意设备。订阅设备可通过选择订阅主题,仅接收所需的数据。本研究证明,MQTT协议结合物联网设备能够简便地实现聚合物加工生产线的数据监控。现代工业通信架构正逐渐偏离普渡模型(Purdue model)等金字塔式结构,而本研究也表明这一发展趋势是合理的。

通过使用 Python 实现软件,该代码可被复用于多种平台19。因此,不同平台的设备均能够参与处理数据的发布与订阅。此外,通过导入多个预构建的代码库(如 PyModbus、pyodbc、paho.mqtt 和 PyQT5),可大幅减...

访问受限。请登录或开始试用以查看此内容。

披露

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

作者声明无利益冲突。

致谢

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

本研究由首尔科技大(首尔科学技术大学)资助的研究项目支持。

访问受限。请登录或开始试用以查看此内容。

材料

本文使用的材料清单
姓名公司目录编号评论
边缘设备AdavantechUNO 420Intel Atom E3815 无风扇
薄膜挤出机EM Korea不可用用于生产 450 mm 薄膜
PydroidIIEC不可用安卓设备
Python3Python 软件基金会不可用Windows, Linux
Raspberry Pi 4CanaKit不可用标准套件

参考文献

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,
  1. Shafiq, S. I., Szczerbicki, E., Sanin, C. Proposition of the methodology for Data Acquisition, Analysis and Visualization in support of Industry 4.0. Procedia Computer Science. 159, 1976-1985 (2019).
  2. Dilda, V., et al. Manufacturing: Analytics unleashes productivity and profitability. McKinsey & Company. , https://www.mckinsey.com/business-functions/operations/our-insights/manufacturing-analytics-unleashes-productivity-and-profitability (2017).
  3. Ismail, A., Truong, H. L., Kastner, W. Manufacturing process data analysis pipelines: A requirements analysis and survey. Journal of Big Data. 6, 1(2019).
  4. Nwanya, S. C., Udofia, J. I., Ajayi, O. O. Optimization of machine downtime in the plastic manufacturing. Cogent Engineering. 4 (1), 1335444(2017).
  5. Zhou, T., Song, Z., Sundmacher, K. Big data creates new opportunities for materials research: A review on methods and applications of machine learning for materials design. Engineering. 5 (6), 1017-1026 (2019).
  6. Rousopoulou, V., Nizamis, A., Thanasis, V., Ioannidis, D., Tzovaras, D. Predictive maintenance for injection molding machines enabled by cognitive analytics for Industry 4.0. Frontiers in Artificial Intelligence. 3, 578152(2020).
  7. Mamo, F. T., Sikora, A., Rathfelder, C. Legacy to Industry 4.0: A Profibus Sniffer. Journal of Physics: Conference Series. 870, 012002(2017).
  8. Figueroa-Lorenzo, S., Añorga, J., Arrizabalaga, S. A role-based access control model in Modbus SCADA systems. A centralized model approach. Sensors. 19 (20), 4455(2019).
  9. Schleipen, M., Gilani, S. -S., Bischoff, T., Pfrommer, J. OPC UA & Industrie 4.0 - Enabling technology with high diversity and variability. Procedia CIRP. 57, 315-320 (2016).
  10. Nițulescu, I. -V., Korodi, A. Supervisory control and data Acquisition approach in node-RED: Application and discussions. IoT. 1, 76-91 (2020).
  11. Perez-Lopez, E. SCADA systems in the industrial automation. Tecnología en Marcha. 28 (4), 3-14 (2015).
  12. Andersen, D. L., Ashbrook, C. S. A., Karlborg, N. B. Significance of big data analytics and the internet of things (IoT) aspects in industrial development, governance and sustainability. International Journal of Intelligent Networks. 1, 107-111 (2020).
  13. Kashyap, M., Sharma, V., Gupta, N. Taking MQTT and NodeMcu to IOT: Communication in Internet of Things. Procedia Computer Science. 132, 1611-1618 (2018).
  14. Connet, J. Mythbusting the MES. Systema. , Available from: https://www.systema.com/blog/mythbusting-the-mes (2021).
  15. Yeh, C. -S., Chen, S. -L., Li, I. -C. Implementation of MQTT protocol based network architecture for smart factory. Proceedings of the Institution of Mechanical Engineers, Part B: Journal of Engineering Manufacture. 235 (13), 2132-2142 (2021).
  16. Parian, C., Guldimann, T., Bhatia, S. Fooling the master: Exploiting weaknesses in the Modbus protocol. Procedia Computer Science. 171, 2453-2458 (2020).
  17. Mishra, B., Kertesz, A. The use of MQTT in M2M and IoT systems: A survey. IEEE Access. 8, 201071-201086 (2020).
  18. pyodbc 4.0.34. , Available from: https://pypi.org/project/pyodbc/ (2021).
  19. Ayer, V., Miguez, S., Toby, B. Why scientists should learn to program in Python. Powder Diffraction. 29 (2), 48-64 (2014).
  20. Boyes, H., Hallaq, B., Cunningham, J., Watson, T. The industrial internet of things (IIoT): An analysis framework. Computers in Industry. 101, 1-12 (2018).

访问受限。请登录或开始试用以查看此内容。

重印与许可

申请许可以重复使用本 JoVE 文章的文本或图表

申请许可

标签

MQTT Python Modbus

相关文章