# Opportunistically Exploiting Internet of Things for Wireless Sensor Network Routing in Smart Cities
## 4 The Integration Platform
### Gossip Protocol  
By default the sensor remains in the Normal mode. Based on two factors, (1) number of replies from IoT devices and (2) number of received messages (IoTexists messages) from neighbors, IoT mode is turned On for 1 min. IoT exists messages are sent using gossip algorithm inspired from  
\begin{table}
\begin{tabular}{l c c c} \hline \hline
**Message** & **From** & **To** & **Description** \\ \hline send (helloloT) & SN & IoT & Message to search IoT in vicinity \\ \hline send (distance, speed) & IoT & SN & IoT reply message to SN \\ \hline send (selectedOK) & SN & IoT & SN confirms IoT as selected candidate \\ \hline send (OK) & IoT & SN & IoT reply OK to selection as approval to send \\  & & & data and waits for dataPacket. \\ \hline send (dataPacket, synchTime) & SN & IoT & SN sends dataPacket along with synchTime of WSN \\ \hline send (dataAck) & IoT & SN & Acknowledge message for data reception \\ \hline send (dropHello) & IoT & SN & Hello message to find SN to drop dataPacket to WSN layer. \\ \hline send (energy, RxSlot, location) & SN & IoT & Reply to dropHello message with SN’s energy level and location \\ \hline send (selectedOK) & IoT & SN & IoT confirms SN as selected SN for sending data \\ \hline send (OK) & SN & IoT & Reply OK to selection as approval to send dataPacket \\ \hline send (dataPacket) & IoT & SN & IoT drops datapacket to selected SN \\ \hline send (dataAck) & SN & IoT & Acknowledge message for data reception \\ \hline \hline \end{tabular}
\end{table}
Table 1: List of messages exchanged by elements of integration platform (IT) Platform.  
SIR gossip protocols [34]. The Gossip protocol algorithm is shown Algorithm 4. The push method is used by a Sensor node when it is discovering IoT devices. In line 6, on receiving ample replies from IoT devices, it changes its state to IOT and pushes this information to other sensor nodes using pushIoTExistMessage(m) method at line 12.
```
sendIoTExistMessageTo(P,m) = //sends message \(m\) to neighbor \(P\) isIoTRepliesEnough() = //returns True if no. of IoT replies is \(>=3\), else returns False state = //represents the current state of node
1:procedureGossipAlgorithm()//Push method
2:while true do
3: wait \(\Delta\) if\(isIoTRepliesEnough()\)then
4: m.age = -1 pushIoTExistMessage(m)
5:endif
6:endwhile
7:endprocedureOniToTExistReceive(m)//Push Receiver method
8:if\(m.age<2\)then
9: pushIoTExistMessage(m)
10:endif
11:endprocedure
12:procedurePushIoTExistMessage(m)
13:P = //random neighbor
14:if\(state==NORMAL\)then
15: state = IOT
16:endif
17: IoTTimerSet(1 min)
18: m.age ++
19: sendIoTExistMessageTo(P,m)
20:endprocedure
```  
**Algorithm 4** GossipAlgorithm  
Once a sensor decides to turn On IoT mode, it is for 1 minute. It broadcasts IoTExist (age = 1) messages to other sensors. Each receiving sensor that receives using procedure at line 8, re-broadcasts message after incrementing age unless age of the received message is two. Thus such messages stop after two hops.  
If a Sensor node does not receive such messages, and only one IoT reply, then it keeps itself in the Normal mode. The sensor can still communicate with IoTs. However its energy consumption can not be avoided.