Next Article in Journal
Facial Emotion Recognition with Inter-Modality-Attention-Transformer-Based Self-Supervised Learning
Next Article in Special Issue
Redox Flow Batteries: A Glance at Safety and Regulation Issues
Previous Article in Journal
Fast Adaptive Binarization of QR Code Images for Automatic Sorting in Logistics Systems
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Blockchain-Based Peer-to-Peer Energy Trading System Using Open-Source Angular Framework and Hypertext Transfer Protocol

by
Mirza Jabbar Aziz Baig
1,*,
Mohammad Tariq Iqbal
1,*,
Mohsin Jamil
1 and
Jahangir Khan
2
1
Department of Electrical and Computer Engineering, Memorial University of Newfoundland, 230 Elizabeth Ave, St. John’s, NL A1C5S7, Canada
2
BC Hydro, 6911 Southpoint Drive, Burnaby, BC V3N4X8, Canada
*
Authors to whom correspondence should be addressed.
Electronics 2023, 12(2), 287; https://doi.org/10.3390/electronics12020287
Submission received: 7 December 2022 / Revised: 31 December 2022 / Accepted: 3 January 2023 / Published: 5 January 2023

Abstract

:
Renewable energy resources have been gaining ground in recent years and we are on the verge of a decentralized energy market with consumers becoming prosumers. Platforms that facilitate peer-to-peer (P2P) sale or purchase of energy are therefore essential. This paper presents a way to trade energy across P2P networks using blockchain technology. The main server is a Raspberry Pi 4 Model B (Pi4B), on which the user interface (UI) as well as the private Ethereum blockchain are configured. The blockchain also implements a smart contract. For the purpose of developing the UI that provides assistance in conducting trading activities, an open-source Angular framework is used. Also explored in the study is the development of an Internet of Things (IoT) server using the latest ESP32-S3 microcontroller. The field instrumentation devices (FIDs) are connected to the microcontroller for the purpose of data acquisition and for subsequent transmission to an IoT server. The blockchain network maintains a record of all transactions in an immutable manner. Assuring security is achieved through a local configuration of the system, hosted on a private network with restricted access. For the purposes of information security and data integrity, additional security measures are also considered, such as a secret recovery phrase, firewalls, login credentials and private key. Among the servers and clients, there is an implementation of a Hypertext Transfer Protocol. The P2P energy trading approach involving renewable energy designed for remote communities is explained and illustrated in this paper.

1. Introduction

