1. Application Devices
OT devices: Stepper motor, MODBUS TCP remote I/O module, PLC devices; Edge device: Hongji Industrial Raspberry Pi; IT devices: PC, Android phone; IT software: Hongji HiveMQ MQTT communication platform.
2. Principle
The Hongji Industrial Raspberry Pi collects data from the stepper motor, MODBUS TCP IO module, and PLC device using the MODBUS protocol, and performs some simple data processing. The Hongji HiveMQ configures the PC side as an MQTT Broker; the Industrial Raspberry Pi can transmit data to the PC side via the MQTT protocol; on the mobile side, operators can subscribe to the data topics from the PC side through a self-developed APP.
3. Actual Testing
1. Industrial Raspberry Pi Source Code
import threading
import time
from doctest import OutputChecker
from os import P_PID
from time import sleep
from threading import Thread
from tkinter import W
from myCtrlLib import *
import sys
import serial
import paho.mqtt.client as mqtt
import json
def on_connect(client, userdata, flags, rc):
print(f"Connected with result code {rc}")
client = mqtt.Client()
client.on_connect = on_connect
client.connect("192.168.1.168", 1883, 60)
# Read PLC data
def read_plc_data():
on_motor()
i = 0
j = 0
while True:
Weight = readFromName('Weight') # Read PLC weight data
Humidity = readFromName('Humidity') # Read PLC humidity data
Temperature = readFromName('Temperature') # Read PLC temperature data
Switch = readFromName('Switch_1') # Read photoelectric switch state
sleep(1)
Back_motor()
sleep(1)
Advance_motor() # Control motor based on switch state
if Switch == 1:
i = i + 1
if Weight > 500:
j = 1
else:
j = 0
# Construct JSON data
data = {
'Stepping_motor_speed': 300, # Motor speed
'Temperature': Temperature, # Temperature value
'Humidity': Humidity, # Humidity value
'Obj_weight': Weight, # Weight value
}
json_data = json.dumps(data)
client.publish('IndustrialProductionLin', payload=json_data, qos=0, retain=True)
print(i)
# Motor start
def on_motor():
writeToName('Motor', 1)
pass
# Motor forward
def Advance_motor():
writeToName('DIR', 0)
pass
# Motor reverse
def Back_motor():
writeToName('DIR', 1)
pass
# Motor stop
def stop_motor():
writeToName('Motor', 0)
pass
# Create and start thread
plc_thread = threading.Thread(target=read_plc_data) # Start thread
plc_thread.start() # Main thread waits for both threads to finish
plc_thread.join()
2. Results
4. Why Choose Hongji Industrial Raspberry Pi and Hongji HiveMQ Solution?
1. The Hongji Industrial Raspberry Pi integrates a variety of field bus protocols, and with the corresponding Python libraries, OT data collection can be achieved with simple configuration. For example, the MODBUS protocol used in this case can quickly realize OT data integration through PiCtory configuration and Python programming. 2. The Hongji Industrial Raspberry Pi currently supports up to 8GB RAM, with performance equivalent to a PC, capable of handling complex calculations and lightweight machine learning models. 3. The Hongji HiveMQ platform is an IoT solution based on MQTT communication, supporting quick configuration of MQTT Broker, high load, high concurrency, and high scalability. In practical applications, it ensures fast and stable data transmission without any data loss. Additionally, it supports enterprise-level expansion, such as integration with Kafka and enterprise-level information security management.