Use a Cryptnox Hardware Wallet smartcard for IOT projects related to blockchain
Crytpnox is a swiss company developing and producing hardware wallets (cold storage) in smart card format.
In this project, we will show how a Cryptnox Hardware wallet smart card can be used to secure the private key for a token minting power meter. It can potentially have an application to projects related to tokenized Kilowatts per hour (kWh) of renewable origin. The solution presented can also have application to any kind of sensor readings.
We are using an Ethereum Virtual Machine compatible blockchain with ERC20 smart contract. The amount of kWh token minted by the device is equivalent to the measurement of kWh production over a period T.
The code of the project is published on the following repository:
GitHub - Cryptnox-IOT-Projects/kWh-Minting-Burning-Meter: Software & Hardware to create a Kilowatts…
Software & Hardware to create a Kilowatts per Hour Meter that mints (production) or burns (consumption) a corresponding…
The hardware required:
- A Cryptnox Hardware Wallet Card (Type BG-1 ). You can purchase a Cryptnox Hardware Wallet SmartCard on Amazon or on the Cryptnox Shop
- A contact smart card reader (shop.cryptnox.com/pages/mini-smartcard-reader)
- A Raspberry Pi Model 3 or 4 with Ubuntu 22.04 installed
- A standard electricity power meter with SO pulse out connectors (standard IEC 62053–31). In our project, we will use a Velleman EMDINO1 rail mount kWh Meter (https://www.velleman.eu/products/view/?country=fr&lang=fr&id=411264)
The device will record electricity production from the SO pulse out reading of the meter.
The device’s core functionality is the following:
- Measure electricity production on a connected wire in kWh over a period of time T
- At the end of each period of time T, the device will perform the following actions:
a) internally reads the total amount of kWh,
b) generate a corresponding “mint” transaction for equivalent tokens of a specific smart contract,
c) perform a digital signature with the Cryptnox Card,
d) broadcast the signed transaction to the chain endpoint,
e) reset the internal kWh reading to zero
Part 1: Connecting The Meter pulse out connectors to the Raspberry Pi
The meter will be connected to pins 2 and 40 of the Pi (pin description below)
The Pi 5v output (pin 2) is connected to the pulse out input connector of the Meter (connector 21). The pulse out output connector of the Meter (connector 20) is connected to a 10 K Ohm resistor, and then to pin 40 (GPIO 21) of the Pi (Note: to avoid “floating” and false pulse detection, it is mandatory to activate the internal pull down resistor on GPIO 40. This has been implemented in our code).
The meter will output an idle low voltage output (T_low), and on each pulse, a 90 ms high voltage output (see diagram below).
The Meter pulse out output will be connected to pin. Each pulse will be recorded by a python script.
In our case, the setup looks like that:
Part 2: Initialize a Cryptnox Hardware Wallet Card
You can either use CryptnoxPro command line software from Cryptnox, or you can use an Iphone (more user friendly):
Download Cryptnox Wallet from the Apple store:
Application for Cryptnox hardware wallet smartcards. Uses NFC for communication Fully Web3 compatible with…
Start application -> scan card -> Initialize card and follow instructions.
Save the public address on Icloud for easy recovery for later.
Part 3: deploy the contract KWHContract.sol to the EVM compatible chain of your choice (We used Rinkeby testnet).
- Go to `https://remix.ethereum.org`, create a new workspace
- Under contracts, rename file as desired, paste code from solidity file from repository into renamed file on remix:
- Compile and Deploy
- In Deployed Contract, find the addMinter function, paste the public address of the Cryptnox Hardware Wallet card and press “Transact”
Part 4: Install and update the Python script on the Raspberry Pi
Install the script from the repository as per the Readme file, and update contract address in line 29 of pulse_monitor.py
Part 5: Start the electricity production and minting process
You can use consumption from the grid for simulation. Execute the script in the console to start the measuring and minting loop.
Dont forget the arg arguments to the python pulse_monitor.py command, <wallet_public_address> <gpio_number>
The console should look like that when it mints tokens:
On etherscan, the minting transaction should appear: