---
# System prepended metadata

title: " \nBig Data Analysis and Augmented Reality Platform\n  "

---

<center>
  <h1> 
Big Data Analysis and Augmented Reality Platform
  </h1>
</center>




[TOC]

---

# Documentation

**Refer to our main documentation [here](https://github.com/cinnamon-rolling/capstone-norgren/tree/main/documentation) for full description.**

# System Components
## AWS System Architecture 
![aws system archi](https://i.imgur.com/qTaLGIV.png)

## Frontend
**Framework**: ReactJS

**Language**: Javascript, HTML/CSS

## Backend
**Framework**: Django

**Language**: Python

## Database
**Relational Database**: MySQL

## Hardware
![](https://i.imgur.com/7wpDQTL.png)

**Microcontroller**: ESP32 module (for wireless connections), Arduino (for wired connections)

**Microcomputer**: Raspberry Pi

# Initial Setup

## Software setup

**Clone the repo**

```bash
git clone https://github.com/cinnamon-rolling/capstone-norgren
```



## Hardware setup

For each micro-environment, our proposed solution would require hardware components list below.
<table>
<tr>
    <th>Component Name</th>
    <th>Amount</th>
</tr>
<tr>
    <td>DHT11 Humidity & Temperature Sensor</td>
    <td>12</td>    
</tr>
<tr>
    <td>Capacitive Soil Moisture sensor</td>
    <td>12</td>
</tr>
<tr>
    <td>Gravity: Analog pH meter</td>
    <td>1</td>
</tr>
<tr>
    <td>Gravity: Analog Electrical Conductivity Sensor V2 (K=1)</td>
    <td>1</td>
</tr>
<tr>
    <td>HC-SR04 Ultrasonic Sensor</td>
    <td>1</td>    
</tr>
<tr>
    <td>VEML6070 UV Light Sensor</td>
    <td>1</td>
</tr>
<tr>
    <td>Photosensitive Resistance Sensor</td>
    <td>1</td>
</tr>
<tr>
    <td>AS7341 - Spectral Sensor Eval Kit</td>
    <td>1</td>
</tr>
<tr>
    <td>Arduino Uno</td>
    <td>1</td>
</tr>
<tr>
    <td>Arduino Mega 2560</td>
    <td>1</td>
</tr>
<tr>
    <td>ESP32-WROVER</td>
    <td>2</td>
</tr>
<tr>
    <td>Raspberry Pi 4B</td>
    <td>1</td>
</tr>
</table>

### PH-EC Subsystem
This subsystem contains [Gravity: Analog pH](https://wiki.dfrobot.com/Gravity__Analog_pH_Sensor_Meter_Kit_V2_SKU_SEN0161-V2) meter and [Gravity: Analog Electrical Conductivity Sensor V2 (K=1)](https://wiki.dfrobot.com/Gravity__Analog_Electrical_Conductivity_Sensor___Meter_V2__K%3D1__SKU_DFR0300). We use [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf) to wirelessly transmit sensor readings.

**(1) Sensor Connection**
![](https://imgur.com/eJyQzov.png)

**(2) ESP32 Compile**

Compile this [code](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/Arduino%20Code/PH%2CEC/Subsystem1/Subsystem1.ino) to ESP32 module. Make sure you changed following user settings in this code. 
<table>
<tr>
    <th>Variable</th>
    <th>Value Example</th>
    <th>Description</th>
</tr>
    <td>ssid</td>
    <td>SINGTE-LA19A</td>
    <td>Your network name</td>
<tr>
    <td>wifi_password</td>
    <td>123456789</td>
    <td>Password of network</td>
</tr>
<tr>
    <td>mqtt_server</td>
    <td>192.168.1.113</td>
    <td>IP address of the Raspberry Pi</td>
</tr>
<tr>
    <td>mqtt_username</td>
    <td>password</td>
    <td>Username of Mosquitto broker</td>
</tr>
<tr>
    <td>mqtt_password</td>
    <td>password</td>
    <td>Password of Mosquitto broker</td>
</tr>
</table>

**(3)Raspberry Pi**

Install software broker/server

```bash=
sudo apt-get install mosquitto
```

Install command-line client for debugging

```bash=
sudo apt-get install mosquitto-clients -y
```

Open Mosquitto MQTT broker configuration

```bash=
sudo nano /etc/mosquitto/mosquitto.conf
```

Change the file to the following.
```
pid_file /var/run/mosquitto.pid

persistence true
presistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

allow_anonymous false
password_file /etc/mosquitto/pwfile
listener 1883
```
Edit username and password

```bash=
sudo mosquitto_passwd -c /etc/mosquitto/pwfile password
```

- The last "password" means that the username = "password"
  ![](https://i.imgur.com/XHKOmw6.png)
- Then reset password = "password" when prompted

Check status of mosquitto

```bash=
sudo systemctl status mosquitto
```

It should look something like this:
![](https://i.imgur.com/ngEU03h.png)

Else, can try to restart as such:

```bash=
sudo systemctl restart mosquitto
```

Or, enable MQTT broker at boot:

```bash=
sudo systemctl enable mosquitto
```

Start Mosquitto on RPi:

```bash=
sudo mosquitto
```

Install Python MQTT language bindings

```bash=
sudo pip install paho-mqtt
```
Create [*<tr>subscriber.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/subscriber_ph_ec.py) to subscribe to MQTT data. Create [*<tr>main.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/main_ph_ec.py) to receive the data from ESP32.
```bash=
$ sudo nano subscriber.py
$ sudo nano main.py
```

Run *<tr>main.py</tr>* with
```bash=
$ sudo nano python main.py
```
There should be a status `200` printed if request for ec2 is successfully made.

### Ultrasonic-VEML-LightIntensity Subsystem ###
This subsystem contains [HC-SR04 Ultrasonic Sensor](http://web.eece.maine.edu/~zhu/book/lab/HC-SR04%20User%20Manual.pdf), [VEML6070 UV Light Sensor](https://learn.adafruit.com/adafruit-veml6070-uv-light-sensor-breakout) and [Photosensitive Resistance Sensor](https://5.imimg.com/data5/EU/QT/MY-1833510/arduino-photoresistor-detection-photosensitive-light-sensor.pdf). We use [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf) to wirelessly transmit sensor readings.

**(1) Sensor Connection**

![](https://imgur.com/6GYUEma.png)

**(2) ESP32 Compile**

Compile this [code](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/Arduino%20Code/Ultrasonic%2CVEML%2CLightIntensity/Subsystem4/Subsystem4.ino) to ESP32 module. Make sure you changed user settings in this code as previous subsystem. 

**(3)Raspberry Pi**

We assume you have set up the mosquitto environment with PH-EC Subsystem.Start Mosquitto on RPi:

```bash=
sudo mosquitto
```

Create [*<tr>subscriber.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/subscriber_ultra.py) to subscribe to MQTT data. Create [*<tr>main.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/main_ultra.py) to receive the data from ESP32.
```bash=
$ sudo nano subscriber.py
$ sudo nano main.py
```

Run *<tr>main.py</tr>* with
```bash=
$ sudo nano python main.py
```
There should be a status `200` printed if request for ec2 is successfully made.

### DHT-SM Subsystem
This subsystem contains [DHT11 Humidity & Temperature Sensor](https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf) meter and [Capacitive Soil Moisture sensor](https://wiki.dfrobot.com/Capacitive_Soil_Moisture_Sensor_SKU_SEN0193). We use [Arduino Mega 2560](http://eprints.polsri.ac.id/4598/8/File%20VIII%20%28Lampiran%29.pdf) to transmit sensor readings with USB connection.

**(1) Sensor Connection**


![](https://imgur.com/BjmgrSO.png)

**(2) Arduino Compile**

Compile this [code](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/Arduino%20Code/Ultrasonic%2CVEML%2CLightIntensity/Subsystem4/Subsystem4.ino) to Arduino Mega module. 

Open the serial moniter and choose Baud rate of 9600. Enter "s" to serial and you should be able to see one reading of temperature, humidity and soil moisture.

**(3)Raspberry Pi**

Connect Arduino Mega module to RPi with USB wire. We assume you have already set up serial communication on RPi. If you have not set up such, refer to [Full Documentation](https://hackmd.io/XOfCbKiLQDiCOAW7eqN_ow?both#Sensors-under-Queuing-Telemetry-TransportMQTT) under *Hardware* --- *Sensors under Arduino serial communication* --- *Serial connection between Arduino development board and Raspberry Pi* for details.

After establishd serial connection between Arduino microcontroller and RPi,  create [*<tr>DHT_SM.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/DHT_SM.py) to test the serial connection. 

Run *<tr>DHT_SM.py</tr>* with

<code>$ sudo nano python DHT_SM.py</code>

If there is no error, you should be able to see updated value of temperature, humidity and soil moisture index on RPi terminal.

### AS7341 spectral sensor
This subsystem contains [AS7341 - Spectral Sensor Eval Kit](https://ams.com/documents/20143/36005/AS7341_UG000400_5-00.pdf/dfc1370f-4781-b270-1102-e50f0f0b0d1c). We use [Arduino UNO](https://www.farnell.com/datasheets/1682209.pdf) to transmit sensor readings with USB connection.

**(1) Sensor Connection**


![](https://imgur.com/8OwNFTT.png)

**(2) Arduino Compile**

Compile this [code](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/Arduino%20Code/spectrum/spectral_sensor/spectral_sensor.ino) to Arduino Mega module.

Open the serial moniter and choose Baud rate of 9600. Enter "s" to serial and you should be able to see one reading of spectral from channel F1 to F4, with Clear and NIR values. Enter "w" to serial and you should be able to see one reading of spectral from channel F5 to F8, with Clear and NIR values. 

**(3)Raspberry Pi**

Connect Arduino Mega module to RPi with USB wire. We assume you have already set up serial communication on RPi. If you have not set up such, refer to [Full Documentation](https://hackmd.io/XOfCbKiLQDiCOAW7eqN_ow?both#Sensors-under-Queuing-Telemetry-TransportMQTT) under *Hardware* --- *Sensors under Arduino serial communication* --- *Serial connection between Arduino development board and Raspberry Pi* for details.

After establishd serial connection between Arduino microcontroller and RPi,  create [*<tr>spectrum.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/spectrum.py) to test the serial connection. 

Run *<tr>spectrum.py</tr>* with

<code>$ sudo nano python spectrum.py</code>

If there is no error, you should be able to see updated value of spectral on RPi terminal.

### Integration of subsystems

**(1) Integration of *<tr>subscriber.py</tr>***

When 2 ESP32 transmit data to RPi together, we need to integrate the corresponding *<tr>subscriber.py</tr>* into one file. If there is any new sensor coming with MQTT in the future, the *<tr>subscriber.py</tr>* should always been integrated.Here is an example of integrate two subsystems.

Add in all the communication topics

```python=
MQTT_TOPIC_PH = "tank/ph"
MQTT_TOPIC_EC = "tank/ec"
MQTT_TOPIC_UV = "micro/uv"
MQTT_TOPIC_LS = "micro/ls"
MQTT_TOPIC_WL = "micro/wl"
```

Under function *<tr>on_connect</tr>*, make sure all the topics have been subscibed.
```python=
if _type == "PH":
    client.subscribe(MQTT_TOPIC_PH)
elif _type == "EC":
    client.subscribe(MQTT_TOPIC_EC)
elif _type == "UV":
    client.subscribe(MQTT_TOPIC_UV)
elif _type == "WL":
    client.subscribe(MQTT_TOPIC_WL)
elif _type == "LS":
    client.subscribe(MQTT_TOPIC_LS)
```

**(2) Integration of *<tr>main.py</tr>***

We have been using serial communication and MQTT communication at the same time. Therefore, we need to integrate their *<tr>main.py</tr>* file to upload all the sensor readings together and addin the backend API to upload readings to the AWS database. 

Here is the integrated [*<tr>main.py</tr>*](https://github.com/cinnamon-rolling/capstone-norgren/blob/lxy-hardware/hardware/RPI%20code/main.txt).

# How to Run

**To access the website**

Currently, it is hosted on an AWS ec2 instance `http://ec2-3-94-82-103.compute-1.amazonaws.com:3000`

**To run the website on a local instance**, run in the terminal:
```bash=
cd norgren-fe
npm install
npm start
```