Energy-efficient and Blockchain-enabled Model for Internet of Things (IoT) in Smart Cities

Wireless sensor networks (WSNs) and Internet of Things (IoT) have gained more popularity in recent years as an underlying infrastructure for connected devices and sensors in smart cities. The data generated from these sensors are used by smart cities to strengthen their infrastructure, utilities, and public services. WSNs are suitable for long periods of data acquisition in smart cities. To make the networks of smart cities more reliable for sensitive information, the blockchain mechanism has been proposed. The key issues and challenges of WSNs in smart cities is efficiently scheduling the resources; leading to extending the network lifetime of sensors. In this paper, a linear network coding (LNC) for WSNs with blockchain-enabled IoT devices has been proposed. The consumption of energy is reduced for each node by applying LNC. The efficiency and the reliability of the proposed model are evaluated and compared to those of the existing models. Results from the simulation demonstrate that the proposed model increases the efficiency in terms of the number of live nodes, packet delivery ratio, throughput, and the optimized residual energy compared to other current techniques.


Introduction
Smart cities use the latest information and communication technology (ICT) to strengthen public infrastructure, utilities and public services. Smart cities can be viewed as an application of increasing population and urban development growth that has strengthened innovative ways of managing urbanization with minimal environmental impacts, civil lifestyles and governance [1]. Sensors are used in a large area across the city to track and control the smart city application. Typical examples include traffic systems, healthcare systems, toll collection systems, automatically identifying road data and automatically identifying vehicle number plates. Data centres and analytical engines are the backbone in smart cities for decision making process. In smart cities, the network of wireless devices, cameras, and sensors allows managing agencies to efficiently provide mandatory services and actions. Furthermore, smart cities use recycled materials for building facility centres and reducing energy usage; in order to make them more friendly environment. Fig. 1 shows the life cycle of smart cities consisting of four phases. The cycle This research study proposes K-means clustering algorithm for cluster head selection followed by a linear network coding for WSNs consisting of a blockchain enabled IoT devices. The contribution of this research study is to propose a WSN model with the blockchain based IoT devices; thereafter, forming Kmeans clustering of devices [12] to minimize the energy consumption in the intermediate nodes. Another contribution of this work is to implement LNC mechanism and to develop the blockchain to improve the security, and the reliability.
The remaining sections of this paper are arranged as follows: The related work and discussion are presented in Section 2; while the proposed methodology is presented in Section 3; The results and discussion are presented in Section 4; and Section 5 presents the conclusion and future work of the research.

