Introduction
The architecture of Raspi Connect is structured to integrate seamlessly with both Raspberry Pi hardware and blockchain technology. Here's a breakdown of the core components and how they function together:
Raspberry Pi Setup
GPIO Pins: The Raspberry Pi uses General Purpose Input/Output (GPIO) pins to interact with and control home devices like lights, fans, and other appliances.
Python Listener: A dedicated Python script runs on the Raspberry Pi, listening for events from the blockchain. This script controls the GPIO pins based on the commands received from the smart contract.
Blockchain Integration
Smart Contracts: These are deployed on a lisk network They manage the authentication, authorization, and status tracking of the GPIO pins. The smart contract includes functions to update pin statuses and access controls, and emits events whenever a pin status is updated.
Events: Events are emitted by the smart contract to indicate a change in pin status or access control. These are crucial for the real-time updating of the Raspberry Pi GPIO pins via the Python listener.
Communication Flow
Event Emission: When an authorized user updates a pin status via the blockchain (for instance, turning a light on or off), the smart contract emits an event that includes the device ID, pin number, and new status.
Python Listener: The Python script on the Raspberry Pi listens for these events. Upon detecting an event, the script updates the GPIO pins to reflect the new status, effectively controlling the connected device.
Security and Authentication
Blockchain Security: Leveraging blockchain for controlling IoT devices enhances security by ensuring that all commands are encrypted, immutable, and traceable. This prevents unauthorized access and manipulation.
Smart Contract-Based Authentication: Only authorized users can interact with the smart contract to change pin statuses. This layer of authentication ensures that only legitimate commands are executed by the Raspberry Pi.
Getting Started
Prerequisites
- Node.js 18+
- Python 3+
- Windows 8+ (for simulating GPIO pins)
- Windows Build Tools - Only for Windows (Simulating GPIO pins on Windows)
- Raspberry Pi (for actual GPIO pins)
Steps
This project consists of three main components:
1. Compiling and Deploying Contract
Copy
.env.exampleto.envand fill in the required environment variables.
- Install required dependencies
npm install
- Compile the contract
npx hardhat compile
- Set Private Key to hardhat config variables (For deploying contract to network. Make sure you dont use your primary account)
npx hardhat vars set PRIVATE_KEY
- Deploy the contract
npx hardhat run scripts/deploy.ts --network <network>
2. Starting Client
Copy
client/.env.exampletoclient/.envand fill in the deployed contract address and other required environment variables.
- Install required dependencies
cd client
npm install
- Start the client
npm run dev
Navigate to
http://localhost:3000in your browser to see the client. Connect your wallet and start using the app.Register Device with the contract by clicking the "+ Device" button in the client interface.
Load the control panel with registered device Id by entering device Id and click on arrow button.
3. Setup Contract Event Listener and Rasp Pi GPIO Simulator
Copy
.env.exampleto.envand fill in the contract address and RPC URL.
- Install required dependencies
pip install -r requirements.txt
- Run the event listener
python listener.py
- Enter the registered device Id in previous step when prompted.
Usage
Connect your wallet to the client interface and register a device with the contract.
Load the control panel with registered device Id by entering device Id and click on arrow icon.
Start the event listener in new terminal and enter the registered device Id when prompted.
Use the client interface to turn pins on or off.
The event listener will listen for choosen device events in the contract and simulate/update the GPIO pins on the Raspberry Pi.
Built With
- Hardhat - Ethereum development environment for compiling, testing, deploying, and interacting with smart contracts
- Solidity - Ethereum's smart contract programming language
- Web3.py - Python library for interacting with Ethereum blockchain
- GPIO Simulator - Python library for simulating GPIO pins
- RPi.GPIO - Python library for accessing GPIO pins on Raspberry Pi
- React + Vite - Frontend development environment for building fast and modern web apps
contracts
0xC7d966Cc0E5Ec53940D31cf64426b3198678c181
License
This project is licensed under the MIT License
Built With
- gpio
- hardhat
- rpi.gpio
- simulator
- solidity
Log in or sign up for Devpost to join the conversation.