Simple Blink Example using Raspberry Pi, LED Light and Ethereum (web3 1.0.0)
ganache-cli v6.1.8
Node v8.9.0
npm v5.5.1
web3 v1.0.0-beta.36
onoff v1.1.2
truffle v4.1.13
Before doing anything make sure the breadboard and LED are correctly connected to the Raspberry Pi. Make note of the GPIO pin being used.
Once you have cloned the repo make sure to install the package.json
dependencies. From inside the IoT-Blink directory run:
`npm i`
-
In one terminal window initialise ganache-cli:
ganache-cli
-
In another terminal window change directory to IoT-Blink
-
Navigate to the truffle directory
cd truffle
-
Compile the solidity contracts
truffle compile
-
Migrate the solidity contracts
truffle migrate
-
Copy the contract address, the line printed in the terminal should read:
Blink: ...<contract adddress>
-
Open
blink.js
in any text editor and replace the following line with the LEDs GPIO pin number:var led = new Gpio(<PIN NUMBER>, 'out')
-
Run blink.js, passing the contract address with the address from step 6 in the previous section in place of ADDRESS:
node blink.js ADDRESS
-
In another terminal window run
transaction.js
, replacing the contract address as in the previous step:node transaction.js ADDRESS
-
The LED should begin to blink!