Literature Review
Taheri et al. [16] suggested a clustering protocol coined with fuzzy logic that is primally based on a multi-hop. The proposed method of the clustering has three stages. The knowledge about the neighbor's is modified in the initial stage and the fuzzy output is measured. Every node sensor is remotely located at some points in the later phase until the delay time to listen to the CH message. If it fails, it announces itself to be a temporary CH and places the message simultaneously inside the boundary of the cluster. In the next iteration, it becomes the last CH and transmits a message if it has the least cost between the temporary cluster heads in the vicinity.
Gnanambigai et al. [17] surveyed the low energy adaptive clustering hierarchy (LEACH) and the variant protocols. They concluded that WSNs are in a need of more scalable and energy efficient algorithms. The drawback of the LEACH cluster head selection is that the CH selection occurs randomly [18][19][20]. Because of this particular criterion, there are chances that a low-energy sensor node may be selected as CH.
Suresh et al. [21] devised an energy-efficient dual CH selection method for WSNs. In this method, two cluster heads-specifically, the primary and secondary cluster heads -are picked with respect to parameters like the node degree, the residual energy, the least standard distance from the member nodes' timer using the particle swarm optimization procedure. When a supply node desires to broadcast information to the destination node, an energy-efficient direction-finding protocol is utilized, based on factors such as the anticipated number of the retransmissions and the possibility of a breakdown in a connection. In this method, every cluster node transmits the information to the primary CH node, then after, the collected information is broadcasted to base station (BS) via the secondary CH node.
Researchers have intensively modified the LEACH protocol to improve the efficiency of the network. The research community has been energetically contributing to improve the existing schemes and methodologies in order to improve the performance of the IoT networks [22]. For example, the energyefficient method of trust derivation for WSN-based IoT networks has been explored in Duan et al. [23].
Sharma et al. [24] proposed a methodology to enhance the lifespan of the LEACH protocol using neural networks. They implemented an intelligent energy preservation model for the LEACH protocol called as LEACH-C algorithm which has increased lifespan. The nodes having the maximum energy of all are the best choice for CH.
Jamadar et al. [25] proposed an innovative energy-efficient WSNs using the K-means clustering algorithm. This method works on the basis of discovering the CH node with minimum distance from the centroid in terms of the Euclidean distance. The sensor is labelled as the CH node if the distance is lesser than the defined threshold value. K-means clustering protocol is employed in order to perform clustering of nodes which separates the sensor nodes to form K-clusters. Because of the successful CH nodes, the overall effectiveness of WSNs is improved with the respect to the parameters like the lively nodes and the spent energy for the transmissions.
Hwang and Huang [26] provided a secure channel of the communication in WSNs that are designated as a collector by a smart card owner to securely gather the data from the nodes which validates the collector and sending the data via a secure channel to the collector. By using the lightweight computing, the collector verifies the identification of the card's owner. This approach reduced the cost of communication.
Qin et al. [27] suggested the importance of the trust sensing algorithm for the routing that improves the security in WSNs. The aim of this mechanism used to control the attacks of the common networks affected by the inadequate energy and the defective deployment of the nodes on the networks for the data transactions in WSNs. Authors presented a trustworthy and secure routing scheme using attributes of a lightweight algorithm. The scheme provided resistance against several communication attacks at the same time.
Behera et al. [28] focused on the cluster head selection that interchanges the positions of the CH node among the cluster members having a maximum level of the energy. The algorithm takes into consideration, the residual energy, the initial energy, and the optimally selected CHs for selecting the succeeding set of CHs for WSNs.
Sun et al. [29] examined the effectiveness of the blockchain based network of IoT devices. In this work, authors proposed the spatio-temporal domain Poisson distribution. In this approach, the spatially distributed nodes and the rate data arrival were modelled as the Poisson point process (PPP). The successful blockchain transaction rate, throughput and the signal to interference noise ratio were derived.

