-
Notifications
You must be signed in to change notification settings - Fork 1
4. Energy transactions
(documentation in progress)
For this iteration of the prototype v0.2, we have:
- a Raspberry Pi connected to a battery (= "Node 1" = "consumer"). This node is monitored by an ACS712-based sensor and a LiPo Fuel Gauge and connected to the channels 2 and 3 of the relay.
- a Raspberry Pi connected to a solar panel and a battery (= "Node 2" = "producer"). This node is monitored by an INA219 sensor and connected to the channels 0 and 1 of the relay.
- a Raspberry Pi controlling the relay, allowing to switch the energy source.
On each node (consumer and producer), the CitizenWatt application, an Ethereum client and the Daisee application are running (see the previous instructions, pages 2 and 3).
In order to allow for energy exchange, additional python scripts are required:
➡ https://github.com/DAISEE/Scripts
Clone the repository on each Raspberry Pi:
$ git clone https://github.com/DAISEE/Scripts.git
-
After connecting the relay to the Raspberry Pi (see the tutorial on Sunfounder Wiki), connect the node 1 energy source to the first channel (= channel 0) and the node 2 energy source to the second channel (= channel 1).
-
Install RPI.GPIO library:
$ pip3 install RPi.GPIO pyyaml
- Run the following script:
$ python3 scripts/server_relay.py
The others nodes can interact with the relay through sockets (port: 15555).
- To interact with the Ethereum blockchain, the web3.py library, a python implementation of web3.js, is used.
$ pip3 install web3
- create the parameter file (
parameters.yml
) from the example and complete it:
Type | Field | Description |
---|---|---|
contracts | ||
daisee | Daisee.sol address on the blockchain | |
token | DaiseeCoin smart-contract address on the blockchain | |
node | url of Ethereum client | |
node | ||
address | Ethereum account | |
accountpswd | Ethereum account password | |
url | url of the monitoring application (should be the same as Ethereum client) | |
id | id of the sensor (on the monitoring app) | |
type | type of node ('C' for consumer, 'P' for producer). | |
login | login for energy monitoring application | |
password | password for energy monitoring application | |
limit | threshold from which the exchange is triggered | |
delta | quantity of energy to buy | |
channel | relay channel | |
fuelgauge | if the battery state of charge is monitored (Boolean) | |
sellers | ||
sellern | part to duplicate, with the Ethereum account and channel of the seller (where n is the seller number) | |
relay | ||
host | Ip of the rapsberry pi controlling the relay | |
port | socket port (15555) |
exemple:
contract:
address: '0xc33179A7f73fCcCe0DED8e613Fcf2688bA385558'
token: '0xdFf8C10F1E64B592cF902e82C948E2ddF9f49aaF'
node: '192.168.0.10'
node:
address: '0x004ec07d2329997267ec62b4166639513386f32e'
accountpswd: 'password1'
url: 'http://192.168.0.10:8080'
sensorId: 1
typ: 'C'
login: 'user'
password: 'password2'
limit: 20
delta: 200
channel: 2
fuelgauge: False
sellers:
seller1:
account: '0x00625a1a269ac76c7c7b98939b5e60916fd41070'
channel: 0
relay:
host: '192.168.0.50'
port: 15555
The script client_interaction.py
allows to update energy data on the Blockchain from data exposed by CitizenWatt API and triggers energy exchanges.
Just run the script:
$ python3 scripts/client_interaction.py
The transactions are displayed on the DAISEE App:
-
To allow energy exchange, the consumer has to have some tokens.
If not, transfer some tokens via the Parity UI (functionTransfer
of the Token contract): -
Moreover, it is necessary that the Daisee contract can transfer these token to the energy producer at the time of the purchase.
- Function
Approve
of the Token contract: - After validation of the transaction, the allowance is updated:
- Function
Note: to avoid to update the allowance before buying energy, the token contract offers the function
approveAndCall
. This function is not yet used in this version of the prototype.
see Issue : DAISEE/Scripts/issues/11
-
Data displayed on the DAISEE App
-
Run the script
$ python3 scripts/client_interaction.py
- Data displayed on the DAISEE App after running the script:
As long as the battery charge is greater than the threshold, Node 1 consumes the energy of its own battery (blocks 728 to 731).
Once the battery charge has fallen below the threshold, Node 1 buys energy (block 732) and consumes power from Node 2 battery (blocks 733 to 735).
The table "Purchased energy" shows the energy consumed compared to the energy purchased.
(to be completed)