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.
-
Install Visual Studio Code
-
Install Azure IoT Toolkit for VSCode extension
-
Install Azure IoT Edge for VSCode extension
-
Install Docker for Windows
-
Install .NET Core SDK
-
Install Truffle
-
Install ganache-cli
-
Install Solidity Compiler and set it on your PATH
-
Create IoT Hub, IoT Edge Device and Leaf Device in Azure Portal (documentation)
-
Create Azure Container Registry named
edgeregistrywith Admin User
- Create a new Ubuntu 16.04 VM and configure IoT Edge device as transparent gateway (documentation)
- See
notes.txtfor configuration notes around certificate & edge config values
- See
-
Connect with Raspberry Pi
npm install -g device-discovery-clidevdisco list --ethordevdisco list --wifi
-
sudo apt-get autoremovesudo 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 iotedgesudo systemctl status iotedgesudo journalctl -u iotedgejournalctl -u iotedge --no-pager --no-full- Resolving libssl1.0.2 issue
sudo apt remove docker-cedpkg --status libssl1.0.2sudo apt updatesudo apt upgradesudo cat /etc/apt/sources.listcat /etc/os-releaseuname -m
- Install nodejs
wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-armv7l.tar.xztar -xvf node-v8.11.3-linux-armv7l.tar.xzcd node-v8.11.3-linux-armv7l.tar.xzsudo cp -R * /usr/local/
- Start Ganache
ganache-cli - Open command prompt and navigate to
smartcontractsfolder truffle compiletruffle 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)
- 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.csupdateabiandbinaryvariables with the ones copied aboverpcEndpointvariable with the RPC Server value shown in Ganache
cd testingdotnet restoredotnet run
- Update
RecordTransactionmethod inBlockchainEdge\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.jsonfile and clickBuild IoT Edge Solution. This will build the container images and push to ACR.
- In the Azure IoT Hub Devices explorer in Visual Studio Code, right click the edge device, click on
Create deployment for edge deviceand select theBlockchainEdge\config\deployment.jsonfile.- We can also do this using Azure Portal using Set Modules option.
- Copy
devicefolder - Update IoT hub leaf device connection string
node app.js
- Copy
devicefolder - 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.
-
Remove IoT Edge cache
sudo rm /var/lib/iotedge/cache -f -d -rsudo rm /var/lib/iotedge/hsm -f -d -rsudo systemctl restart iotedge
-
Docker debugging
sudo docker exec -it <containerid> bashsudo docker logs -f <containerid>sudo docker rm $(sudo docker ps -a -q) -fsudo docker rmi $(sudo docker images -a -q) -f

