## 3 Materials and Methods
### Advanced MES for Hybrid and Multi-Level Integration  
SMEs that wish to implement advanced technologies face different significant challenges. In this context, the research proposes to address the integration of advanced technologies, the use of low-cost control units and internal reorganization to adapt to the new productive dynamics. In this context, it is proposed to develop a solution that addresses these issues, converging in the same control unit, concepts, methodologies and operations for parallel and concurrent work in a multi-level scenario.  
Figure 3 shows the MES architecture implemented on a Raspberry Pi 4 B development board, with a 1.5 GHz quad-core processor, 4 GB RAM and 802.11 ac Wi-Fi. This implemented structure demonstrates that the MES can be deployed at different hierarchy levels, giving it flexibility to manage process overloads in the plant while ensuring interoperability between the plant and cloud endpoints. In this context, the key features that this architecture offers for intelligent manufacturing management are described below: (a) It constantly ensures the connection to the cloud. (b) It enables bidirectional information flow with the cloud service infrastructure via Node-RED as a client and an MQTT (mosquito) broker. (c) It has a local database, which, via MySQL, allows recording order requests as a backup in case of internet service provider (QoS) failure. It also manages the information table that synchronizes stations (D) and (E), responsible for dispatching requests, and stations (A, B, C, and D), responsible for replenishing parts. For this, it uses as key data the position of the parts for dispatch and their color for replenishment (see Figure 4). (d) It establishes a bidirectional communication with the ESP32 master located at station (D), which notifies it every time a part is removed, updating the information tables. This allows the local database to efficiently organize the replenishment process for each dispatched part.  
In Figure 3, the hierarchy levels at which the MES can operate are presented in different shades, highlighting how the AI and FCM processes run on different instances of the same processor. The first process, together with the other top-level tasks described in the previous paragraph, are managed on one instance, while the second process is executed on the remaining instance of the same board, allowing for an efficient distribution of resources.  
Figure 3: Modular microcomputer architecture for multi-level management, integrating plant data, local storage and cloud services.  
3.3.1. Stock Management and AI in the Production Process  
The token replenishment process at station (D) is performed in such a way that each warehouse rack is matched with a characteristic color of the piece. On the other hand, each time the dispatch process is completed, an image of the current situation of the warehouse is automatically captured by means of a 720p HD webcam for the execution of an object detection model in real time using YOLO v5 convolutional neural networks (CNNs), and then a segmentation algorithm is applied to precisely delimit the space corresponding to each detected piece and thus know its position within a matrix that is generated in the image (see Figure 4). These data are sent to a web server where this information is stored and managed, so that a user can see in real time the number of pieces per color that the manufacturing company has in stock. Meanwhile, in the plant, the MES manages the process of replenishment of cards, and at the same time, another user can place a new order, in which case the MES automatically downloads a vector template of the requested order, which indicates the position of the piece that corresponds within the matrix and consequently its color, thus maintaining a continuous and orderly flow of processes and synchronizing the replenishment and dispatch of colored pieces.