Content uploaded by Anju Pillai
Author content
All content in this area was uploaded by Anju Pillai on Jun 16, 2022
Content may be subject to copyright.
Blockchain and IoT based inventory monitoring
system
Anmol Kaushik
Department of Electrical & Electronics Engineering
Amrita School of Engineering, Coimbatore
Amrita Vishwa Vidyapeetham, India
anmol.kaushikcontact@gmail.com
Anju S. Pillai
Department of Electrical & Electronics Engineering
Amrita School of Engineering, Coimbatore
Amrita Vishwa Vidyapeetham, India
s_anju@cb.amrita.edu
Abstract— Blockchain Technology has certain inherent
characteristics that can prove particularly useful to the field of
IoT. It has the potential to add a layer of trust and transparency
to the data reported by IoT based applications due to its
decentralized and immutable nature. An application that utilizes
these aspects of Blockchain has been explored in this paper. A
smart inventory monitoring system that focuses on shipped goods
was developed. The proposed system monitors the temperature
and humidity of the goods’ container. It also keeps track of
whether the lid of the container was opened at a certain point or
not and the duration for which it was left opened. These details
are periodically uploaded to Ethereum Blockchain’s Rinkeby
Test Network along with a timestamp and location history. These
details can then be retrieved from the Ethereum Blockchain and
monitored for signs of tampering or undesirable conditions. The
system was implemented on a Raspberry Pi 4. Details such as
transaction construction and upload times have also been
reported in the paper. The proposed system was able to provide
an immutable and decentralized historical log of the shipped
inventory as it passed through different stages of the delivery
process.
Keywords— Blockchain, IoT, Raspberry Pi, Ethereum, Supply
Chain, DApp, Smart Contracts
I. INTRODUCTION
Blockchain Technology has the potential of adding an
extra layer of ‘trust’ to the data reported by an Internet of
Things (IoT) based system [1]. It’s decentralized and
distributed nature can also provide a method of resistance to
cyber-attacks such as Distributed Denial of Service (DDoS)
attacks. Simply put, a blockchain is a distributed, immutable,
and decentralized ledger/database [2]. In a blockchain, valid
and verified transactions are grouped together in blocks [3].
Multiple such blocks are linked together in such a way that
each block (except the genesis block) contains a reference (for
example a hash) to the previous block. Thus, any
tampering/change in the previous block will lead to the
invalidation of the whole chain of blocks [4]. This ‘tamper-
resistant’ nature of blockchain technology is being utilized by
IoT based applications to add a layer of transparency in their
data transactions.
Centralized architectures (such as cloud computing) that
have contributed significantly to the rise of IoT face an issue
with a lack of confidence in how a network’s data is handled
and sourced [5]. Blockchain can enhance the trust factor of an
IoT application by improving traceability and reliability of the
reported data [5]. Using blockchain, it can be clearly identified
from where a segment of data (such as sensor readings)
originated, and an immutable log of this data is maintained
over time. If this log is tampered with, the entire chain of
blocks will be invalidated, and the data manipulation attempt
will be detected. The distributed nature of blockchain
networks also makes sure that multiple copies of the ledger are
maintained at various nodes. These copies can then be
consulted to further help with detecting any tampering
attempt.
Smart contracts can further enhance nodes in an IoT
system [6]. Smart contracts allow execution of code (or
agreements) stored on a blockchain only upon the meeting of
specific requirements. This allows nodes to behave more
autonomously and in a more secure manner [7]. This also
helps with improving the scalability of an IoT network. The
transactions also become faster when a central authority does
not have to authenticate them repeatedly.
One application of blockchain in the sphere of IoT is in the
logistics industry [8]. In this industry, blockchain can be
leveraged to achieve the above-mentioned benefits.
Blockchain can be used to track shipments throughout its life
cycle [8]. Any irregularities can be monitored and
permanently logged using a blockchain network.
In this paper, the proposed system showcases a proof of
concept that utilizes the Ethereum network to track a goods’
container for signs of tampering or non-maintenance of ideal
environmental conditions. The IoT based system periodically
monitors the temperature and humidity of a shipping container
using a DHT22 sensor. These details are then uploaded to
Ethereum’s Rinkeby test network along with timestamps and
location history. Another aspect of the system is the
monitoring of tampering attempts. An Infrared (IR) sensor is
used to monitor the opening/closing of the lid of the shipping
container. During the shipping process, when the lid of the
Proceedings of the Second International Conference on Electronics and Sustainable Communication Systems (ICESC-2021)
IEEE Xplore Part Number: CFP21V66-ART; ISBN: 978-1-6654-2867-5
978-1-6654-2867-5/21/$31.00 ©2021 IEEE 827
2021 Second International Conference on Electronics and Sustainable Communication Systems (ICESC) | 978-1-6654-2867-5/21/$31.00 ©2021 IEEE | DOI: 10.1109/ICESC51422.2021.9532876
Authorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on March 08,2022 at 04:44:25 UTC from IEEE Xplore. Restrictions apply.
container is opened, this event is logged and the duration for
which the lid was opened is also tracked. Details such as the
number of times the lid was opened as well as the duration for
which it was left opened are also uploaded to the Ethereum
blockchain. The system was implemented on a Raspberry Pi
(RPi) 4 single board computer (SBC).
Rest of the paper is organized as follows, Section II
provides a literature survey focusing on similar
implementations of Blockchain and IoT integration. Section
III provides details of the system implementation and utilized
technologies. Section IV provides a discussion on the achieved
results and outputs. Finally, Section V provides a conclusion
to the paper.
II. RELATED WORK
A review of blockchain-based systems has been provided
by the authors in [9]. The authors surveyed multiple
applications of blockchain in the transport industry. They
identified that blockchain has the potential to increase trust
among suppliers by allowing for the monitoring of malicious
attacks and product storage quality throughout the shipment’s
journey [9]. They also correctly identified that a lot of research
has gone into proposed ideas of systems leveraging blockchain
while instances of real-life implementations are comparatively
lacking. This brief literature survey focusses on examples of
actual implementation of blockchain based IoT systems.
The authors in [8] presented a decentralized application
(Dapp) that allows for tracking dispatched products until they
reach a delivery location. The shipped item could be tracked
throughout its life cycle, even when it is disposed till it either
decomposes or is recycled [8]. The authors designed a smart
contract and uploaded it to the Ethereum Ropsten test
network, followed by uploading it to the Ethereum main net.
The amount of gas (unit of transaction cost in Ethereum)
required for transactions was also reported.
In [10], the authors presented a blockchain based platform
to manage IoT devices. The authors showcased a proof of
concept where an IoT network comprised of a few Raspberry
Pis and a smartphone was managed using a blockchain
platform (Ethereum in this case). Here, each of the three
Raspberry Pis were meant to represent energy meters (e.g., a
light bulb) and the smart phone was used to set up an energy
policy (which was updated based on the electrical power
usage). The energy policy once defined on the smart phone
was uploaded to the Ethereum network. The meter devices
periodically polled the blockchain network for updated policy
values and adjusted their functioning accordingly. The meter
devices also periodically uploaded their power draw to
Ethereum. Ethereum was used to implement a tamper-resistant
management system.
Another SBC based implementation of BlockIoT
(blockchain + IoT) systems was exhibited in [11]. In this
paper, authors present a Dapp where blockchain is taken
advantage of while performing authentication in parking lots.
In their proposed system, an admin registers the approved
license numbers of cars and stores them on a blockchain.
When a vehicle is about to enter the parking lot, a license plate
recognition system recognizes the vehicle’s license number,
and this ID is verified against the record of approved licenses
that have been stored on the Ethereum blockchain. If the
license is in the approved list, the vehicle is allowed entry into
the parking lot. This work utilizes blockchain technology to
prepare a tamper-resistant ledger of approved vehicles.
Additionally, a detailed analysis of blockchain and its role
in IoT has been provided in [6]. The authors also give a
detailed explanation of the workings of a blockchain network
including transaction validation, mining and consensus
protocols.
The study provided valuable insights which guided the
implementation of the application that has been presented in
this paper.
III. SYSTEM IMPLEMENTATION METHODOLOGY
This section presents details of the implementation of the
system. It provides details of the technologies involved and an
analysis of the implementation methodology.
A. Smart Contract and Blockchain-side Backend
Implementation
Our implementation started with the design and
compilation of the smart contract. Smart contracts are pieces
of code stored on a blockchain that execute when specific
predefined conditions are fulfilled [12][13]. They provide a
means to automate workflows on the blockchain without the
need for a central authority. Solidity [14] is the most widely
used programming language for developing smart contracts.
Here, a smart contract was developed in Solidity to receive
data from the Raspberry Pi and log it on the blockchain. Also,
functions to return data from the blockchain were developed.
Fig.1 provides a brief look into the parameters stored on the
Ethereum blockchain. It also shows the constructor function to
our smart contract type.
Multiple functions to set/return the variables mentioned
above were developed. These functions can be used to
manipulate these variables and even specify conditions(if/else)
based on their values. The complexity of the functions
depends on the application. These functions can then be
invoked to manipulate the variables defined by this smart
contract.
Next step was the compilation of this solidity smart
contract. For this, the Node.js package (NPM) for a compiler
called solc was used. The compiler generates various outputs
that include binaries, bytecode, parse tree and estimations of
gas usage [15]. One of the crucial elements of the solc’s
output is the Application Binary Interface (ABI). The ABI of a
Proceedings of the Second International Conference on Electronics and Sustainable Communication Systems (ICESC-2021)
IEEE Xplore Part Number: CFP21V66-ART; ISBN: 978-1-6654-2867-5
978-1-6654-2867-5/21/$31.00 ©2021 IEEE 828
Authorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on March 08,2022 at 04:44:25 UTC from IEEE Xplore. Restrictions apply.
Fig. 1 Smart Contract parameters and constructor
smart contract is usually a .json file that represents a deployed
smart contract’s variables and functions and provides a
context for the contract [16]. The ABI in Ethereum provides a
way to interact with the contract both from outside the
Ethereum blockchain network as well as for contract-to-
contract interactions [17].
Followed by the compilation, an instance of the contract
was deployed to Ethereum Rinkeby Test network. An account
generated and loaded with ether (cryptocurrency based on the
Ethereum platform) for the Rinkeby Test network was utilized
to deploy the contract and fulfil the associated gas costs. Gas
is a unit of cost associated with transactions on the Ethereum
blockchain.
A Javascript based script was developed to deploy the
bytecode generated by the compiler onto the Rinkeby test
network. The script made use of the Web3.js [18] collection of
libraries that allow interfacing with an Ethereum node. Access
to an Ethereum Rinkeby node was provided by a service
called Infura [19].
Upon deployment, the smart contract is linked to an address
which can be used to interact with a specific smart contract on
the Ethereum blockchain
B. Interfacing sensors to the Raspberry Pi
A DHT22 sensor was interfaced to the Raspberry Pi.
Python based functions were used to decode the temperature
and humidity values from the data packet received from the
sensor. Similar python functions were developed to
communicate with the IR sensor. The high/low values
received from this sensor were used to simulate the opening
and closing of the lid of a shipping container. Python’s
multithreading module was used to execute the following two
tasks concurrently: monitoring and uploading data periodically
to Ethereum (Task1) and logging the opening and closing of
the lid and its duration and count (Task2).
C. Blockchain Integration
A Python library know as Web3.py was used to interact
with the deployed smart contract. The Web3.py code was
integrated with the sensor-interface code which was developed
earlier. In order to communicate with the previously deployed
smart contract, its address and ABI are required. Once these
parameters were obtained upon compilation and deployment,
integration code that can invoke functions previously defined
in the smart contract was developed.
Task2 supplied the details of the opening and closing of
the lid. These details include: the number of times lid of the
container was opened and the total duration for which it was
left opened. Task1 was responsible for accumulating the
readings from Task2 and the DHT22 sensor readings. Once
these details are obtained, a transaction to the Rinkeby
network is constructed. A timestamp and a simulated location
history (here dummy data was used, can be improved with a
GSM sensor) are further added to the transaction. The
transaction invokes the set_parameters function previously
defined in the deployed smart contract. Once the transaction is
made and validated by the actors on the network, these details
are stored on the blockchain. Web3.py provides functions to
perform these steps in the correct format. Raspberry Pi’s Wi-
Fi connectivity was used to communicate with Rinkeby
network through the previously mentioned Infura node.
To read details from the smart contract, the multiple data-
return functions previously defined in the smart contract were
invoked and the received data was displayed and logged to a
.csv file. Thus, an interface to the smart contract deployed on
the Rinkeby test network was created on the Raspberry Pi.
D. Summary of Methodology
A summary of the involved steps has been provided in the Fig.
2.
Fig.2 Methodology Flow
Smart Contract
Design and
Compilation
Deployment of
the Smart
Contract
Interfacing
sensors with the
Raspberry Pi
Integration of
Blockchain-side
code on the RPi
Proceedings of the Second International Conference on Electronics and Sustainable Communication Systems (ICESC-2021)
IEEE Xplore Part Number: CFP21V66-ART; ISBN: 978-1-6654-2867-5
978-1-6654-2867-5/21/$31.00 ©2021 IEEE 829
Authorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on March 08,2022 at 04:44:25 UTC from IEEE Xplore. Restrictions apply.
Fig. 3 System Implementation on a RPi4
IV. RESULTS AND ANALYSIS
This section presents the results obtained from the
implementation. Fig.3 provides an image of the system
implementation on the Raspberry Pi 4. Here, the object
obstructing the IR sensor (left) acts as the lid. When the object
is removed from the range of the IR sensor, it simulates the
opening of a goods’ container’s lid.
Fig.4 shows the sensor values from the DHT22 and IR
sensors and the data upload step. Once all the details including
a timestamp and location-history have been obtained, a
transaction is constructed and signed with the private key of
the uploading account. Once constructed, the transaction is
added to the pending transactions on the Rinkeby network.
Once the transaction is validated, the data is stored on the
blockchain. Table 1 provides the average time taken for the
above-mentioned activities.
TABLE I AVERAGE TRANSACTION CONSTRUCTION AND UPLOAD
TIMES
Activity Average
Time taken
(s)
Transaction build and signing 0.72
Transaction upload and validation 7.58
Fig. 4 Output when the lid has not been opened
Fig. 5 Output when the lid is opened and closed
It is important to note that the transaction time on an
Ethereum based network depends on the amount of gas paid as
well as network congestion [20]. Fig.5 showcases the output
of the system if the lid is opened and left open for a few
seconds. Here, the lid was opened once and closed again after
2.64 seconds. The number of times the lid was opened is
logged as well as the duration.
Another python program can be developed to read the
current values that have been stored by the smart contract on
the blockchain. This can be done by invoking the smart
contract functions and creating a read transaction. Fig.6
displays the data retrieved from the smart contract deployed on
the Rinkeby Testnet. Here, the scenario is as follows: the
container has travelled a fair bit of distance and the lid has been
opened 6 times. The following output is the latest data that was
stored onto the Rinkeby blockchain. Thus, a historical log of
the shipment is created. These details can be retreived
continuously and exported to a spreadsheet (here .csv) file to
get an idea of the change in these parameters over time. This
has been depicted in Fig. 7.
This log is immutable therefore, all the data mentioned
shown above can’t be modified by the shipping company or
malicious actors. The tamper attempts and duration are forever
logged on the Rinkeby blockchain network. Additionally,
change in the environmental parameters (temperature and
humidity) can be observed throughout the shipment’s
duration. The distributed nature of blockchain also ensures
that multiple copies of this log are maintained over numerous
Rinkeby nodes. This ensures increased transparency in the
shipping process for customers.
Fig. 6 Latest smart contract data stored on the Rinkeby network
Fig. 7 Data received from Rinkeby exported to a csv file
Proceedings of the Second International Conference on Electronics and Sustainable Communication Systems (ICESC-2021)
IEEE Xplore Part Number: CFP21V66-ART; ISBN: 978-1-6654-2867-5
978-1-6654-2867-5/21/$31.00 ©2021 IEEE 830
Authorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on March 08,2022 at 04:44:25 UTC from IEEE Xplore. Restrictions apply.
V. CONCLUSIONS
In this paper, a system that utilizes the Ethereum
Blockchain platform to increase transparency and trust in the
goods’ shipment process was presented. A few limitations of
the proposed system can be adressed in future iterations of this
work. A limitation of the work is that it doesn’t encrypt the
data before logging it onto the Ethereum blockchain.
Lightweight cryptography can be used to first encrypt the data
before upload. Additionally, the time taken for transaction
upload and validation can be deemed too high for certain
applications. This can be remedied by evaluating other
blockchain platforms [21][22] based on the target application.
Blockchain technology though inherently tamper-resistant can
still face some security issues such as the 51% vulnerability
[23] . These issues have been detailed in [23] along with some
possible remedies. In conclusion, the shipment of sensitive
goods (such as Covid vaccines) can leverage blockchain
technology to monitor the entire shipping process with
certainty. Additionally, most IoT edge devices are resource
constrained especially in terms of computational capability.
For these devices, a blockchain platform can potentially
provide a pre-built immutable, decentralized and distributed
ledger system without taking away resources from the edge
device.
REFERENCES
[1] J. Cuomo. “How Blockchain adds trust to AI and IoT.” ibm.com
https://www.ibm.com/blogs/blockchain/2020/08/how-blockchain-adds-trust-
to-ai-and-iot/ (accessed Jan 12,2021).
[2] L. S. Sankar, M. Sindhu and M. Sethumadhavan, "Survey of consensus
protocols on blockchain applications," 2017 4th International Conference on
Advanced Computing and Communication Systems (ICACCS), 2017, pp. 1-5,
doi: 10.1109/ICACCS.2017.8014672.
[3] M. Samaniego, U. Jamsrandorj and R. Deters, "Blockchain as a Service for
IoT," 2016 IEEE International Conference on Internet of Things (iThings) and
IEEE Green Computing and Communications (GreenCom) and IEEE Cyber,
Physical and Social Computing (CPSCom) and IEEE Smart Data
(SmartData), 2016, pp. 433-436, doi: 10.1109/iThings-GreenCom-CPSCom-
SmartData.2016.102.
[4] IBM Cloud. Blockchain Explained (Jul. 31,2019). Accessed
Jan.1,2021.[Online Video]. Available :
https://www.youtube.com/watch?v=QphJEO9ZX6s
[5] Reyna, Ana & Martín, Cristian & Chen, Jaime & Soler, Enrique & Díaz,
Manuel. (2018). On blockchain and its integration with IoT. Challenges and
opportunities. Future Generation Computer Systems. 88. 173-190.
10.1016/j.future.2018.05.046.
[6] K. Christidis and M. Devetsikiotis, "Blockchains and Smart Contracts for
the Internet of Things," in IEEE Access, vol. 4, pp. 2292-2303, 2016, doi:
10.1109/ACCESS.2016.2566339.
[7] C. Pauw. “How Significant is Blockchain in Internet of Things.”
cointelegraph.com
https://cointelegraph.com/news/how-significant-is-blockchain-in-internet-of-
things (accessed Jan. 15,2021).
[8] Christodoulou, Panayiotis & Christodoulou, Klitos & Andreou, Andreas.
(2018). A Decentralized Application for Logistics: Using Blockchain in Real-
World Applications. Cyprus Review. 30. 181-193.
[9] Astarita, Vittorio & Giofré, Vincenzo & Mirabelli, Giovanni & Solina,
Vittorio. (2019). A Review of Blockchain-Based Systems in Transportation.
Information. 11. 21. 10.3390/info11010021.
[10] S. Huh, S. Cho and S. Kim, "Managing IoT devices using blockchain
platform," 2017 19th International Conference on Advanced Communication
Technology (ICACT), 2017, pp. 464-467, doi:
10.23919/ICACT.2017.7890132.
[11] Z. Zinonos, P. Christodoulou, A. Andreou and S. Chatzichristofis,
"ParkChain: An IoT Parking Service Based on Blockchain," 2019 15th
International Conference on Distributed Computing in Sensor Systems
(DCOSS), 2019, pp. 687-693, doi: 10.1109/DCOSS.2019.00123.
[12] “What are smart contracts on blockchain?” ibm.com
https://www.ibm.com/topics/smart-contracts (accessed Jan. 15, 2021).
[13] Abraham, Misha & Kp, Jevitha. (2019). Runtime Verification and
Vulnerability Testing of Smart Contracts. 10.1007/978-981-13-9942-8_32.
[14] “Solidity” soliditylang.org https://docs.soliditylang.org/en/v0.4.24/
(accessed Jan. 20, 2021).
[15] “Using the compiler” soliditylang.org
https://docs.soliditylang.org/en/v0.4.24/using-the-compiler.html (accessed
Jan. 20, 2021).
[16] M. Javor. “Compiling and Smart Contracts : ABI Explained.”
sitepoint.com
https://www.sitepoint.com/compiling-smart-contracts-abi/ (accessed Feb.
1,2021).
[17] “Contract ABI specification” soliditylang.org
https://docs.soliditylang.org/en/v0.5.3/abi-spec.html (accessed Jan. 20, 2021).
[18] “web3.js – Ethereum Javascript API” web3js.io
https://web3js.readthedocs.io/en/v1.3.4/ (accessed Feb. 3, 2021)
[19] “Ethereum and IPFS APIs” infura.io https://infura.io/ (accessed Jan.
10,2021)
[20] “How long does an Ethereum transaction really take?” ethgasstation.info
https://ethgasstation.info/blog/ethereum-transaction-how-long/(accessed May.
1,2021)
[21] Benji, Mariya & Sindhu, M.. (2019). A Study on the Corda and Ripple
Blockchain Platforms: Proceedings of ICBDCC18. 10.1007/978-981-13-
1882-5_16.
[22] Sajana, M. Sindhu, and M. Sethumadhavan, “On block-chain
applications: Hyperledger fabric and ethereum,”In-ternational Journal of Pure
and Applied Mathematics,vol.118,no. 18, pp. 2965–2970, 2018.
[23] Xiaoqi Li, Peng Jiang, Ting Chen, Xiapu Luo, and Qiaoyan Wen. 2020.
A survey on the security of blockchain systems. Future Gener. Comput. Syst.
107, C (Jun 2020), 841–853. DOI:https://doi.org/10.1016/j.future.2017.08.020
Proceedings of the Second International Conference on Electronics and Sustainable Communication Systems (ICESC-2021)
IEEE Xplore Part Number: CFP21V66-ART; ISBN: 978-1-6654-2867-5
978-1-6654-2867-5/21/$31.00 ©2021 IEEE 831
Authorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on March 08,2022 at 04:44:25 UTC from IEEE Xplore. Restrictions apply.