## 3 Measurement, Control, and Communication Architecture
### Software and Communication
#### 3.2.3. Supervisory Control and Monitoring Layer: MATLAB(r) App  
The MATLAB(r) app acts as the graphical user interface (GUI) for monitoring the SWT system in real time. Developed using MATLAB(r) App Designer, it provides a unified platform for visualizing operational data and sending control commands remotely.  
Although MATLAB(r) was used in this study due to its availability at the authors' institution and its ease of development, the communication platform presented in this work is fully compatible with open-source alternatives such as GNU Octave [42].  
Upon initialization, the application establishes two persistent WebSocket connections with the Raspberry Pi(r):  
* One to receive real-time measurement data (port 8081);
* Another to send control commands (port 8080).  
These connections are created using a MATLAB(r)'s WebSocket library [43], enabling full-duplex communication between the app and the embedded system. Incoming messages are handled via event-driven callbacks that decode the data and update the graphical elements of the interface, such as gauges, indicators, and dynamic plots displaying wind speed, generator voltage, current, and power output.  
User actions--such as selecting control modes, toggling MPPT strategies, or adjusting voltage setpoints--are processed by the app and sent as ASCII-encoded commands over the control WebSocket. The Raspberry Pi(r) then forwards these to the Arduino(r) for immediate actuation via UART.  
To ensure robustness, the app continuously monitors connection status. In case of brief disconnections (e.g., network issues or system restarts), the app attempts automatic reconnection to restore communication without user intervention. This behavior provides resilience and responsiveness, essential for experimental and supervisory control environments.  
Figure 5 shows the current user interface of the MATLAB(r) app, designed specifically for the remote monitoring and control of the SWT platform.  
The internal communication logic of the app is outlined in Algorithm 2, which summarizes the WebSocket-based data and command flow used in the application.  
Figure 5: Designed app to monitor and control the SWT.  
```
InitializeWebSocketconnectiontotheRaspberryPiatIP\"XXX.XX.X.XXX\"withport8081 for receivingdatafromtheDC-DCconverter. InitializeWebSocketconnectiontotheRaspberryPiatIP\"XXX.XX.X.XXX\"withport8080 for sendingcontrolcommandstotheconverter. PeriodicallycheckforincomingdatafromtheconverterviaWebSocket: -Ifdataisreceived: -Parsetheincomingdataframetoidentifyandextractkeyparameters. -Convertrawsensordataintphysicalunitsusingpredefinedscalingfactors. -Updatetheappwithreal-timevalues:power,current,temperature,voltage,andwind speed. Onusercommand,sendcontrolsignalstotheconverterviaWebSocket: -Switchtheoperatingmode(MPPTorPowerCurtailment)andsendcorrespondingcontrolcommands. -IfPowerCurtailmentisselected,sendpowerreservesettingstotheconverter. Ensureperiodicupdateofoperationalparametersandmaintaincommunicationintegritybetweenthesystemandtheconverterbycontinuouslyprocessingdataeveryfewseconds.
```  
**Algorithm 2**Pseudocode--MATLAB(r) App WebSocket Communication Logic