Designing and Implementing an IIoT System for Smart Factories
Karthik MuthineniKarthik Muthineni
Considering implementing an IIoT System for your factory? This article explains how to read data from Ultrasonic Ranger using Simatic IoT2040. Python acts as a communication bridge between Ranger and Simatic. The received data is then sent to NETPIE using​ NETPIE client library​ for Python.
This is a design and implementation of an #IIoT ecosystem for #SmartFactories, MODBUS sensors, @Siemens Simatic IoT2040 gateway and NETPIE.|| #IoTForAll #IoT #HowTo #DIY #Maker'
The Ultrasonic Ranger is used to detect the distance of the target object by transmitting a sound signal that reflects back to the transmitter after hitting the target. Ultrasonic sensors are used in a wide variety of applications both indoor and outdoor. The Ultrasonic sensor comes with 10 pins used for power supply and RS485 output signal as shown in Figure 1.
Data is read by sending frames of data to the module and then listening for the response. Each Ultrasonic Ranger has a unique 24-bit address written on the front side of the module as shown in Figure 2. The data frame you send to the SRF485WPR is shown in Figure 3.
For example, let us consider the frame that should be sent to the Ultrasonic Ranger is represented in Figure 5. Checksum is calculated for entire frame, excluding break as described below
Siemens Simatic IoT2040 works based on Yocto Linux that needs to be installed on an SD-card and should be inserted in Simatic. The Yocto Linux can be downloaded from the Siemens website. After downloading the image, insert the SD-card into the SD-card slot of the Linux computer and follow the instructions below.
sudo unzip Example_Image_V2.2.0.zip
df -h
unmount /dev/mmcblk0
sudo dd bs=1M if=name_of_image of=SD card_location
Simatic has two Ethernet ports named X1P1LAN and X2P1LAN. The first Ethernet port i.e. X1P1LAN has the default DHCP address 192.168.200.1. Using the Secure Shell (SSH), you can communicate with Simatic from your Linux computer. To achieve this, connect one end of the Ethernet cable to your computer and another end of the Ethernet cable to the X1P1LAN port of Simatic. Log in to the Simatic through the SSH.
For reading the data from the Ultrasonic Ranger using Simatic, Python is used. By default, Python is installed on Yocto Linux. Some Python libraries that have the capability of sending data frames serially need to be installed on Simatic. For this purpose, pip is used. Pip is a package management system used to install and manage Python libraries.
src iotdk-all http://iotdk.intel.com/repos/2.0/iotdk/all
src iotdk-i586 http://iotdk.intel.com/repos/2.0/iotdk/i586
src iotdk-quark http://iotdk.intel.com/repos/2.0/iotdk/quark
src iotdk-x86 http://iotdk.intel.com/repos/2.0/iotdk/x86
python get-pip.py
pip install pyserial
pip install microgear
pip install serial
With all the necessary libraries installed, we will now start to write a Python code that reads the data from the Ultrasonic Ranger. For this, create a Python file named ranger as described below
nano ranger.py
chmod +x ranger.py
./ ranger.py
NETPIE platform is a cloud-based platform-as-a-service that facilitates interconnecting IoT devices (“things”) together in a most seamless and transparent manner possible by pushing the complexity of connecting IoT devices from the hands of application developers or device manufacturers to the cloud. On NETPIE, create Application and generate device key. “board” ​is the Application ID created for this demonstration as shown in Figure 7.
Create Data Source as shown in Figure 8.
Here's the result:
The use of Siemens Simatic IoT2040 as a gateway device that receives data from SRF485WPR was discussed in this article. With Simatic IoT2040, handling the production data in industries has become more efficient, which opens paths towards the Industrial Internet-of-Things (IIoT) applications.
Originally published May 26, 2019. Updated January 29, 2020.
The Most Comprehensive IoT Newsletter for Enterprises
Showcasing the highest-quality content, resources, news, and insights from the world of the Internet of Things. Subscribe to remain informed and up-to-date.
New Podcast Episode
Related Articles