Proposed Methodology
In the literature survey, we have observed that all the existing work to save the energy in the WSN-IoT systems are based on the parameters like the load balancing, the selection of cluster head, the minimum distance from centroid, the modified LEACH and the dual cluster head [16,17,[21][22][23][24][25][26][27][28][29]. None of these works have addressed the energy saving using the coding technique. The proposed model is accompanied by the linear network coding to minimize the frequency of the direct transmissions with the BS. The security of the proposed energy-efficient model is coined using a blockchain. The blockchain provides decentralized availability of the information that is distributed through a network which is based on its participant's trust [30]. The architecture of the proposed WSN-IoT model is illustrated in Fig. 2 which shows the selection of an appropriate CH using K-means, the encoding using LNC and the security through the blockchain network. The architecture has four components: (i) The WSN-IoT network; (ii) Gateway; (iii) The Blockchain network and (iv) The IoT applications. The first component is the WSN-IoT network which is the collection of the WSN nodes and the IoT devices. The WSN nodes sense the information from the environment and performing the routing function. The WSN nodes are also responsible for the clustering whereas the IoT devices are responsible for the data encoding using LNC. The second component is Gateways, which is responsible for the data reception and forwarding to the blockchain network as illustrated in Fig. 2. The WSN network and Gateway are connected through the base station. The sensor's data are inserted into the blockchain network using the consensus mechanism. The application layer retrieves the data from the blockchain network and performing the data analytics to initiate the appropriate actions in the applications of the smart cities.

Network Model
Consider the situation where there are N uniformly distributed nodes in the N x N square area. The assumptions about the participating nodes, BS, the location, the communication model of the underlying network model are presented as follows: 1. In the typical sensor network application, the nodes and the base station are all immovable once the deployment is finished.
2. The transmission is secured using the blockchain network.
3. The sensors nodes are assumed to be heterogeneous with varying the initial energy. 4. The geographical information of the sensors is known in advance. 5. All the clusters are connected to a single BS that is reasonably away from the sensing field.
6. This simulation model considers the one-hop communication to reduce delay. In the proposed model, the CHs communicate directly with the sensor nodes or BSs.
The energy consumption is measured by the Eqs. (1) and (2) using the first order radio model [31]. The transmission and the reception costs for the L À bit message in the network is computed using the below Eqs.
where : d th À threshold distance Energy, E e denotes the electronic energy, which is dependent on the factors like the scattering and the coding of signals, the modulation and the filtering techniques, while e mp d 4 or e fs d 2 , relies on the distance to the receiving node as well as the tolerable rate of the bit-error. The distance threshold is denoted by d th . Energy dissipation can be expressed as Eq. (3) [31].
3.2 K-means Clustering K-means clustering is based on the Euclidean distances and CHs rely on the nodes' residual energies [32]. In this algorithm, the central node, which is responsible for collecting information about the node such as the identification number (ID), the residual energy, and the positions of all the sensor nodes, saves these data in the form of a list. Once all the information is obtained from all nodes and then, the clustering algorithm (K-means) is executed [33].

Linear Network Coding
In linear coding, the data are split in many blocks by the source node. Every block contains m packets which are called as native packets [34,35]. This is represented by x j ; e 1; 2; . . . ; m f g . Thus; the LNC coded packet x 0 i is transmitted by the source node to the next CH. This packet x 0 i can be mathematically represented by the Eq. (5) [34]. where: c ji -matrix of coefficients The operations like the multiplication and the addition are computed over a Galois Field, GF(2q) [34]. A code vector, c * i ¼ c i1 ; c i2 ; . . . ; c im ð Þ and the ID of the block are embedded into the x 0 i header of the data packet. A counter that holds initial value of m 0 , where the value of m 0 is greater than m. This counter is maintained at the source node. The counter is decreased by one unit each time a coded packet is transferred to another node. The random transmission of the coded data packets continues till the value of the counter reaches to Zero [34]. The forwarding and recruiting functionalities are executed at each and every hop. The receiving CH starts the creation of the subsequent cluster once the packets of the same block are received. Now, this receiving cluster becomes a new transmitting cluster with the same nodes. The transmitting CH initially schedules the appropriate time of when the node is scheduled to send the encoded data to the receiver cluster which is applied to every nodes of the transmitting cluster [34]. The receiving CH then takes a control of the nearby nodes to form the receiver cluster, and to choose the nodes having the higher cost c i . This variable c i is defined for a node i, which can be possibly utilized for the receiver cluster, as expressed in the Eq. (6) [34,35].

Algorithm:
Step 1. Initially, to form 'k' clusters, let initially assume 'k' centroids which are placed at random places.
Step 2. Compute the Euclidean distance to all centroids from each node, and assign it to the nearest centroid as shown in Eq. (4). These 'n' initial clusters are generated, assuming that 'n' nodes are given which belongs to R d . Now, find the k centroids where: d X j ; m i À Á À Euclidean distance between X j and m i i f g n j¼1 À Centroid of the cluster Step 3. Now, recompute the locations of centroids of all the clusters and check if there is a variation in the location from the earlier one.
Step 4. If changes are found then go back to Step 2, otherwise finalize the clusters and end the process of clustering.
where: P ji À Probability of loss and I ji À Function of indication to indicate the availability of the sensor for receiving the packets.
The senor i might not be accessible because it is reserved to receive or to transmit data packets for another cluster from another path. The probability P ji is intermittently tested by ping samples of every neighbors. I ji relies on the way transmitting CH which assigns the sensor nodes to forward the data [34]. Consequently, the sensors which are expected to get more data are chosen as a recipient cluster from the transmitting cluster.
Let us consider that a node has obtained the encoded data x's. Then, the newly encoded data packet can be obtained from the Eqs. (7) and (8) [34,35]. where: c i À Randomly generated numbers selected from GF(2q) x 00 À Native data packets Similarly to the transmitting node, a sensor will embed a new code vector represented as g * i ¼ g 1 ; g 2 ; . . . ; g m ð Þ , within the x 00 header of the packet, when transmitting the encoded data packet [34]. When the sink node gets an encoded data, it will initially check if the data is new. A data is considered to be new and fresh only if it is linearly independent from the data received previously from the same block that the sink node has received. If the encoded data is not new, the data will automatically be disposed. Therefore, as long as m new packets are gathered, the receiver node is capable of recovering the native data packets. The process of decoding at the sink node implicates solving the group of the linear equations using the Gaussian algorithm. The linear equation determines a unique solution if m is the rank of the matrix [34].  : where: x 0 i -is an encoded packet c j1 ; c j2 ; . . . ; c jm À Á -code vector x j -represents native packets.
The sensors in the transmitting cluster might has obtained two or more packets from the preceding cluster, such that, they can form their own combination as shown in Fig. 3. The sensor nodes merge all obtained packets from the same block using randomly chosen coefficients to create a random linear combination.

Blockchain Formation
The blockchain is a decentralized, distributed and immutable shared database record which contains the archive of the transactions and the assets [36][37][38]. The validated and timestamped data are transformed into blocks that are chained together. This blockchain employs Rivest-Shamir-Adleman (RSA) as well as SHA-256 algorithm for providing resilient cryptographic proof for the integrity and the authentication of data or information [39]. Generally, the data block comprises the list of communications and a hash-key to the preceding block. The centralized authorities and the trusted third parties (TTP) have high chance of getting interrupted, hacked, or compromised. In addition, they might as well disobey and turn into being corrupt in the near future, although they are trustable presently. Every transaction in the blockchain is a shared public record which is checked by a widely held consensus of the minority nodes that are energetically playing a role in the transaction's verifications and validations. The header field of the block comprises of several fields, out of which, one is a version for tracking the protocol upgradations. In addition, the header consists of a timestamp, the total count of communications, and the size of the block. Private blockchains are built, which include the sensors for saving the data and then sharing them. These nodes are then classified into the given two classes: non-mining nodes and mining nodes. 1) Non-mining Nodes-The purpose of the non-mining nodes is to only receive and broadcast the requests of data sharing transactions, therefore, it does not require the same quantity of resources when compared to a mining node. It is notable that all the nodes keep a complete and validated replica of the blockchain and the sensors with a respect to the smart contracts. It is assumed that all the CHs have a legit connection with the blockchain network and forever round of transactions, the sensors upload the data collected from the point of interconnects (PoIs) to the blockchain network. Thus, the total number of requests for data storage S sent by the nodes N, at the end of round r, is given as S ¼ N Â r.
2) Mining Nodes-These nodes are utilized for verifying the transactions happening for the data sharing and for compiling them into the data blocks. These nodes are subjected to utilize the resources of machine computing consistently for the purpose of solving computational difficulties and for submitting the blocks to the blockchain network. Since each cluster head has a legit connection with the blockchain, the cluster head can perform encryption on the data collected with a private key and then forwarding it with a signature to the blockchain like a request for the storage. Additionally, the cluster heads can transmit the request for a query to the blockchain and can collect the reverted data.
3) Transaction and Consensus Mechanism-The acquisition of a data packet from IoT devices or sensors triggers the creation of a blockchain transaction. The gateway performs a number of transactions including data, control, and outcome transactions that generate a large amount of data. Therefore, a reference pointer is stored to locate the data in the transaction on the blockchain. The typical format for a transaction includes the transaction identifier, the type of transaction, the reference to data, the address of the senders and receivers, the block number, the signature, the public and private keys. The selection of the healthy or the efficient blockchain nodes is an important aspect for a faster and reliable consensus algorithm. The healthy nodes which acts as a miner are selected based on multi-criteria which may include the parameters like the computing capability, the storage capacity, the reputation, the mining cost, the throughput and the bandwidth etc. In this work, to rank the reputation of the blockchain mining node, we have selected the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) [40,41]. Nowadays, proof-of-work (PoW) has become an important consensus mechanism to verify the transactions using the mathematical challenges. The mining node collects all the transactions pending to generate a block in the PoW and iteratively hashes the collected data with its hashes using the Merkle tree. The process of hashing terminates when the hash of transactions becomes equal to or less than a pre-determined target value (t h ) known as a threshold and shown in the Eq. (10) [40,41]. In this equation, H is SHA-256 hash function and b c is the current block.
The probability to discover nonce of proof H can be expressed as the Eq. (11) [40,41].
Upon successful computation of the target hash, the miner sends the proof to every node in the blockchain network, data transaction and other data to re-compute H by other miners to add the new block in the network. In this work, we have applied the consensus mechanism based on Rivest, Shamir and Wagner's time-lock puzzle as shown in below [42]. In the simulation, initially, 15 nodes have been generated as the blockchain nodes. As soon the number of new nodes is added in the sensor network, another configured blockchain is selected. The first configuration consists of 10 non-mining nodes and 5 mining nodes, while the second configuration consists of 50 non-mining nodes and 25 mining nodes. The last configuration consists of 100 non-mining nodes, while the number of mining nodes is 50. These mining nodes act for consensus mechanism.

