## 3 Materials and Methods
#### Wireless Sensor Network Installed
Figure 4: The implementation of the wireless sensor network. Figure 3: A block diagram summarizing the WSN Development Kit, including network structure, communication protocols, hardware specifications, and power supply options. The algorithm that governs this system operates in tandem with a central coordinator node. When the network is activated, the coordinator sends out packets to map the network's topology. Each node is assigned a hierarchy level based on its sensor readings and RSSI and LQI values, which are indicators of link quality. These nodes take measurements according to a predefined schedule. If the difference between a node's current reading and its default value exceeds 50%, the node's hierarchy level increases, signaling that the parameter being monitored is highly variable and requires close attention. If the node's hierarchy surpasses a certain threshold, and its RSSI and LQI values are significantly higher than normal, the node switches to a proactive mode, ensuring that it monitors its environment continuously. If the conditions are stable, the node operates in a reactive mode, which conserves energy by only taking measurements as needed. This allows the network to adapt dynamically to each home environment. ```
Algorithmpsudocodeofthestnetworksystem. Start://TurnONallnodes Turn_ON_AllNodes() //Setrequest.time request_time=Set_Request_Time() //Coordinatornodesstarts Coordinator_Node_Starts() //Foreachnodeinthemetwork FOReachnode_iINnodes://Initializevariables hierarchy_i=0 default_measurement_i=Set_Default_Measurement() LQI_Initial=Set_LQI_Initial() RSSI_initial=Set_RSSI_Initial() //Foreachrequest.time FOReachrequest_timeINrequest_times://Setmeasurementmeasurement_i=Set_Measurement() //Calculatedifferenceinmeasurement_i=ABS(default_measurement_i-measurement_i) //Checkifthedifferenceinmeasurementissignificant IFd_measurement_i>0.05*default_measurement_iTHEN: hierarchy_i+hierarchy_i+1 //Checkconditionsforproactivemode IFhierarchy_i>3 ANDABS(LQI_initial-LQI_i)>0.05*LQI_iAND ABS(RSSSI_initial-RSSSI_i)>0.05*RSSSI_iTHEN: Set_Node_Proactive_Node(node_i) ELSE: Set_Node_Reactive_Node(node_i) //Esterncrby-basedrecommendations IFhierarchy_i==3 THEN: Send_Recommendations(Group_1) ELSEIFhierarchy_i>2 THEN: Send_Recommendations(Group_2) ELSEIFhierarchy_i>=1 THEN: Send_Recommendations(Group_3) ELSE: No_Recommendations() End
```  
Nodes, which may contain multiple sensors, generally maintain stable RSSI and LQI values unless influenced by other devices or changes in the environment. These fluctuations can indicate unusual conditions that the system uses to generate recommendations. The sensor system is standardized for general use but adapts its operations, energy consumption, and recommendations to suit individual households. The recommendations for improving sleep are categorized into three groups:1. Environment Optimization: Suggestions include closing windows to reduce noise, using comfortable bedding, employing noise machines or earplugs, maintaining a cool room temperature, using a humidifier for better air quality, keeping the room dark with blackout curtains, and minimizing electronic devices in the bedroom. 2. Pre-Sleep Relaxation: Recommendations focus on relaxation techniques before bed, maintaining a consistent sleep schedule, using a weighted blanket, experimenting with aromatherapy, avoiding caffeine and heavy meals before sleep, utilizing a white noise machine, and trying a sleep mask. 3. Sleep Habit Development: Tips include establishing a regular bedtime routine, engaging in regular exercise but not close to bedtime, avoiding exposure to blue light before sleep, considering sleep aids if necessary, avoiding daytime maps, experimenting with natural sleep remedies like melatonin, and ensuring that the bed is comfortable and supportive. In this study, the wireless sensor network was configured to monitor vital signs and environmental factors within the homes of elderly participants, with sensors deployed in key areas, such as bedrooms and living spaces.