## 3 Proposed Method
### Algorithms for Sensor Nodes  
Detailed implementation of the above-discussed CH rotation rule is presented in form of algorithms executed by sensor nodes. The smart sensor nodes in WSN execute the operations presented by the pseudo codes in Algorithms 1-4. The operations are repeated in regular time intervals (steps). During normal operation the non-CH node (cluster member) reads data from its sensors, detects events based on the collected sensor readings and, if an important event is detected, transmits the detection results to CH node (see Algorithm 1). For energy saving, the sensor node wakes its communication module up only when the data transmission is necessary. In case when the initial energy of sensor nodes is not known in advance, the cluster member can include information about its residual energy in the first data frame, which is send after selection of new CH. As shown in Algorithm 2, the normal operation of CH node consists of collecting sensor readings, detecting events, aggregating results received from cluster members, and sending the aggregated results of event detection to sink. Once the last step of the normal operation period is finished, all sensor nodes in WSN switch to executing the CH selection algorithm (Algorithm 3). According to the proposed CH selection approach, a new CH node is selected if the current CH node performs this role not shorter than the time \(TCH_{i}\), which is calculated using the method presented in Section (see line 4 in Algorithm 3). This approach requires the probabilities of event occurrence (\(p_{i}\)) to be evaluated for all sensor nodes in the cluster. To this end the CH node holds an event counter that indicates how many times given sensor node has reported an event. The probability \(p_{i}\) is estimated as a quotient of the value recorded in event counter divided by the duty time. It should be noted that the variable called duty time in Algorithms 2 and 3 informs how long the current CH fulfils the CH role. If the aforementioned condition of CH change is satisfied then the next sensor node from a predetermined sequence is selected to act as CH. The sequence is established during initialization of the WSN and corresponds to the order in which the sensor nodes have joined the cluster. In case when the CH change condition is not met, the current CH node stays in its role. For large clusters with many sensor nodes, the computations of \(TCH_{i}\) that require solving the system of linear equations (4), can lead to significant energy expenditure and computation time, when performed by the CH node with limited resources. Thus, an optional procedure was proposed where the system of equations is solved by the sink (base station), which is powered from the mains and has greater computational power than CH node. According to this procedure the CH node sends a request to the sink with estimated probabilities of event occurrence (\(p_{i}\)) and receives the \(TCH_{i}\) time. It should be also noted that the equation system can be effectively solved by using artificial neural networks [32] or approximate algorithms [33]. Moreover, an approximate solution is sufficient for the proposed CH rotation method, as the \(TCH_{i}\) time must be determined with precision that corresponds to the time interval between two successive CH selections. At the time of CH selection procedure, the cluster members listen to sync frame, which is broadcasted by the CH node. The sync frame includes address of the new selected CH. If a cluster member receives the sync frame with CH address equal to its own address then it switches to act as CH node. Another basic function of the sync frame is time synchronization of all nodes in the cluster. The sensor nodes are synchronized by resetting their timers on reception of the sync frame.