As a result of the energy transition from fossil fuels to renewable energy, the energy sector globally is experiencing a significant transformation. The energy consumer has evolved into a prosumer. Distributed energy resources, such as photovoltaic (PV) systems, have been prevalent in energy markets, contributing to the growth of prosumers [1]. This creates a decentralized energy market that provides consumers with the opportunity to purchase energy locally rather than through the utility companies only. Energy can now be traded directly between individuals without the involvement of an intermediary. According to [2], consumers and prosumers trade energy directly through P2P trading. It can be greatly facilitated by the use of information and communication technologies. A revolution has been sparked by blockchain and intelligent devices on the P2P market. The blockchain enables the prosumer to conduct financial transactions independently. Conversely, smart devices coupled with the Internet-of-Things (IoT) provide low-cost means to exchange energy. There is no doubt that market for conventional electricity has been heavily influenced by renewable energy sources. Even so, it has not been able to capture the traditional electricity market in its entirety. There may be a number of factors contributing to this, including the inability to obtain a return on investment. Throughout this study the authors strive to maximize the returns to prosumers on their investment. A blockchain and IoT-centered energy trading platform is proposed by the authors. With its decentralized structure, the proposed system provides participants with the most recent energy trading solutions, including financial transactions, energy transfers, and energy metering. Participants in the proposed system will be able to conduct financial transactions using all the security features that come with a blockchain network. As for the IoT server, this enables peers to control and monitor their own energy generation. The proposed method for P2P energy trading uses two major components to host the server, a raspberry pi model 4B (Pi4B) that hosts a private blockchain server with UI and ESP32-S3 microcontroller to host the IoT server.
According to the authors’ findings in [3], the increasing use of distributed energy resources in distribution systems is enabling low-voltage networks to utilize new methods of operation. P2P energy trading schemes have been proliferating recently as a result of recent trends in cryptocurrencies and blockchain, which enable neighbors to exchange electricity without any intervention from traditional intermediaries. Under this scenario, the network’s technical constraints have not been adequately addressed. According to the authors, the impact of exchange on network constraints can be assessed using a sensitivity analysis. A low-voltage U.K. network is used to test the proposed method. As a result of this study, it was found that P2P schemes can still provide users with economic benefits without violating the network constraints. Another study [4] identified peer-to-peer energy trading as an effective method by which multiple consumers could benefit from renewable energy in an active distribution network. This study emphasizes the energy transactions to be implemented securely, and it is still necessary to meet the distribution voltage constraints. A decentralized P2P energy trading protocol that is capable of voltage regulation is proposed by the researchers. IEEE bus-33 and 69 standards are used to verify the effectiveness and efficiency of the system through case studies. Zheng et al. [5] describe the proliferation of distributed energy resources as leading to peer-to-peer trading. According to the authors, there is a growing consensus among the experts that the future of the energy market is P2P. This study examines the concept of shared energy storage, based on the sharing economy principle, as a way of reducing capital expenditures and increasing storage devices’ efficiency. P2P energy trading model for residential homes with shared energy storage is presented in this study. It has been demonstrated through numerical simulations that energy trading through P2P is beneficial for all participants, while the introduction of shared energy storage may be capable of further reducing the energy costs. In their study [6], the authors found that P2P energy trading benefitted both consumers and operators. A key role for demand-response management will be to bridge the gap between local demand and supply in future P2P energy markets. The authors proposed a blockchain-based system for community-based P2P energy trading. Through the use of two noncooperative games, a demand-response mechanism is proposed. The proposed energy trading system uses Hyperledger blockchain to prototype dynamic pricing for suppliers in both games. On-chain and off-chain processing modes were implemented to study the system’s performance. As a part of this study experiments validated that demand-response games reduce peak loads significantly, while providing lower latency and overhead compared to on-chain models. Authors have proposed deploying Verifiable Query Layer (VQL) to the cloud for data query services for blockchains in [7]. A proposal for vChain+ to support boolean range queries is presented in [8]. That supports data queries on the blockchain.
Another study [9] discusses the factors that have led to the transformation of corporate standards in the electricity sector globally due to disruptive technologies as well as the reduction in costs associated with photovoltaics. In addition to providing a customer choice aligned with the values of a community, P2P energy trading has the capability to make green energy more readily available locally. This study investigates the factors that drive and challenge implementing P2P energy trading in Thailand from the perspective of participants in the regulatory sandbox program. Political, economic, social, technological, legal and environmental factors will have a significant impact on P2P energy trading implementation, according to the authors. Among its recommendations are establishing third-party access, liberalizing the electricity market, and incorporating prosumers in existing legal structures to establish a regulatory framework towards the future of P2P energy trading. Local consumption of renewable energy is promoted by P2P energy trading. There is, however, distrust amongst users, as well as high transaction costs associated with P2P. As a solution to these issues, the authors propose a credit and blockchain-based P2P energy trading model. A six-stage P2P electricity trading process is first presented. In the next step, Docker and Go are used to simulate Hyperledger Fabric. In P2P electricity trading, the proposed model can enhance trading stability and efficiency by reducing the cost for users and managing credit [10]. According to researchers [11], there has been an increase in energy trading owing to the availability of distributed energy sources as well as the ability of electricity producers to export surplus fuels at a financial profit. Energy from multiple sources is successfully combined through the energy trading system providing energy consumers with better facilities and consistent use of resources. The authors discuss decentralization, scaling and device reliability as ways in which blockchain can enhance transparency and performance. A blockchain-based smart grid is also demonstrated in terms of its importance in future smart grid activities. Furthermore, the research briefly examines the implementation of blockchains to ensure future autonomous electric grids will be decentralized, secure and scalable. In [12], an IoT and blockchain-centered P2P energy trading platform is introduced as a pilot study. Based on open-source technology, the authors proposed a blockchain-based platform for P2P energy trading with the fundamental characteristics of a P2P energy trading platform.
The authors in [13] believe that P2P energy trading represents one of the most promising solutions for energy management in an isolated distributed system. Their proposal focuses on the development of a P2P energy trading platform based on blockchain and IoT technology. A Node-Red-based dashboard is used to perform energy monitoring and trading tasks, while email notifications are used to provide trading alerts. Through experimental results, the proposed system has been validated, and it is recommended for fast and secure P2P energy trading. An isolated DC-microgrid could benefit from a P2P energy trading solution based on blockchain and IoT, as referenced in another study [14]. In the context of [15], through the implementation of a smart contract on a private blockchain, a P2P energy trading system is proposed. As a part of this system self-generated energy is monitored and controlled using the IoT platform and to perform trading activities, and the authors developed a user interface using the React J.S library. In the suggested P2P energy trading system, a microcontroller and FIDs were used, as well as a private communication channel for data exchange using the Message Queuing Telemetry Transport protocol (MQTT). Testing and validation of the developed system are carried out using an experimental setup. Other researchers [16] have developed a low-cost P2P energy trading setup that has been implemented in a remote community using open-source technology. For P2P energy trading within the community, the authors developed a low-cost server utilizing blockchain technology and the IoT. As part of the development of the proposed system, they also used React.JS, FIDs and Microcontrollers. Hypertext Transfer Protocol (HTTP) is used in this study to communicate data over a private network, and security considerations are also considered.
Through the course of this study, the literature has been extensively reviewed, and some of it is summarized above. In light of the literature reviewed and to the best of the authors knowledge, no platform has been identified that uses Angular-6, a component-based application development platform together with ESP32-S3 microcontroller for blockchain-based P2P energy trading. A private Ethereum blockchain has also been incorporated with open-source Angular-6 as part of our design. As for blockchain server, Pi4B is used, while ESP32-S3 is utilized to host IoT server. In addition to being fully automated, each server is interconnected via HTTP. The platform is installed locally and can be accessed remotely via a Human Machine Interfaces (HMIs). An interface allows users to perform energy trading activities that is accessible at http://localhost:4200/ (accessed on 1 October 2022). The proposed system offers the following key contributions.
  • Angular, the framework on which many popular websites such as Paypal, IBM, Weather, Samsung, etc. are built, is configured in implementation of the proposed P2P energy trading system. In addition, Angular-based UI is deployed on Pi4B coupled with a local blockchain server as well as an IoT server running on ESP32-S3. To the best of authors’ knowledge, a novel P2P energy trading system is proposed, and no such system has been reported before.
  • Implementation of a P2P energy trading with locally configured servers, hosted on a private communication channel, is particularly useful for remote locations that do not have access to the internet.
  • An appropriate system configuration ensures independent monitoring and control of P2P energy trading.
  • Considering the fact that the proposed design is open-source, there is no subscription fee or operating cost to be incurred due to the use of open-source technology.

2. System Description

An overview of the proposed blockchain centered P2P energy trading system is described in this section. As illustrated in Figure 1, the proposed system design consists of an energy storage system (ESS) represented here with batteries, a domestic load component, a main server and an IoT server. To implement the system design, we have used ESP32-S3 microcontroller that hosts an IoT server and a Pi4B as the main server to set up the Ethereum private blockchain and user interface (UI). The proposed system is hosted on a private network represented by a Wi-Fi router in Figure 1 and is accessible to every participant of the P2P energy trading system using HMIs. The rest of the system architecture is composed of FIDs such as a relay, a current sensor and a voltage sensor. In addition, the figure illustrates the connections that can be used to trade energy with other peers.
In the event that any participant in this proposed P2P energy trading system needs to engage in energy trading, an UI allows them to access the system remotely and execute trades, such as the purchase and sale of energy. Upon receiving the trade request, the relay will be turned on and the trading session will begin. Following the transfer of the required amount of energy, the relay will shut off automatically. The trading process in this system is entirely automated and is conducted through the use of computer algorithms. Later in this article, we explain the pseudocode. Authentication of users has been configured to ensure network security. To facilitate client-server communication, the proposed system makes use of the HTTP request-response protocol. Open-source technology is at the core of the system.

