Giter Club home page Giter Club logo

iot-blink's Introduction

IoT-Blink

Simple Blink Example using Raspberry Pi, LED Light and Ethereum

All sources:

This assumes you have a Raspberry Pi and can access it via a terminal.

1. Install Geth - Linux Release for ARMv7 - https://geth.ethereum.org/downloads/

1.1 Example of getting the file:
    'wget https://gethstore.blob.core.windows.net/builds/geth-linux-arm7-1.6.0-facc47cb.tar.gz'
    (If needed, transfer file to Pi):
     from mac: 'scp ~/Downloads/geth-linux-arm7-1.6.0-facc47cb.tar.gz [email protected]:~'
    (enter password to pi to complete transfer of file).

1.2 ssh back into Pi: ssh [email protected] <- your Pi IP address here 
    then untar (decompress) file
    'cd ~'
    'tar -vxjf geth-linux-arm7-1.6.0-facc47cb.tar.gz'
    then run
    './geth --syncmode=fast console' (Note: Add the --testnet flag if you'd like to sync to Ropsten testnet)
     (‘fast’ option for quick sync… otherwise this will take around 10 days on an average Pi vs. 1 day).
  1. Install NodeJS source: http://thejackalofjavascript.com/getting-started-raspberry-pi-node-js/ Note: can use a 2nd terminal window and get all the way to testing an LED with nodejs, but without Ethereum, while the geth node is syncing.

    2.1 (Update system)
    'sudo apt-get update -y && sudo apt-get upgrade -y'
    
    2.2 Check to see if your pi already has node with:
    'node -v' 
    If not, then download latest node version for arm:
    'wget http://node-arm.herokuapp.com/node_latest_armhf.deb'
    install that bad boy
    'sudo dpkg -i node_latest_armhf.deb'
    test run of node - calls for version, if version present, then you're ready to move on.
    'node -v'
    
  2. Install npm on RPi

'sudo apt-get install npm -y'

  1. Create node project folder:

'mkdir blink'

'cd blink'

'npm init'

  1. In that project folder, install onoff and web3 modules

     5.1 Install onoff
     'npm install onoff --save'
    
     I needed to apply fix to current release of Jessie Raspbian from errors from this command
     source: https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=127939
    
     edit file:
     'sudo nano /usr/include/nodejs/deps/v8/include/v8.h'
     in that file change:
     enum WriteOptions {
         NO_OPTIONS = 0,
         HINT_MANY_WRITES_EXPECTED = 1,
        NO_NULL_TERMINATION = 2,
        PRESERVE_ASCII_NULL = 4,
      };
    
     to this:
     enum WriteOptions {
        NO_OPTIONS = 0,
        HINT_MANY_WRITES_EXPECTED = 1,
        NO_NULL_TERMINATION = 2,
        PRESERVE_ASCII_NULL = 4,
        REPLACE_INVALID_UTF8 = 0
     };
    
     5.2 Install web3
     'npm install web3 --save'
    
  2. Wire up your LED and let's make sure your LED can be blinked by a nodejs program by following these directions: http://thejackalofjavascript.com/raspberry-pi-node-js-led-emit-morse-code/

  3. Let's use the blockchain now.

     7.1 Assuming the geth is completed syncing lets stop the process and restart with rpc.
         './geth --testnet --syncmode=light --verbosity 4 --datadir "/wwws/geth/data" --rpcapi "db,eth,net,web3,personal" console 2>> /wwws/geth/eth.log'
    
     7.2 Run ethtest.js in a separate terminal instance (put that in your blink dir)
         'sudo node ethtest.js'
         needs sudo to control GPIO
    
  4. Load contract in your ethereum-wallet on local computer

     8.1 Use this: https://github.com/ethereum/mist/releases  
     
     8.2 On contract tab, load contract from ethtest.js.  
           Using the existing contract this address will be: 0x9535eb707582edb3317dfdcdb751ce41865005fc (Note: Ropsten testnet address)
           If you deployed your own contract, then use that address.
           The ABI you will need to insert into mist is located in the "blink.js" file.
           
     8.3 Interact with the contract through the wallet by using set function in bottom right of window and set an integer value. 
     
     8.4 Sign the transaction (currently costs around 0.0012 ether) and send it off.
    
     8.5 2 blocks later, you should have a blinking led assuming step 6 worked for you.  Console window of nodejs ethtest.js should also output a blink message. 
    
     8.6 Visit etherscan.io or testnet.etherscan.io to view your transaction in the blockchain.               
    

iot-blink's People

Contributors

souptacular avatar loebelch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.