Results and Discussions
The suggested methodology was simulated in MATLAB R2018a an NS2 platform. This section of the research article provides all the results achieved from the simulation of the network transactions. The overall throughput, the alive nodes and the dead nodes for each round of transmission of the wireless communication are provided. The parameters considered for the simulation of the proposed network model are presented in Tab. 1.
The proposed scheme uses LNC for the data transmission that enhances the energy efficiency of WSNs. The security of data [43] is established using the blockchain.

Performance Metrics
Average throughput analysis-The amount of data successfully obtained at the receiver end per unit time in the network. This can be expressed as a given in the Eq. (12).
Average throughput ¼ number of packets received delay (12) Network Lifetime-This can be defined as a relation between the consumed energy and the available energy in the network [44]. In other words, this refers to the time when the very first node exhausts its energy in the WSN.
Residual Energy-This refers to energy remnants in a node. The residual energy can be expressed in the Eq. (13).
Reliability analysis-The reliability is the measurement of system life time that is inversely proportional to the loss of packets. Size of data for one block 2000 bits Packet delivery ratio (PDR) analysis-This can define as the percentage of the total packets obtained by the receiving end to the sum of the packets of the data sent.

PDR ¼
sum of data packets received by receiver sum of data packets sent by transmitter Fig. 4 displays the overall throughput obtained for increasing rounds of the data transmission. The total number of rounds of the transmissions is 12,000. The throughput reaches up to 700000 bits/second (bps). A comparison of throughput with the existing work has been presented in Tab. 2, which demonstrates the higher throughput achieved by the presented network model compared to the existing work.