3. Technology and Software

The following section provides an overview of each major technology employed in the development of our proposed P2P energy trading system developed using open-source technology. Among these technologies are a main server that is hosted on Pi4B, a single board computer (SBC) and an IoT server that serves as a data acquisition, monitoring and control system. A versatile microcontroller ESP32-S3 is used in this study as a platform for hosting an Internet of Things server. Other key components employed in this study are the FIDs. As well as this, we have also established a local communication network using a Wi-Fi router. In addition, servers’ communication is carried out through HTTP protocol.

3.1. Raspberry Pi

In February 2012, the Raspberry Pi 1 Model B, generation 1 was released. The low price of $35 contributed to its immediate success. An inexpensive computer running Raspbian, a Linux operating system based on Debian, can be quickly assembled by adding a few peripherals. Typically, this device is often mentioned as a Single Board Computer (SBC) [17]. Raspberry Pi computers have proven enormously successful in a wide range of electronic projects. Do-it-yourself tinkerers and special purpose projects use it because of its low cost and accessibility. Its low cost has also made it possible to use it as a component in single-purpose devices, despite being a general-purpose computer [18]. Raspberry Pi Foundation, United Kingdom, developed and manufactures the Raspberry Pi (Pi). Compared with a mid-range desktop computer that typically costs between US$500 and US$600, the latest Pi 4 Model B (Pi 4B) is available for just US$35 for the base model with 2 GB of RAM [19].
A significant part of this study was conducted using Pi4B, the first of a generation of Raspberry Pi computers with significantly improved CPU, GPU, and I/O performance compared to its predecessor. Pi4B allows access to 28 BCM2711 GPIO ports via the Raspberry Pi’s 40-pin header. The device features a quad-core 64-bit ARM Cortex A72 processor running at 1.5 GHz, has 4 Gigabytes of RAM and is 802.11 b/g/n standard protocol compliant. To add to this the following key characteristics, make this chip appropriate for the proposed energy trading platform [20].
  • Compact size
  • H.264 hardware decode (up to 1080p60)
  • VideoCore VI 3D Graphics
  • 1xSDCard
  • 2x micro-HDMI ports supporting dual displays up to 4Kp60 resolution
  • 2xUSB2ports
  • 2xUSB3ports
  • Linux software stack
  • 0 to 50 degrees Celsius ambient temperature range.
As a main server UI is configured on Pi4B. For the purpose of energy trading UI is accessible through browser at http://localhost:4200/ (accessed on 1 October 2022). In addition, the blockchain server is hosted on it. This system is configured on Raspberry Pi OS 64-bit, the latest release [21].

3.2. ESP32-S3

As a low-power MCU-based system on a chip (SoC), ESP32-S3 supports wireless connectivity with integrated 2.4 GHz Wi-Fi, as well as Bluetooth® Low Energy. The device consists of a 32-bit Xtensa® LX7 dual-core microprocessor and a low-power coprocessor. It is a complete Wi-Fi subsystem that conforms to IEEE 802.11b/g/n standard protocol and supports the Station, SoftAP, and SoftAP + Station modes of operation. A wide range of applications can be served by its multiple low-power modes. Among its capabilities, the ULP coprocessor is able to operate in a low-power manner. ESP-32-S3 has a powerful memory ensured by 128-bit data bus and SIMD commands, 384 KB ROM, 512 KB SRAM, 16 KB SRAM in RTC and various interfaces that allow connection to external RAM, as well as the other key features includes advanced Peripheral Interfaces, low power management and device security [22,23].
Our research involved the use of the ESP32-S3 SoC device for local data acquisition, monitoring, and control applications. For this purpose, the ESP32-S3 is connected to the FIDs for real-time data acquisition, which helps to monitor energy trading and control operations.

3.3. The Blockchain

The blockchain is a cutting-edge technology that has modernized social interactions and trade. As far as the definition is concerned, the term blockchain refers to a chain of blocks on a decentralized network that stores information with digital signatures. Bitcoin and Ethereum are examples of digital cryptocurrencies created using this technique. The primary feature of this technology has recently been focused on numerous other application domains in a variety of research and industrial studies [24]. It refers to a ledger of blocks that is timestamp able, immutable, auditable, permanent and tamper resistant. These blocks enable data to be stored and shared in a peer-to-peer manner. Data stored in the blockchain may include payment history, contracts or even personal information. The security, auditability and anonymity of blockchain technology have attracted significant attention [25].
This study is carried out using the Ganache command-line interface (CLI), a client for Ethereum. A fast and customizable blockchain emulator, Ganache CLI is the latest version of TestRPC. This allows you to access the blockchain without incurring the overhead associated with running an Ethereum node. Through it, it is possible to access and incorporate a local Ethereum blockchain server. It is advantageous to use Ganache for the following reasons [26].
  • No transaction cost.
  • Modifying gas price and mining speed is possible.
  • Accounts can be recycled or reset.
  • Accounts can be instantiated along with a predetermined number of Ethers.
  • Transactions are “mined” instantly.
An illustration of the running Ganache CLI remote procedure call server (RPC) used as part of this study is shown in Figure 2. The account assignment gives ten accounts, with 1000 Ethers in each account, as well as a private key for every single account. This study uses v7.0.2 Ganache.

3.4. Internet of Things (IoT)

As a concept that originated in 1999, when Kevin Ashton coined the term IoT, the Internet of Things has evolved into one of the most powerful business development tools [27]. In a recent report, the National Intelligence Council and McKinsey Global Institute claimed that everyday objects, such as furniture, paper documents, food packages, etc., will take on the role of Internet nodes by the year 2025. Through integrating technologies with the human environment, they envision the future. There is no need for humans to intervene in the IoT, as things communicate and exchange data autonomously [28]. The IoT enables sensors and devices to communicate with one another in real time, thereby facilitating real-time data monitoring and control. Furthermore, P2P energy trading was supported through the use of an IoT platform based on Node-Red [15].
In the course of this study, we have set up a local IoT server for monitoring and control purpose. ESP32-S3 chip hosts the local IoT server with a local IP address. Using IoT servers, real-time data are received and displayed on dashboards. Through browsing to a local IP address, a user may access the Internet of Things server.

