# Low-Cost Digitalization Solution through Scalable IIoT Prototypes
## 4 Case Study
### The Retrofitting Solution Development  
The broaching machine was controlled using a simple electrical circuit, including non-intelligent components such as relays and contacts. The electrical cabinet was updated by adding and embedding the Zerynth 4 ZeroBox [65] as an IIoT edge device. The 4 ZeroBox was mounted on the DIN-35 rail and powered by a 24 VDC power supply unit that had already been present in the electrical cabinet. The IIoT-enabled electrical cabinet of the broaching machine is shown in Figure 4. Then, in order to evaluate the performance and the efficiency of the broaching tool, the existing analog manometer was replaced with a digital pressure transmitter, WIKA S-20 (measuring range 0-250 bar). The piston movement signals are transmitted to the digital input-output pins of the 4 ZeroBox using the reserve contacts of the R1 and R2 relays. The 4 ZeroBox was wirelessly connected to the internet through an internal Wi-Fi network in the factory.  
A software algorithm was developed, and the 4 ZeroBox was programmed, using Python programming language. The software utilized for programming is Visual Studio Code; more precisely, the Zerynth expansion. The Zerynth Visual Studio Code expansion uses the Zerynth Software Development Kit (SDK) to program and manage the 4 ZeroBox. The connection to the hardware was established, and the 4 ZeroBox was connected to the Zerynth Cloud through Zerynth Device Manager (ZDM) [71]. The communication between the 4 ZeroBox and the Zerynth Cloud is implemented through an MQTT protocol.  
The firmware was programmed in Python programming language with the libraries from Zerynth SDK. The multi-threaded structure was utilized with one main thread and one thread used for data gathering, the acquisition thread. The acquisition thread has only one task, sampling the digital pressure transmitter every 20 ms and storing the data in the queue. A data frame is created by storing every sample with the UNIX timestamp. An accurate timestamp was obtained by the process of synchronization of the 4 ZeroBox to the ZDM. The acquisition thread starts asynchronously after detecting the press of any of the buttons on the remote control. A button press is detected as the change of the logical level on the digital input pins of the 4 ZeroBox. Furthermore, any press of the button is registered as an event and stored in the queue, along with the UNIX timestamp.  
The main thread is tasked with initialization, establishing the connection and synchronization to the ZDM, and data storage and publishing to the ZDM, as well as the control of the acquisition thread. After detecting data in the queue, the main thread takes the data frame and stores it on the local SD card. All the data collected during one active period of the acquisition thread is stored on the SD card and treated as one cut of the tube. The cut signifies one piston extension and one retraction, as explained in Section 4.2. The main thread detects the block of the acquisition thread and starts sending the data from the SD card storage to the Zerynth Cloud storage.  
The data are sent to the Zerynth Cloud, where it is stored and handled by the ZDM. The communication between the device and the cloud is protected by the TLS v1.2 and v1.3 protocols based on private and public keys [67]. Every data frame is assigned the timestamp the data were received. The data are in the form of a JSON file. After the data are stored, it is possible to download it in a couple of ways: scheduling the periodic download or using REST API to retrieve the data from the Zerynth Cloud. After the data are downloaded, they can be analyzed. The entire system can be seen in Figure 5, while Figure 6 shows the overview of the entire process.  
Figure 4: IIoT-enabled electrical cabinet layout.