Giter VIP home page Giter VIP logo

blockchain-iot-edge's Introduction

From Drones to Solar Farms to Mining in Oilfields, edge computing has become a very important aspect of most IoT Solutions. As these IoT devices gain more intelligence and become more autonomous, creating a decentralized IoT network becomes crucial for maintaining trust and reducing maintenance cost. The goal of this project is to explore the possibilities of using Blockchain to make edge computing more robust and create protocol for a decentralized IoT network.

Azure IoT Edge Smart Contract Module for Blockchain

Azure IoT Edge Smart Contract Module for Blockchain

Prerequisites

Setup

  • Create IoT Hub, IoT Edge Device and Leaf Device in Azure Portal (documentation)

  • Create Azure Container Registry named edgeregistry with Admin User

Install Azure IoT Edge on Linux X64

  • Create a new Ubuntu 16.04 VM and configure IoT Edge device as transparent gateway (documentation)
    • See notes.txt for configuration notes around certificate & edge config values

Install Azure IoT Edge on Linux ARM32 (Raspberry PI)

  • Deploy Azure IoT Edge runtime on Raspberry Pi

  • Connect with Raspberry Pi

    • npm install -g device-discovery-cli
    • devdisco list --eth or devdisco list --wifi
  • Upgrade jessie to stretch

    • sudo apt-get autoremove
    • sudo apt-get clean
  • Generate certificates and make IoT Edge device act as a transparent gateway

    • ./certGen.sh create_edge_device_certificate "piedgecert"
    • sudo systemctl restart iotedge
    • sudo systemctl status iotedge
    • sudo journalctl -u iotedge
    • journalctl -u iotedge --no-pager --no-full
    • Resolving libssl1.0.2 issue
      • sudo apt remove docker-ce
      • dpkg --status libssl1.0.2
      • sudo apt update
      • sudo apt upgrade
      • sudo cat /etc/apt/sources.list
      • cat /etc/os-release
      • uname -m
    • Install nodejs
      • wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-armv7l.tar.xz
      • tar -xvf node-v8.11.3-linux-armv7l.tar.xz
      • cd node-v8.11.3-linux-armv7l.tar.xz
      • sudo cp -R * /usr/local/

Build SmartContract and generate ABI and Binary

  • Start Ganache ganache-cli
  • Open command prompt and navigate to smartcontracts folder
  • truffle compile
  • truffle test .\test\iotedgecontract.js (Make sure the unit tests are passing)
  • solc --abi .\contracts\IoTEdgeContract.sol (Copy ABI)
  • solc --bin .\contracts\IoTEdgeContract.sol (Copy Binary)

Test Smartcontract module code

  • Start Ganache ganache-cli --secure -u 0 -h <raspberry pi IP address>
    • The -u option is to unlock the account, see ganache-cli options for more details.
  • In testing\Program.cs update
    • abi and binary variables with the ones copied above
    • rpcEndpoint variable with the RPC Server value shown in Ganache
  • cd testing
  • dotnet restore
  • dotnet run

Build SmartContract IoT Edge Module

  • Update RecordTransaction method in BlockchainEdge\modules\SmartContractModule\Program.cs
  • Start Docker for Windows on your laptop
  • Login to Azure Container Registry
    • docker login edgeregistry.azurecr.io -u edgeregistry -p <password>
  • In Visual Studio Code, right click on BlockchainEdge\deployment.template.json file and click Build IoT Edge Solution. This will build the container images and push to ACR.

Deploy Smartcontract module

  • In the Azure IoT Hub Devices explorer in Visual Studio Code, right click the edge device, click on Create deployment for edge device and select the BlockchainEdge\config\deployment.json file.
    • We can also do this using Azure Portal using Set Modules option.

Testing Smartcontract module via simulated leaf device

  • Copy device folder
  • Update IoT hub leaf device connection string
  • node app.js

Testing Smartcontract module via thunderboard sensor device

  • Copy device folder
  • Update IoT hub leaf device connection string
  • Start bluetooth on thunderboard
  • sudo node sensor.js
  • Install node-thunderboard-react nodejs package
    • sudo npm install --unsafe-perm
  • Known Issue
    • The IoT edge module code hangs after connecting to the RPC endpoint if ganache-cli is running on Raspberry PI. Test this by connecting to an Azure Ethereum cluster and changing the Environment variables in the Smart Contract Module.

Demo (click on the image to play the video)

Blockchain IoT Edge Demo

Additional Resources

blockchain-iot-edge's People

Contributors

jomit 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.