3.5. User Interface (UI)

A description of the user interface developed as part of this research is provided in this section. As a means of facilitating peer interaction, we have developed an intuitive UI for the proposed P2P energy trading platform. The UI is configured on the main server, Pi4B, and the user can access URL (Uniform Resource Locator) by visiting http://localhost:4200/ (accessed on 1 October 2022). Figure 3 illustrates UI for blockchain based P2P energy trading platform. For their respective energy calls, peers may use “Buy Energy” or “Sell Energy” sections of the UI. Aside from this, the peers are able to view their associated account numbers and balances on the user interface. Additionally, the UI provides application-side access to the blockchain, where the user can access the details of trading.
Angular has been used to develop the user interface in this study. The Angular framework is a suite for developers that provides a collection of well-integrated libraries with features such as management of forms and communication between the client and server. As a prototype to global deployment, Angular delivers Google’s largest applications with productivity and scalability [29]. A wide range of popular and impressive websites, including business, banks, news and weather, use Angular for their front-end development. Angular framework has been successfully applied by Upwork, Deutshe Bank, IBM, Weather, PayPal, Delta and Samsung [30].
In the course of this study, we have integrated the UI with Ethereum blockchain and MetaMask. MetaMask is used to access Ethereum blockchain accounts. The MetaMask platform is a trailblazing tool that facilitates user interactions and experiences on the Web3. In addition to a browser extension, it is also available as a mobile app for Android and iOS devices, as of now. MetaMask was developed to ensure the security and ease of use of Ethereum-based websites. Specifically, it manages user accounts and connects the user to the blockchain [31]. This study involves the deployment of a smart contract on the private blockchain. We have used Angular-6 for development of UI and the basic source codes for smart contract and UI can be found at [32,33].

3.6. Communication and Network

Hypertext Transfer Protocol (HTTP) is the most commonly used protocol by the internet traffic. There are primarily HTTP request and response messages contained within it. In HTTP, upon receiving a request from a client, a server responds to the request. Presently, it is the most widely used application-level protocol [34]. It is the HTTP that underlies the World Wide Web. Information/data are communicated between devices over the network using HTTP as an application layer protocol. When an HTTP client transmits a request to a server, the server responds with a message. A valuable amount of information is conveyed in these responses in response to an HTTP request [35]. Our study involves the use of HTTP to transmit energy trading data amongst the clients and servers. Following the receipt of a trading call from the client, the main server transmits data information to the local IoT server, which then initiates the trade. With the assistance of a computer algorithm, the transfer is automatically terminated after the trading request has been satisfied.
In this study, The Tenda Router (N304 V2) and 2.4 GHz operating frequency band were used, to create the TCP/IP Wireless network connectivity over which the HTTP protocol is implemented for data transfer between client and server. According to IEEE 802.11n standard, this device is compliant. The ESP32-S3 microcontroller and Pi4B used in this research are also capable of supporting TCP/IP, IEEE 802.11b/g/n Wi-Fi standards, this router is configured to enable a private network and implement HTTP. In addition to the Service Set Identifier and password, firewall protection is enabled as part of network security.
The study also makes use of FIDs in order to facilitate the practical transfer of energy. With the aid of resistors and the voltage divider rule a voltage sensor is set up, which measures the voltage consumed whereas the current sensor measures the current. As a final step, a relay is used to initiate or terminate the transfer of energy. A detailed description of FIDs and their use can be found in [13]. This study involves on-chain storage of data and the use of a microSD card for system memory.

4. Design and Implementation of Hardware Component

Our discussion in this section is focused on the design and implementation of hardware components for the proposed P2P energy trading solution based on blockchain technology. Also included in this section will be information regarding the connections.

4.1. Prototype Design

A brief description of the conceptualization of a system prototype is provided here. In Figure 4, a voltage sensor is constructed by arranging pull down resistors on a breadboard in accordance with the voltage divider rule. In this study, ESS voltage is measured using this voltage sensor, with the inputs connected to the battery using jumper wires. A current sensor mounted on the breadboard serves to measure load current. The relay used in the hardware design of the P2P energy trading system is intended to initiate or terminate energy trading activities. In this case, an ESP32-S3 microcontroller is utilized for acquiring current and voltage data through sensors and transmitting it to the local IoT server, which is also hosted on an ESP32-S3 microcontroller. Through the IoT server, peers may monitor and control the activities associated with energy trading. Furthermore, a Pi4B is visible in Figure 4, which hosts the UI and a private blockchain server.

4.2. Experimental Setup

Preliminary to their use, the hardware components were programmed and configured in accordance with the procedures described in Section 3. According to Figure 5, the experimental setup consists of a battery serving as the voltage source (in a real system that will be charged using PV) and an LED light serving as the load for the purpose of demonstrating real-time energy consumption in response to a trading request. Data monitoring is performed in real time by the current and voltage sensors. The experimental set up includes a Wi-Fi router, which enables communication between the client and server using HTTP over a local network. A remote access is also demonstrated using the HMI to the local IoT and the main server. In Figure 5, B represents the battery a voltage source, CC represents a Wi-Fi router used as a communication channel in this study, C represents the current sensors, Espp32-S3 microcontroller is represented by M, a voltage and current sensors are represented by V and C, respectively. Raspberry Pi is presented by Pi and a laptop shows an HMI device here.

5. Implementation Methodology

This section describes the data and information exchange process that occurs between the main server and local IoT server in blockchain based P2P energy trading. Our study utilizes the ESP32-S3 microcontroller for the purpose of setting up a local IoT server and obtaining data (voltage and current) through the use of voltage sensor and the current sensor. The data measurements and collection are carried out with the aid of the Arduino Integrated Development Environment (IDE) programs compiled and uploaded into the ESP32-S3 microcontroller. A private communication network enables the ESP32-S3 to further transmit these data to a local IoT server, accessible through Internet Protocol (IP) address. In Algorithm 1, a pseudocode is provided for the implementation methodology. According to Algorithm 1, steps 1 to 7 connect the microcontroller to the wireless network, then display the connection status in Arduino IDE serial monitor. A description of the process of trading energy can be found in steps 8 to 17 of Algorithm 1. During the energy trading process, the relay will start the energy transfer after receiving the trading call over HTTP from UI. In addition to data acquisition, the ESP32-S3 displays these data on local server’s dashboard. Energy consumption and demand are then compared by the server, and after the trading request has been fulfilled, the energy trading process over HTTP is terminated. Upon disconnecting from the client, a new process is initiated, as illustrated in line 18 and 19.
Algorithm 1 Energy trading data acquisition, monitoring and Control
Initialization;
Energy Demand = 0;
Energy Consumed = 0;
While
    1.  ESP32-S3 is not connected to private network;
    2.  Set up ESP32-S3 connection by passing, SSID, and password over private network;
