## 4 Proposed MCA-IoT Design
### MCA-IoT Supervisory Software Development Phases and Implementation
The proposed software adapts to scalable network conditions caused by SN out-of-service faults and variations in SN count or network size. The CH software utilizes modules such as Bocket, Bluetooth, sys, threading, time, csv, Queue, struct, ntplib, gspread SCL, and SDA from board, busio, and seesaw from \(ada fruit\_seesaw\_seesaw\). * Similarly, the BS software also contains the Bluetooth socket server script in Python 3.7 for managing network construction, reception and storage of event data, BLE transceiver operational state moderations, and transmission of received sampled data to the cloud at specific timeslots. This part of the software running on the BS uses Bluepy, BlueZ, and APIs to communicate with edge CHs via the BLE module at scheduled times to receive and store sampled data locally in a csv file. Additionally, this software incorporates LoRa communication technology to transmit the received farm data to the TTN cloud for remote monitoring. The LoRa communication technology was configured to have a transmitter power output of 14 dBm, a spread factor of 7, a bandwidth of 125 kHz, and a coding rate of 4/5. The BS further processes the received data, and if the result exceeds a preset threshold, an actuation signal is sent to the pump to start the irrigation system. This software also accounts for SN out-of-service faults from the CHs by indicating the MN and CH counts of the received aggregated data. The main modules imported into the BS software include socket, Bluetooth, sys, threading, time, csv, Queue, struct, ntplib, and gspread, whereas the MN relies on Bluetooth, time, SCL, and SDA from board, busio, and seesaw from adafruit\_seesaw.seesaw. The sensory data are the main parameters transmitted at the crondab-scheduled timeslot to the BS and TTN cloud at 3-h intervals to reduce data noise while capturing significant changes in soil parameters. Figure 12: Flowcharts of event-routing operational cycle of software running on intra-cluster and inter-cluster/multihop spaces using MN, CH, RCH/edge CH, and BS devices. ```
1:\(n\geq 0\)
2:\(y=x^{n}\)
3:Each MN in the cluster samples or senses data during the scheduled sensing period. 4:Each MN sends its data to the selected or dedicated CH in that sensing cluster. 5:The CH polls the received data and checks if all the member nodes have sent their data. 6:The CH adds/aggregates received MNs into one. 7:\(\textbf{Aggregate\_Data}=\sum_{i=1}^{N}\textbf{Node\_Data}_{i}\triangleright\) Where \(N\) is the total number of member nodes
8:The CH checks for redundancy in the aggregated data to avoid false positives. 9:The CH represents the sensing cluster's area measurement in the aggregated data. 10:\(y\gets 1\)
11:\(X\gets x\)
12:\(N\gets n\)
13:while\(N\
eq 0\)do
14:if\(N\) is even then
15:\(X\gets X\times X\)
16:\(N\leftarrow\frac{N}{2}\)\(\triangleright\) This is a comment
17:elseif\(N\) is odd then
18:\(y\gets y\times X\)
19:\(N\gets N-1\)
20:endif
21:endwhile
```  
**Algorithm 1** Data aggregation in the sensor network  
The BS processes aggregated data in _csv format and appends a copy to the TTN cloud at scheduled intervals using LoRa communication technology. To assess the efficacy of the proposed system, it was tested under various environmental conditions, both indoors and outdoors. Modifications were made to the architecture during each deployment, and performance impacts were monitored and analyzed using MATLAB R2022b, OriginStudio 2022, and WebplotDigitizer version5. A total of four clusters, each comprising four MNs, were tested. The assembly of network components and circuitry for a cluster is shown in Figure 10, with indoor and  
Figure 13: Evidence of implementation of fail-over mechanism. outdoor testbed setups illustrated in Figure 14a,b. Compared to existing Agri-IoT solutions, the MCA-IoT system offers easier deployment and management, is more cost-effective, energy-efficient, simpler, fault-tolerant, and less location-dependent than the state-of-the-art solutions shown in Figure 2b.