Skip to content

Commit be378bf

Browse files
committedJul 30, 2020
Detailed instructions and update to License section
1 parent 46f3584 commit be378bf

13 files changed

+312
-4
lines changed
 

‎README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ Decentralized Intelligent Contact Tracing of Animals and Objects (DICTAO) is a s
66

77
DICTAO uses IoT, AI and Blockchain technologies to tackle the spread of infection by animals and objects.
88

9-
109
## Access the entire book
1110

1211
This repository is a tutorial with instructions to build a simple contact tracing application using the DIApp design pattern. The tutorial is part of the Packt book: _"Hands-On Artificial Intelligence for Blockchain: Converging Blockchain and AI to build smart applications for new economies"_.
1312

1413
You can pre-order the book on [Packt website](https://www.packtpub.com/data/hands-on-artificial-intelligence-for-blockchain), [Amazon global website](https://bit.ly/handson-ai-blockchain-amazon-global-github) or [Amazon India website](https://bit.ly/handson-ai-blockchain-amazon-india-github).
1514

16-
## Instructions
17-
15+
Clone this repository in your local machine and follow appropriate instructions.
1816

17+
## Instructions
1918

2019
### Dependencies
2120

@@ -80,7 +79,7 @@ If you have updated your Jusfile successfully, you need to run the following com
8079
just install-dependencies
8180
```
8281

83-
Make sure that you are running this command in the same directory where justfile exists.
82+
Make sure that you are running this command in the same directory where `justfile` exists.
8483

8584
### Running the app
8685

@@ -102,8 +101,22 @@ just run-server
102101
just run-web
103102
```
104103

104+
## Detailed instructions for beginners
105+
106+
If you are a beginner and need help with detailed instructions, you can refer to the detailed manual which includes screenshots for specific Operating Systems:
107+
108+
1. [Ubuntu users](./instructions/linux.md)
109+
110+
2. MacOS users (Coming soon)
111+
112+
3. Windows users (Coming soon)
113+
105114
## License
106115

107116
MIT License
108117

109118
Copyright (c) 2020 Ganesh Prasad Kumble and DICTAO authors
119+
120+
The original source code of the dictao project is available [here](https://github.com/0zAND1z/dictao).
121+
122+
The original Jupyter Notebook of contact tracing model is available [here](https://github.com/madatpython/PRANA/blob/packt/prana_contact_tracing_using_DBSCAN.ipynb).
74.2 KB
Loading

‎images/just-run-client.png

194 KB
Loading

‎images/just-run-server-input.png

128 KB
Loading

‎images/just-run-server.png

44 KB
Loading

‎images/just-run-web.png

19.3 KB
Loading

‎images/moibit-file-history.png

86 KB
Loading

‎images/moibit-location-storage.png

97.3 KB
Loading

‎images/postman-sample.png

103 KB
Loading

‎images/web-dashboard.png

45.4 KB
Loading

‎instructions/linux.md

+289
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
# Instructions for Ubuntu / linux users
2+
3+
PURPOSE: Use this document to setup the DICTAO code repository on your ubuntu / linux machine.
4+
5+
## Ubuntu
6+
7+
Using the Ubuntu 18.04.4 LTS, I have tested the python implementation of the IoT client code, and backend contact tracing API. I have also tested the deployment of the location update proof smart contract on Remix IDE. Lastly, I have also tested the Node.JS implementation of the front-end web dashboard.
8+
9+
To follow the tutorial in Chapter 8, let us understand how to setup the code one step at a time.
10+
11+
### Installing software
12+
13+
**Rust and cargo**
14+
15+
By installing `rust`, we also get `cargo` installed in our system. We use cargo to install the `just` command.
16+
17+
Visit https://rustup.rs/ or use the following command to install rust:
18+
19+
```sh
20+
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
21+
```
22+
23+
**Just**
24+
25+
By using the `just` command, we can use environment variables to define our credentials and safely share the credentials with the processes.
26+
27+
With rust and cargo installed, we can install `just` by simply executing the following command:
28+
29+
```sh
30+
$ cargo install just
31+
```
32+
33+
**Python and pip**
34+
35+
Our IoT sensor client code and the backend API for contact tracing is implemented in Python. So we need the `pip` and `python` commands to install dependencies and run the software.
36+
37+
Just run the following commands to install Python3 and pip:
38+
39+
```sh
40+
$ sudo apt-get install software-properties-common
41+
$ sudo add-apt-repository ppa:deadsnakes/ppa
42+
$ sudo apt-get update
43+
$ sudo apt-get install python3.6
44+
```
45+
46+
If you want to maintain two different versions of Python, you can also use [`pyenv`](https://github.com/pyenv/pyenv) to install Python3.
47+
48+
**Node.JS and npm**
49+
50+
The front end web dashboard is used to perform digital contact tracing. The dashboard is a simple HTML file hosted using an express server. So we need Node.JS and npm.
51+
52+
To install the latest LTS versions of NodeJS and npm, execute these commands:
53+
54+
```sh
55+
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
56+
$ sudo apt-get install -y nodejs
57+
```
58+
59+
**Brave browser**
60+
61+
I recommend you to use the Brave browser to practice this tutorial. Read more about Brave at www.brave.com.
62+
63+
Visit https://brave-browser.readthedocs.io/en/latest/installing-brave.html#linux or use these commands to install the latest version of Brave browser:
64+
65+
```sh
66+
$ sudo apt install apt-transport-https curl
67+
68+
$ curl -s https://brave-browser-apt-release.s3.brave.com/brave-core.asc | sudo apt-key --keyring /etc/apt/trusted.gpg.d/brave-browser-release.gpg add -
69+
70+
$ echo "deb [arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main" | sudo tee /etc/apt/sources.list.d/brave-browser-release.list
71+
72+
$ sudo apt update
73+
74+
$ sudo apt install brave-browser
75+
```
76+
77+
**Postman**
78+
79+
I use Postman to demonstrate the input and output characteristics of the contact tracing API.
80+
81+
Simply visit https://www.postman.com/downloads/ and click on the download button. You may have to select the appropriate version of the download based on the type of Ubuntu OS installed.
82+
83+
**Jupyter Notebook**
84+
85+
In Chapter 8, I have also explained how to train the DBSCAN based contact tracing model. If you would like to practice it on your system locally, install the Jupyter Notebook.
86+
87+
If you are not a AI geek(yet) and want a minimal setup, you can install it using this command:
88+
89+
```sh
90+
$ pip install jupyterlab
91+
```
92+
93+
Once installed, you can visit https://github.com/madatpython/PRANA/blob/packt/prana_contact_tracing_using_DBSCAN.ipynb to practice the tutorial.
94+
95+
### Signing up for services
96+
97+
**Google Maps Platform**
98+
99+
Google Maps Platforms offers a wide range of GPS-based services. We use the geolocation API offered by this platform in our IoT client code to fetch the current latitude and longitude.
100+
101+
Follow these instructions to setup your geolocation API:
102+
103+
1. Signup for a free trial on the Google Cloud Platform [here](https://console.cloud.google.com/freetrial). You may have to enter your debit/credit card details to complete the signup.
104+
105+
2. After successful signup, create a new project [here](https://console.cloud.google.com/projectcreate). You may name the project as `dictao`.
106+
107+
3. Before creating an API key, we need to enable the Geolocation API. Visit the [Google Maps API list](https://console.cloud.google.com/google/maps-apis/api-list) page and click on Geolocation API under **Additional APIs**. Now, click the "ENABLE" button.
108+
109+
4. To confirm if the Geolocation API enabled, visit the API list page again. The Geolocation API should now be listed under **Enabled APIs**.
110+
111+
5. Now, follow [this](https://developers.google.com/maps/premium/apikey/geolocation-apikey#get-key) instruction to get the API key.
112+
113+
6. Once the API key is generated, it is important to protect it from ill-use. You may want to follow [these](https://developers.google.com/maps/premium/apikey/geolocation-apikey#restrict-key) instructions to protect your API by restricting access. Using these instructions, you can limit the requests from your own IP address and limit the scope of the request to Geolocation API.
114+
115+
7. You can now visit the [Credentials page](https://console.cloud.google.com/google/maps-apis/credentials) to copy the API key. We'll need it while configuring our `justfile`.
116+
117+
**MoiBit API**
118+
119+
We use MoiBit to securely store the location history of each sensor.
120+
121+
Follow these instructions to setup your MoiBit API:
122+
123+
1. Visit the [MoiBit signup page](https://account.moibit.io/#/signup) and submit the form
124+
125+
2. Verify your email and log in to MoiBit
126+
127+
3. Visit the [home/dashboard page](https://account.moibit.io/#/home) to access the API key and secret
128+
129+
4. Now, visit the [file explorer page](https://account.moibit.io/#/fileexplorer) and create a new folder by clicking on the "New folder" button. Now, enter the folder name as **dictao** and click on the submit button.
130+
131+
5. We will be using this folder to store the location history of one or more sensors and use it to perform contact tracing
132+
133+
**Infura**
134+
135+
We use Infura to access the Ethereum Kovan testnet.
136+
137+
Follow these instructions to setup your Infura account:
138+
139+
1. Visit the Infura signup page [here](https://infura.io/register) and submit the form
140+
141+
2. You may have to verify your email before logging in to Infura
142+
143+
3. Visit the [dashboard](https://infura.io/dashboard/ethereum) and click on "CREATE NEW PROJECT" button
144+
145+
4. You can enter the name as **dictao** and press "CREATE" button
146+
147+
5. Now, you are automatically redirected to your newly created project. Your **Project ID** can be found in the same page. We'll need it while configuring the `justfile`.
148+
149+
**Metamask**
150+
151+
Finally, we need to create an ethereum account and designate it uniquely for each sensor. For the sake of simplicity, I recommend using Metamask to create ethereum wallets and export their wallet address and private key.
152+
153+
Follow these instructions on your brave browser:
154+
155+
1. Visit the [Metamask download page](https://metamask.io/download.html)
156+
157+
2. Click on the Brave browser icon or visit [this](https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en) page
158+
159+
3. Click on the "Add to brave" button. You'll be asked to confirm again by clicking the "Add extension" button
160+
161+
4. You'll now be redirected to your local web page of the MetaMask. Click on "Get started" button.
162+
163+
5. Now, click on "Create a Wallet" to create a new Ethereum wallet
164+
165+
6. You may choose to share your usage data by clicking on "I agree" button
166+
167+
7. Enter a strong password and confirm it again. You may have to accept the terms and coniditions before clicking on "Create" button.
168+
169+
8. Follow the instructions suggested in the next screen "Secret Backup Phrase"
170+
171+
9. After backing up your seedphrase, you need to click on "Account 1" to copy the wallet address. We need this address while configuring our `justfile`.
172+
173+
10. Right next to the "Account 1", you can click on "Account details" option from the dropdown menu and click on the "Export Private Key" button.
174+
175+
11. Type your password and copy your account's private key. We also need this while configuring our `justfile`.
176+
177+
**NOTE:** You need to maintain enough balance to run the tutorial. Visit https://faucet.kovan.network/ and authenticate yourself with GitHub to receive one Kovan Ether (KETH).
178+
179+
### Deploying your smart contract
180+
181+
Each time a sensor updates its location on MoiBit, we need to maintain a proof of it on a transparent ledger accessible to everyone. In this tutorial, we achieve this using a smart contract on the Ethereum Kovan testnet.
182+
183+
**NOTE:** For simplicity, I recommend you to use the smart contract that has been already deployed by me on the Kovan testnet. The address of the smart contract is `0x79217e504A28ABCd30D2E90E2C99334FA2e9Fb19`. You can visit [Etherscan](https://kovan.etherscan.io/address/0x79217e504A28ABCd30D2E90E2C99334FA2e9Fb19) to review all the transactions committed by the sensor for each successful location history update made in MoiBit.
184+
185+
If you are interested in venturing out and using your own contract, you may use the [Remix IDE](https://remix.ethereum.org/) to deploy the smart contract and populate enough data required to perform contact tracing:.
186+
187+
### Configuring your justfile
188+
189+
If you apply the credentials from the previous section in the respective export command, it'll probably look like this:
190+
191+
```yaml
192+
export GMAPS_API_KEY := "ABCDEFGHIJKL..."
193+
export MOIBIT_API_KEY := "ABCDEFGHIJKL..."
194+
export MOIBIT_API_SECRET := "VERYLONGSTRING..."
195+
export WEB3_INFURA_PROJECT_ID := "ABCD..."
196+
export PROOF_SMART_CONTRACT_ADDRESS := "0x79217e504A28ABCd30D2E90E2C99334FA2e9Fb19"
197+
export WALLET_PRIVATE_KEY := "LONGSTRING...."
198+
export WALLET_ADDRESS := "0xWALLETADDRESS"
199+
200+
run-client:
201+
python iot-client-code/python/main.py
202+
203+
run-web:
204+
cd frontend-tracking-dashboard && node index.js
205+
206+
run-server:
207+
python backend-contact-tracing/server.py
208+
209+
install-dependencies:
210+
pip install --user -r requirements.txt
211+
cd frontend-tracking-dashboard && npm install
212+
```
213+
214+
We are now ready to run the tutorial and have some fun!
215+
216+
### Installing dependencies
217+
218+
First things first, we need to install all the dependencies used by our Python and Node implementations. So, you'll need to execute the following just command:
219+
220+
```sh
221+
$ just install-dependencies
222+
```
223+
224+
This will automatically install all the pip and npm dependencies so that you don't have to.
225+
226+
### Running the IoT client code
227+
228+
It all starts when an sensor updates its latest location to MoiBit. We can check this out by running:
229+
230+
```sh
231+
$ just run-client
232+
```
233+
234+
You will be able to observe similar output as follows:
235+
![just run-client](./../images/just-run-client.png)
236+
237+
When you visit the **dictao** folder in MoiBit's file explorer page, you should be able to view a new file as shown below:
238+
![moibit location updated](./../images/moibit-location-storage.png)
239+
240+
When you select the "Version" under the dropdown menu of the file, you can observe the hash same hash as captured in the terminal as follows:
241+
![moibit file hash](./../images/moibit-file-history.png)
242+
243+
The proof of this location history update is committed to the Ethereum Kovan testnet. We can verify this by opening the link mentioned at the bottom of the console output shown in the first screenshot. The file hash has been inputted in the transaction as shown below:
244+
![etherscan transaction](./../images/etherscan-transaction-input-data.png)
245+
246+
### Running the backend contact tracing API
247+
248+
You need to run the above commands from several sensors having distinct wallet address and location history. I have reduced your effort here by populating the location history of more than 10 sensors in the smart contract address mentioned in the justfile.
249+
250+
So, let us run the contact tracing API using the following command:
251+
252+
```sh
253+
$ just run-server
254+
```
255+
256+
If your console displays the following output, the server has been initiated properly:
257+
![run-server](../images/just-run-server.png)
258+
259+
Let us now use Postman to test the API with sample inputs as follows:
260+
![postman sample query](./../images/postman-sample.png)
261+
As you can observe from the above screenshot, the API received an "id" as an input and returned a response body consisting of all the potentially infected IDs. This is made possible with the help of the DBSCAN algorithm explained in Chapter 8.
262+
263+
Meanwhile, you can observe the following update in your console:
264+
![just run-server input](./../images/just-run-server-input.png)
265+
266+
From the above screenshot, we can understand that the API is downloading the entire dataset from MoiBit, performing contact tracing and returning a list of infected IDs back to the client with the HTTP 200 response code.
267+
268+
### Running the web dashboard
269+
270+
The API must be accessed via a simple web dashboard to inquire for potential contacts / infections made by the given ID.
271+
272+
Let us launch the dashboard by running the following command:
273+
274+
```sh
275+
$ just run-web
276+
```
277+
278+
If all the dependencies are installed properly, you should be able to observe the following output from the console:
279+
![just run-web](./../images/just-run-web.png)
280+
281+
Let us now visit http://localhost:3000/ and enter the same sensor wallet address `0xaF7087D93B08Ea1f3866E9D2Fc7d216Fe98a8E8E`. We will obtain the results in the tabulated format as follows:
282+
![web dashboard](./../images/web-dashboard.png)
283+
From the above screenshot, we have a functional contact tracing dashboard that can search for potential infections associated with a suspected sensor.
284+
285+
This summarizes how to run the DIApp on your Ubuntu linux machine.
286+
287+
## Got any other Linux distros?
288+
289+
If you would like to document the instructions for other linux distributions, please fork the [dictao](https://github.com/0zAND1z/dictao) repository and submit your PR!

‎instructions/macos.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Instructions for MacOS users
2+
3+
Work In Progress. Visit back in a while!

‎instructions/windows.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Instructions for Windows 10 users
2+
3+
Work In Progress. Visit back in a while!

0 commit comments

Comments
 (0)
Please sign in to comment.