If
    3.  ESP32-S3 connection established with local-Wi-Fi;
    4.  Display “Connected” on Arduino IDE Serial Monitor;
else
    5.  Display “Connection failed… retry in 5 s” on Arduino IDE Serial Monitor;
    6.  ESP32-S3 connects to private Wi-Fi network;
    7.  Display IP address on Arduino IDE Serial Monitor;
While
    8.  Refresh sensor value;
         If demand is available then
    9.  ESP32-S3 reads demand data over http;
         If Energy demand from UI then
    10.  Update energy demand;
    11.  Relay is turned on by ESP32-S3;
    12.  Energy transfer begins;
    13.  Power and energy are calculated by ESP32-S3 based on sensor values;
    14.  Data displayed on local IP;
    15.  Update data;
           If energy consumed >= energy demand then
    16.  Switch off relay;
    17.  Energy transfer terminates;
    18.  Disconnect client;
    19.  Step 8;
end

6. Testing and Results

A blockchain-based P2P energy trading system as described earlier in this paper, has been successfully tested and the results are presented in the following section. According to the results of the system testing, the desired outcome has been achieved. Figure 6 illustrates how the system operates. In this flowchart, a brief summary of how the energy trading system works is presented, along with a closer appearance at the information.
In Figure 3, peers can perform tasks associated with energy trading through an intuitive user interface. Through this interface, they will be able to perform energy “Buy” and “Sell” transactions. Using this platform, participants in the proposed blockchain-based P2P energy trading system can meet their energy needs and sell surplus energy as well. MetaMask is also integrated into the UI as a chromium extension for the secure management of accounts and the connecting of peers with the blockchain server. A demonstration of how accounts created specifically for this study (Figure 2) can be imported into the energy trading platform with the private key associated with those accounts is presented in Figure 7a, while Figure 7b depicts the user authentication process to access MetaMask. When the peer place and energy trading request on UI (Figure 3) Users’ account details will appear on the screen with the MetaMask extension. The same account number and balance will also be appearing in the My Account part of the UI. After this, the client can either confirm or reject the transaction by accessing their account, as demonstrated in Figure 8. Along with allowing users to purchase and sell energy, the proposed P2P energy trading platform will also allow users to view the trading activities of their peers, including their own. An overview of My Account status on the User Interface, where peers can view their own trading activity, is depicted in Figure 9. It illustrates the actions performed by the user in regard to the purchase and sale of energy. Figure 10 and Figure 11 illustrate actions performed by other peers on the network in order to buy energy and sell energy, respectively. Through the P2P energy trading system, users are able to see the amount of energy available for trade along with the price, as well as the owner of the particular transaction. In the event a peer performs any trading activity, the activity will appear in the respective section on the UI and all peers will be able to see it. To execute a trading call, peers can use the Buy or Sell buttons on the user interface. A local IoT server running on the ESP32-S3 microcontroller will determine the amount of energy being transferred following a trading operation. When an energy trading request is successfully completed, the relay is activated to begin or stop energy transfer.
In order to keep track of the trading activities on the UI, a private blockchain server, an Ethereum client, is employed. The study involves the implementation of the Ganache CLI in order to establish a local blockchain network for real-time money transfers in response to energy purchases and sales. Through http://localhost:5051/ (accessed on 1 October 2022), all participants can access the blockchain server. The ganache-CLI block explorer is open source and configured locally. It enables participants to explore blocks in a local blockchain network using a localhost-based block reader. It is possible for participants to view data regarding the amount of energy transferred, mining details, block sizes, gas used, and gas limit. The ganache CLI client is communicated with using the Ethereum library written in Go language [36]. Based on the transactions entered into the UI of the system, the blocks are mined on the blockchain server as shown in Figure 12. This process generates 28 blocks, the block explorer can be used to view these blocks. A block is mined in response to each energy trading activity and displayed on the dashboard of block explorer. In Figure 13, peers are given the option to explore further by providing a block hash or block number to obtain further information regarding a particular block. On the blockchain server, block 28 is illustrated in Figure 14. Energy transactions within a block are illustrated in Figure 15. An Ethereum transaction fee is displayed as well as a block hash, which is a unique address of each block mined following a successful transaction, the time stamp, which indicates the time and date at which the block was mined, and the gas used. Ethereum’s native currency, Ether (ETH), is used to pay for gas. In Ethereum, gas prices are measured in gwei, and 1 gwei is equal to 10-9 ETH [37]. Additionally, there is information regarding the parent hash (of a previous block), gas limit and block size. In this paper, we propose a blockchain-based P2P energy trading system with an IoT server that is running on an ESP32-S3 microcontroller, which is used for data acquisition, monitoring and control of energy trading. An energy meter with switching capabilities and functions as a means of initiating and terminating energy trading. ESP32-S3 initiates the energy transfer request over HTTP and ends it after the specified amount of energy is transferred. The status of the IoT server is illustrated in Figure 16.
To validate energy transactions, ten accounts have been created as part of this system. MetaMask can access a remote blockchain server by providing RPC URL and respective chain ID. The transaction processing time shown by the server on MetaMask is less than 30 s. A successful test of the system, however, revealed that the actual transaction time is 2 s.

7. Discussion

