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
edgeregistry
with Admin User
- 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
- See
-
Connect with Raspberry Pi
npm install -g device-discovery-cli
devdisco list --eth
ordevdisco list --wifi
-
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/
- 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)
- 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
updateabi
andbinary
variables with the ones copied aboverpcEndpoint
variable with the RPC Server value shown in Ganache
cd testing
dotnet restore
dotnet run
- Update
RecordTransaction
method 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.json
file 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 device
and select theBlockchainEdge\config\deployment.json
file.- We can also do this using Azure Portal using Set Modules option.
- Copy
device
folder - Update IoT hub leaf device connection string
node app.js
- 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.
-
Remove IoT Edge cache
sudo rm /var/lib/iotedge/cache -f -d -r
sudo rm /var/lib/iotedge/hsm -f -d -r
sudo systemctl restart iotedge
-
Docker debugging
sudo docker exec -it <containerid> bash
sudo docker logs -f <containerid>
sudo docker rm $(sudo docker ps -a -q) -f
sudo docker rmi $(sudo docker images -a -q) -f