Analysis of Real-Time Streams at the Industrial IoT Edge
In certain scenarios, data needs to be analyzed and processed near where data is generated when a large amount of data is generated on edge devices, which reduces the amount of data to be migrated to the cloud and improves real-time data processing. IEF can work with the Cloud Stream Service (CS). By deploying the stream computing applications on edge nodes, IEF extends the real-time stream computing capability from the cloud to the edge. Then, CS edits and delivers stream processing jobs to edge nodes. In this way, stream data can be quickly and accurately analyzed and processed at the edge.
Prerequisites
- IEF and CS have been enabled.
- An edge node has been registered and managed.
Deploying an Application
- Log in to the IEF console. In the navigation pane on the left, choose Edge Marketplace > Edge Application Center, and click Deploy on the Edge Flink card. On the page displayed, associate an edge node and specify parameters. The parameter values cannot be smaller than their default values. Otherwise, the deployment will fail.
- Log in to the CS console (https://console.huaweicloud.com/cs/?locale=en-us#/dashboard). In the navigation pane, choose Job Management.

- Click Create Job. The Create Job page is displayed.

- Set Type to Flink Streaming SQL Edge Job and enter the job name. The Description, Template, and Labels field are optional. A job can be quickly created if you use an existing template.
- Click OK. The Edit page is displayed.

- Edit the Flink streaming SQL edge job as required to process data generated on edge devices. Currently, type can be set to edgehub and encode can be set to json or csv. For details about the SQL syntax, see Syntax Constraints.
Example: Exporting the names and scores of students who scored 80 or higher
create source stream student_scores(name string, score int) with ( type = "edgehub", topic = "abc", encode = "json", json_config = "score = student.score; name=student.name" ); create sink stream excellent_students(name string, score int) with ( type = "edgehub", topic = "abcd", encode = "csv", field_delimiter = "," ); insert into excellent_students select name, score from student_scores where score >= 80;
- On the right of the page, set Parallelism and Edge Node. Parallelism specifies the number of tasks where CS jobs can simultaneously run, and Edge Node specifies the edge node to which the job belongs. You can select multiple edge nodes to deploy the job.

- Click Submit. On the displayed Job Configuration List page, click OK to submit and start the job. You can view the job running status on the Job Management page and click a specific job to view the job details, job monitoring information, and job execution plans.

Verifying Job Running
- Log in to a node that interwork with edge nodes. Then, install Mosquitto. Mosquitto implements the communication among the algorithm, container, and MQTT Broker.
- Install Mosquitto.
- In the Ubuntu OS, run the following commands to install Mosquitto:
apt-get install mosquitto systemctl start mosquitto systemctl enable mosquitto
- In the CentOS OS, run the following commands to install Mosquitto:
yum install epel-release yum install mosquitto systemctl start mosquitto systemctl enable mosquitto
For more information about Mosquitto installation, visit the Mosquitto official website https://mosquitto.org/download/.
- In the Ubuntu OS, run the following commands to install Mosquitto:
- Configure Mosquitto.
- If a firewall is deployed, add a firewall filtering rule.
firewall-cmd --add-port=1883/tcp --permanent firewall-cmd --add-port=8883/tcp --permanent systemctl restart firewalld
- Run the following command to query the directory where the Mosquitto configuration file is located:
ps aux | grep mosquitto
The directory of the Mosquitto configuration file is shown in the following figure:

- Run the vim command to open the configuration file.
vim Directory of the Mosquitto configuration file (for example, vim /etc/mosquitto/mosquitto.conf)
- By default, Mosquitto listens on port 1883 of the whole network segment. Add the following lines at the end of the configuration file to limit the IP addresses on which Mosquitto listens:
bind_address 172.17.0.1 listener 1883 127.0.0.1
- Query the directory of the Mosquitto startup file and modify the file for the init.d and systemd systems. The file directory is shown in the following figure:
systemctl status mosquitto
Figure 2 Directory for storing the Mosquitto startup file
- For the init.d system, run the following command to open the Mosquitto startup file:
vim /etc/init.d/mosquitto
Add docker after # Required-Start: $remote_fs $syslog.Figure 3 Modifying the Mosquitto startup file for the init.d system
- For the systemd system, run the following command to open the Mosquitto startup file:
vim /usr/lib/systemd/system/mosquitto.service
Add the Docker startup dependency by adding docker.service after After=network-online.target.Figure 4 Adding the Docker startup dependency
- For the init.d system, run the following command to open the Mosquitto startup file:
- Restart Mosquitto.
systemctl daemon-reload systemctl restart mosquitto
- Check whether Mosquitto is started.
systemctl status mosquitto
If active (running) is displayed in the command output, Mosquitto is running properly.
For more information about Mosquitto configuration, visit the Mosquitto official website https://mosquitto.org/.
- If a firewall is deployed, add a firewall filtering rule.
- Install Mosquitto.
- Run the following command to subscribe to data:
mosquitto_sub -h 127.0.0.1 -t abcd
In the command, abcd is the topic name defined in the job.
- Open a new window, and run the following command to publish data:
mosquitto_pub -h 127.0.0.1 -t abc -m '{"student":{"score":90,"name":"1bc2"}}'
In the command, abcd is the topic name defined in the job.
After data is published, the data subscribed to in 2 can be received.
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.