Following successful testing and observing the results, this section outlines some of the key characteristics of the proposed energy trading system.
Low Power: A system designed to operate 24 h a day, seven days a week is highly dependent on its power consumption. It is important to select the individual components of an IoT-based system based on their power consumption. The proposed system uses a Raspberry Pi as its main server, which consumes as low as 2.5 Watts (W). A local IoT server runs on an ESP32-S3 as a part of this research with a power consumption of 0.6 W. During the course of this study, 1.7 W of electricity were consumed by a Wi-Fi router used to establish a local communication network. Each component’s power consumption is observed under operating conditions, and specific information can be found in the data sheets. The Table 1 below summarizes the power consumption of the hardware components used in this study.
Low Cost: Through the utilization of readily available and low-priced hardware components, a low-cost system design has been achieved. Listed below in Table 2 is a breakdown of costs for each element of the blockchain-based P2P energy trading system, along with the total cost of the system. There is an overall cost of CAD $146.88 for the system. According to the current design, ten peers can be connected to the system with ten different accounts being created. Consequently, if such a system is implemented over a small remote community of ten houses, the cost per peer will be CAD $14.68.
Open-Source Technology: The proposed system design incorporates open-source technology. There are no annual costs or subscription fees associated with the open-source software used in the design. In this way, the proposed system of peer-to-peer energy trading will have zero operating costs.
Private Network: In the designed P2P energy trading system, all transactions are conducted over a local network. Thus, the proposed system is an ideal energy trading solution for remote communities that have no access to the internet.
Energy trading on blockchain: A private Ethereum blockchain is incorporated into the proposed system design. By using this approach, peers can trade energy over a local, decentralized network without having to access the main Ethereum blockchain platform. Through a decentralized, transparent, immutable and tamper-proof structure, they are able to trade energy locally. As an added benefit, all transactions are time stamped and can be tracked easily.
Remote Access: One of the most important characteristics of the proposed system is its HMIs interaction capability. It is intended that the peer can have remote access to the UI and IoT server without being physically present at the site. Peers can then trade energy, monitor operations and control them remotely through this system.
Efficient transaction settlements: In view of the fact that the proposed system is designed and tested for ten peers at first, it has a small ledger. Moreover, a private blockchain is used in the system. Thus, the design allows for fast financial transactions within a period of less than two seconds.
Security: There is a set of security controls in place for the design systems, including SSIDs and passwords, firewalls, secret recovery phrases, MetaMask credentials and a private key used to access the Ethereum wallet. Furthermore, this locally configured system incorporates the entire blockchain security protocol.
Intuitive UI: The proposed system of peer-to-peer energy trading has been designed to have a user-friendly interface. Users do not need to undergo any special training in order to use this system.
Future research guide: Electricity trading and management solutions can be provided as a result of this research, especially in relation to remote communities. An energy trading system based on blockchain can be designed and planned based on the research described above.
System Limitations: Ganache CLI is used in this system, which is designed for use in local environments. Larger or complex systems may not benefit from this. Furthermore, it is not suitable for mining or running on public testnet.
Despite the fact that this study is intended for P2P energy trading on a community level. The work can, however, be extended to cover trade between peers and utility companies.

8. Conclusions

A recent shift in the energy sector from fossil fuels to renewable sources has transformed energy consumers into prosumers. Distributed resources have resulted in the decentralization of the energy market. Certainly, renewable energy sources have significantly influenced the market for conventional electricity. While this is true, it has not been able to capture the traditional electricity market on an overall basis. Inability to obtain a return on investment may be one of the factors contributing to this. As important as it is to have access to distributed generation, it is also crucial to have a platform that facilitates energy trading and generates returns on investments in the renewable energy sector. In countries with ample renewable energy resources, the use of renewables is not fully tapped due to the absence of such platforms. The use of blockchain technology, as well as smart devices, is expected to lead to a revolution in the development of these platforms such as P2P energy trading platforms. It is possible that distributed generation may gain traction by using the P2P energy trading model. It is imperative that distributed generation will gain traction by using the P2P energy trading model. Therefore, the potential for electrification of remote areas may also result from the possibility of obtaining proper returns on energy investment.
This article presents an advanced P2P energy trading platform based on the Ethereum private blockchain and Internet of Things, integrated with an Angular-based UI. We also demonstrated the hardware implementation of our proposed P2P energy trading solution using very few low-cost, low-power, open-source and readily available components as the essential elements of the proposed system. The hardware components include Pi4B and ESP32-S3 as crucial components of the system. Other components include FIDs and a Wi-Fi router. It was necessary to create an experimental setup in order to validate the system design. It appears from the results of the study that the system is suitable for the purpose of carrying out P2P energy trading operations. As well as performing energy transactions, the system is able to perform financial transactions. The proposed system performs data monitoring and display over the IoT server after data acquisition through FIDs. While it maintains digital ledger over the blockchain network, energy efficiency has been demonstrated by this system, as its main server consumes only 2.5 W, the local IoT server consumes 0.6 W, FIDs consume 0.5 W and the communication channel consumes 1.7 W. As a further benefit of the system, the cost of the system is extremely low at CAD $15. Lastly, security features essential for data integrity and security are incorporated into the proposed system.

9. Future Work

In the future, the authors intend to implement this project in remote locations lacking electricity and internet connectivity. Specifically, the project seeks to assist people living in areas without electricity around the globe. We are in the process of adding a feature for auto sale and purchase in addition to the full details of the electrical connections. The future work extensions will also include an increased range of the network. Detailed information will be provided in upcoming publications.

Author Contributions

M.J.A.B.: methodology, software and hardware implementation, data curation, writing—original draft. M.T.I.: conceptualization, resources, supervision, funding acquisition, writing—review and editing. M.J.: co-supervision, writing—review and editing. J.K.: co-supervision, writing—review and editing. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

All the data and supporting material has been cited and referred in references.

Conflicts of Interest

The authors declare no conflict of interest.

Abbreviations

This manuscript uses the following key abbreviations.
P2PPeer-to-Peer
IOTInternet-of-Things
Pi4BRaspberry pi model 4B
MQTTMessage Queuing Telemetry Transport
FIDsField Instrumentation Devices
HTTPHypertext Transfer Protocol
HMIsHuman Machine Interfaces
ESSEnergy Storage System
UIUser Interface
SBCSingle Board Computer
SoCSystem on a Chip
RPCRemote Procedure Call
SSIDService Set Identifier