Performance Evaluation
In general, the data transmitting process of the wireless networks use CHs to receive the information and to send to BS. In this proposed network, CHs wait until the information is gathered and encoded via a linear network coding. A block is created before uploading onto the internet. In order to access the information, the block connections of the blockchain have to be decoded with the help of the previous hash key used in the linear network coding. This ensures a reliable data transmission of IoT devices. A related comparative analysis with the existing work [46] has been shown in Tab. 3.   [46] 30000 R-LEACH [47] 200000 I-LEACH [48] 20000 Proposed model 700000 Fig. 5 displays the alive and dead nodes for varying number of transmission rounds. It can be seen in Fig. 5, that at the round 12,000, there are still 4 nodes staying alive. This infers that the energy spent for the transmission is drastically reduced in the proposed WSNs. Similarly, in Fig. 6, it can be seen that 96 nodes are dead at the 12,000 transmission rounds. Tab. 4 presents the lifetime comparison of the work proposed in this paper with the work proposed in the existing literature. From Tab. 4, clearly demonstrates that the lifetime of the proposed network is improved comparing to the existing works. Fig. 7a displays the average residual energy of the WSN. In the methodology presented, the initial energy is not completely exhausted even after 12000 rounds of the data transmission. Fig. 7a illustrates the low energy consumption which may prevents the network failures; thus, the increases of the network lifetime is guaranteed.
In WSNs, if the PDR is high, all the information is obtained by the receiving node without any loss of the packets. In Fig. 7b, PDR is high for differing intervals of time (increasing number of rounds of data transmission). The graph clearly shows that the proposed model has 99.98% PDR even after 12,000 rounds, which is better than the existing work [49].    [49] 850 8000 R-LEACH [47] 1382 2474 I-LEACH [48] 98 1700 PE-LEACH [50] 1265 1926 Proposed model 1772 10000