References

  1. Kim, J.-G.; Lee, B. Automatic P2P Energy Trading Model Based on Reinforcement Learning Using Long Short-Term Delayed Reward. Energies 2020, 13, 20. [Google Scholar] [CrossRef]
  2. Zhang, C.; Wu, J.; Zhou, Y.; Cheng, M.; Long, C. Peer-to-Peer energy trading in a Microgrid. Appl. Energy 2018, 220, 1–12. [Google Scholar] [CrossRef]
  3. Guerrero, J.; Chapman, A.C.; Verbič, G. Decentralized P2P Energy Trading Under Network Constraints in a Low-Voltage Network. IEEE Trans. Smart Grid 2019, 10, 5163–5173. [Google Scholar] [CrossRef] [Green Version]
  4. Liu, Y.; Sun, C.; Paudel, A.; Gao, Y.; Li, Y.; Gooi, H.B.; Zhu, J. Fully Decentralized P2P Energy Trading in Active Distribution Networks with Voltage Regulation. IEEE Trans. Smart Grid 2022. [Google Scholar] [CrossRef]
  5. Zheng, B.; Wei, W.; Chen, Y.; Wu, Q.; Mei, S. A peer-to-peer energy trading market embedded with residential shared energy storage units. Appl. Energy 2022, 308, 118400. [Google Scholar] [CrossRef]
  6. Zhang, M.; Eliassen, F.; Taherkordi, A.; Jacobsen, H.-A.; Chung, H.-M.; Zhang, Y. Demand–Response Games for Peer-to-Peer Energy Trading with the Hyperledger Blockchain. IEEE Trans. Syst. Man Cybern. Syst. 2022, 52, 19–31. [Google Scholar] [CrossRef]
  7. Wu, H.; Peng, Z.; Guo, S.; Yang, Y.; Xiao, B. VQL: Efficient and Verifiable Cloud Query Services for Blockchain Systems. IEEE Trans. Parallel Distrib. Syst. 2022, 33, 1393–1406. [Google Scholar] [CrossRef]
  8. Wang, H.; Xu, C.; Zhang, C.; Xu, J.; Peng, Z.; Pei, J. vChain+: Optimizing Verifiable Blockchain Boolean Range Queries. In Proceedings of the 2022 IEEE 38th International Conference on Data Engineering (ICDE), Kuala Lumpur, Malaysia, 9–12 May 2022; pp. 1927–1940. [Google Scholar] [CrossRef]
  9. Junlakarn, S.; Kokchang, P.; Audomvongseree, K. Drivers and Challenges of Peer-to-Peer Energy Trading Development in Thailand. Energies 2022, 15, 3. [Google Scholar] [CrossRef]
  10. Zhou, K.; Chong, J.; Lu, X.; Yang, S. Credit-Based Peer-to-Peer Electricity Trading in Energy Blockchain Environment. IEEE Trans. Smart Grid 2022, 13, 678–687. [Google Scholar] [CrossRef]
  11. Zafar, B.; Slama, S.B. Energy Internet Opportunities in Distributed Peer-to-Peer Energy Trading Reveal by Blockchain for Future Smart Grid 2.0. Sensors 2022, 22, 21. [Google Scholar] [CrossRef]
  12. Baig, M.J.A.; Iqbal, M.T.; Jamil, M.; Khan, J. IoT and Blockchain Based Peer to Peer Energy Trading Pilot Platform. In Proceedings of the 2020 11th IEEE Annual Information Technology, Electronics and Mobile Communication Conference (IEMCON), Vancouver, BC, Canada, 4–7 November 2020; pp. 402–406. [Google Scholar] [CrossRef]
  13. Baig, M.J.A.; Iqbal, M.T.; Jamil, M.; Khan, J. Peer-to-Peer Energy Trading in a Micro-grid Using Internet of Things and Blockchain. Electronics 2021, 25, 2. [Google Scholar] [CrossRef]
  14. Baig, M.J.A.; Iqbal, M.T.; Jamil, M.; Khan, J. Design and Analysis of an Isolated DC-Microgrid for a Remote Community in Pakistan. In Proceedings of the 2021 IEEE 12th Annual Ubiquitous Computing, Electronics & Mobile Communication Conference (UEMCON), New York, NY, USA, 1–4 December 2021; pp. 712–716. [Google Scholar] [CrossRef]
  15. Baig, J.K.M.J.A.; Iqbal, M.T.; Jamil, M. Design and implementation of an open-Source IoT and blockchain-based peer-to-peer energy trading platform using ESP32-S2, Node-Red and, MQTT protocol. Energy Rep. 2021, 7, 5733–5746. [Google Scholar] [CrossRef]
  16. Baig, M.J.A.; Iqbal, M.T.; Jamil, M.; Khan, J. A Low-Cost, Open-Source Peer-to-Peer Energy Trading System for a Remote Community Using the Internet-of-Things, Blockchain, and Hypertext Transfer Protocol. Energies 2022, 15, 13. [Google Scholar] [CrossRef]
  17. Johnston, S.J.; Cox, S.J. The Raspberry Pi: A Technology Disrupter, and the Enabler of Dreams. Electronics 2017, 6, 3. [Google Scholar] [CrossRef] [Green Version]
  18. Kölling, M. Educational Programming on the Raspberry Pi. Electronics 2016, 5, 3. [Google Scholar] [CrossRef] [Green Version]
  19. James, N.; Ong, L.-Y.; Leow, M.-C. Exploring Distributed Deep Learning Inference Using Raspberry Pi Spark Cluster. Future Internet 2022, 14, 8. [Google Scholar] [CrossRef]
  20. Raspberry Pi 4 Model B—Datasheet. Available online: https://datasheets.raspberrypi.com/rpi4/raspberry-pi-4-datasheet.pdf (accessed on 15 October 2022).
  21. Raspberry Pi News. Available online: https://www.raspberrypi.com/news/raspberry-pi-os-64-bit (accessed on 1 October 2022).
  22. ESP32-S3 Datasheet. Available online: https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf (accessed on 10 November 2022).
  23. ESP32-S3 Introducing the New ESP-32-S3 Board. Available online: https://esp32s3.com/ (accessed on 10 November 2022).
  24. Krichen, M.; Ammi, M.; Mihoub, A.; Almutiq, M. Blockchain for Modern Applications: A Survey. Sensors 2022, 22, 14. [Google Scholar] [CrossRef] [PubMed]
  25. Hammi, M.T.; Hammi, B.; Bellot, P.; Serhrouchni, A. ‘Bubbles of trust: A decentralized blockchain-based authentication system for IoT. Comput. Secur. 2018, 78, 126–142. [Google Scholar] [CrossRef]
  26. Ganache CLI—Documentation. Available online: https://docs.nethereum.com/en/latest/ethereum-and-clients/ganache-cli/ (accessed on 15 October 2022).
  27. Shammar, E.A.; Zahary, A.T.; Al-Shargabi, A.A. A Survey of IoT and Blockchain Integration: Security Perspective. IEEE Access 2021, 9, 156114–156150. [Google Scholar] [CrossRef]
  28. Shammar, E.A.; Zahary, A.T. The Internet of Things (IoT): A survey of techniques, operating systems, and trends. Libr. Hi Tech. 2020, 38, 5–66. [Google Scholar] [CrossRef]
  29. Angular. Available online: https://angular.io/ (accessed on 20 November 2022).
  30. WireDelta. Available online: https://wiredelta.com/10-most-popular-angular-websites-of-2021/ (accessed on 20 November 2022).
  31. MetaMask. Available online: https://metamask.io/ (accessed on 20 November 2022).
  32. Dappuniversity/Marketplace. Available online: https://github.com/dappuniversity/marketplace/blob/master/src/contracts/Marketplace.sol (accessed on 30 October 2022).
  33. BlockChain DApp using Angular. Available online: https://github.com/abhilashahyd/ethdapp (accessed on 16 November 2022).
  34. Chen, J.; Cheng, W. Analysis of web traffic based on HTTP protocol. In Proceedings of the 2016 24th International Conference on Software, Telecomunications and Computer Networks (SoftCOM), Split, Croatia, 22–24 September 2016; pp. 1–5. [Google Scholar] [CrossRef]
  35. CLOUDFLARE. Available online: https://www.cloudflare.com/learning/ddos/glossary/hypertext-transfer-protocol-http/ (accessed on 14 November 2022).
  36. Ganache-CLI-Block-Explorer. Available online: https://github.com/vivekganesan01/ganache-cli-block-explorer (accessed on 19 November 2022).
  37. Ethereum Gas and Fees. Available online: https://ethereum.org/en/developers/docs/gas/ (accessed on 20 November 2022).
Figure 1. An overview of system architecture.
Figure 1. An overview of system architecture.
Electronics 12 00287 g001
Figure 2. Starting Ganache Server.
Figure 2. Starting Ganache Server.
Electronics 12 00287 g002
Figure 3. Angular based User Interface.
Figure 3. Angular based User Interface.
Electronics 12 00287 g003
Figure 4. Basic Hardware Implementation.
Figure 4. Basic Hardware Implementation.
Electronics 12 00287 g004
Figure 5. Experimental Setup.
Figure 5. Experimental Setup.
Electronics 12 00287 g005
Figure 6. System flowchart.
Figure 6. System flowchart.
Electronics 12 00287 g006
Figure 7. (a) Accounts Import (b) User Authentication.
Figure 7. (a) Accounts Import (b) User Authentication.
Electronics 12 00287 g007
Figure 8. MetaMask notification for purchase.
Figure 8. MetaMask notification for purchase.
Electronics 12 00287 g008
Figure 9. My Account Status on UI.
Figure 9. My Account Status on UI.
Electronics 12 00287 g009
Figure 10. Other Peers Buy Energy Status on UI.
Figure 10. Other Peers Buy Energy Status on UI.
Electronics 12 00287 g010
Figure 11. Other Peers Sell Energy Status.
Figure 11. Other Peers Sell Energy Status.
Electronics 12 00287 g011
Figure 12. Local Blockchain Server.
Figure 12. Local Blockchain Server.
Electronics 12 00287 g012
Figure 13. Block details.
Figure 13. Block details.
Electronics 12 00287 g013
Figure 14. Information about blocks.
Figure 14. Information about blocks.
Electronics 12 00287 g014
Figure 15. Details of Energy transaction.
Figure 15. Details of Energy transaction.
Electronics 12 00287 g015
Figure 16. Server status for the Internet of Things.
Figure 16. Server status for the Internet of Things.
Electronics 12 00287 g016
Table 1. Component-specific power requirements.
Table 1. Component-specific power requirements.
Sr. NoHardware ComponentsPower (Watts)
1Raspberry Pi 4 Model B2.5
2ESP32-S30.6
3ESP32-S3, Breadboard, Sensors, Relay, Wires1.1
4Tenda Router (N304 V2)1.7
Table 2. Pricing Information for Hardware Components.
Table 2. Pricing Information for Hardware Components.
Sr. No.Name of Harware ComponentsPrice CAD $
1Raspberry Pi 4 Model B74.45
2ESP32-S320.74
3Relay2.01
4Current Sensors5.25
516 GB SD Card13.14
6Wireless Router16.29
7MiscellaneousResistors, Breadboard, Wires, etc.15
Grand Total146.88
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Baig, M.J.A.; Iqbal, M.T.; Jamil, M.; Khan, J. Blockchain-Based Peer-to-Peer Energy Trading System Using Open-Source Angular Framework and Hypertext Transfer Protocol. Electronics 2023, 12, 287. https://doi.org/10.3390/electronics12020287

AMA Style

Baig MJA, Iqbal MT, Jamil M, Khan J. Blockchain-Based Peer-to-Peer Energy Trading System Using Open-Source Angular Framework and Hypertext Transfer Protocol. Electronics. 2023; 12(2):287. https://doi.org/10.3390/electronics12020287

Chicago/Turabian Style

Baig, Mirza Jabbar Aziz, Mohammad Tariq Iqbal, Mohsin Jamil, and Jahangir Khan. 2023. "Blockchain-Based Peer-to-Peer Energy Trading System Using Open-Source Angular Framework and Hypertext Transfer Protocol" Electronics 12, no. 2: 287. https://doi.org/10.3390/electronics12020287

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop