Skip to content

Commit

Permalink
Merge pull request #33 from wizzdev-pl/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
damian-kurek-wizzdev authored Sep 8, 2021
2 parents 45983b5 + 42b39a5 commit d30fb98
Show file tree
Hide file tree
Showing 23 changed files with 723 additions and 259 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ terraform/terraform
terraform/terraform.exe

#JSON cloud configuration file
MicroPython/src/aws_config.json
MicroPython/src/kaa_config.json
MicroPython/src/config.json
MicroPython/src/thingsboard_config.json
MicroPython/src/*.json

# Python cache files
*.pyc
Expand Down
Binary file added Blynk/Blynk_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions Blynk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Set up account and device on Blynk cloud platform
The instruction walks you through the process of creating your own IoT device in just a few steps.

An example web dashboard that might be created can look like this:
![Example dashboard](Blynk_dashboard.png "KaaIoT dashboard")

## What is Blynk
[Blynk](https://blynk.io/) is a cloud service provider allowing for building and managing connected hardware: device provisioning, sensor data visualization, remote control with mobile and web applications, over-the-air firmware updates and much more.

## Installation

### Install requirements

After you've created virtual environment, your current directory should be "iot-starter"

```
pip install pyserial cryptography click future pyelftools setuptools
pip install -r Blynk/requirements.txt
```

## Set up Blynk account

### 1. Create account

First, you need to create an account on Blynk cloud website: [blynk.cloud](https://blynk.cloud/dashboard/register). Follow standard registration procedure providing your email and then activating the account.

### 2. Creating template and your device

After you first log in into your new account on Blynk,Console you'll be probably prompted with a quickstart device. Please close the window as we're going to do it manually.

#### **Template**:

Template will be used for creating your new IoT-Starter device.

1. On the left side pane search for **"Templates"** option.
2. Click on **"+ New Template"** with the name and description of your choice. Make sure to use hardware **"ESP32"** and connection type **"WiFi"**. After creating the template you can modify it further adding an image, metadata etc.
3. Now you need to create two **"Datastreams"** that are responsible for accepting telemetry data (temperature and humidity) from our device. To do that go to:<br>
**"Datastreams" --> "+ New Datastream" --> "Virtual Pin"<br>**
Please make two virtual pin datastreams for temperature and humidity. **Please note** which pin is responsible for each telemetry type (only number matters, so if you're assigning **V0** to temperature, the pin responsible for the temperature telemetry is no. **0**). Make sure that the **"Data Type"** is set to **"Double"**. You can also add **"Units"** to the pins (Celsius for the temperature and percentage for the humidity) - it is optional though. Please also adjust the **min** and **max** value for each pin (0 - 100 for the humidity and for example 10 - 40 for the temperature) as well as check the **"Thousands seperator"** option.
4. After creating both virtual pins you can set up a web dashboard after clicking **"Web dashboard"** option. (**"Mobile dashboard"** can be only created in **"Blynk IoT"** mobile app.)
5. Save the changes made to the template.

#### **Device**:

Device will be created from already created template, so all you need to do is:

1. Click on the left side pane **"Search"** --> **"+ New Device"** --> **"From template"**
2. Select your template and give some meaningful name to your device.
3. Click on the created device and go to **"Device info"** and on the right side look for **"BLYNK_AUTH_TOKEN"**. It should look like this:<br>
```
#define BLYNK_AUTH_TOKEN "<long_sequence_of_random_characters>";
```
Copy this long sequence as you will need it in a moment.

After all steps above you should have saved three things:
- Virtual pin for temperature
- Virtual pin for humidity
- Device auth token
1 change: 1 addition & 0 deletions Blynk/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r ./../MicroPython/requirements.txt
Binary file modified KAA/Kaa_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 2 additions & 70 deletions KAA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,11 @@ An example dashboard that might be created can look like this:
![Example dashboard](Kaa_dashboard.png "KaaIoT dashboard")

## What is KaaIoT
KaaIoT is a cloud service provider allowing for device management, data collection and visualization. You can create a powerful dashboard in a matter of seconds. It's free of charge with a limit of up to 5 devices.

## Requirements

### Python 3, PIP
Python can be downloaded from this [website](https://www.python.org/downloads) (in case of using [Anaconda environment](https://www.anaconda.com/products/individual), please skip this part and refer to "**Installation**" section). The Python version required for this project is: either 3.6 or 3.7 (preferably). Please follow installation instructions from their website.
After installation, you can check if it is installed correctly by typing the following commands in your terminal:

* Linux
```bash
python3 --version
pip3 --version
```
If python3 is not recognized, try "python"

* Windows:
```bash
python --version
pip --version
```
[KaaIoT](https://www.kaaiot.com/) is a cloud service provider allowing for device management, data collection and visualization. You can create a powerful dashboard in a matter of seconds. It's free of charge with a limit of up to 5 devices.

## Installation

### 1. Create virtual environment:
First, you need to create virtual environment (either with python venv module or anaconda-python):

Note, that **"ENV_NAME"** is the name of the environment you’re creating.

Enter main directory of the project (iot-starter):
```bash
cd iot-starter
```

* For anaconda (either in terminal - Linux or anaconda prompt - Windows):
```
conda create --name ENV_NAME python=3.7 pip
```

* For venv:
* Linux:
```
python3 -m venv ENV_NAME
```

* Windows:
```
python -m venv ENV_NAME
```

Next, you should activate it. This step is platform dependent:
#### Windows
* For anaconda:
```
conda activate ENV_NAME
```

* For venv:
```
ENV_NAME/Scripts/activate.bat
```

#### Linux/ Mac OS
* For anaconda:
```
conda activate ENV_NAME
```

* For venv:
```
source ENV_NAME/bin/activate
```

### 2. Install requirements
### Install requirements

After you've created virtual environment, your current directory should be "iot-starter"

Expand Down
24 changes: 19 additions & 5 deletions MicroPython/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Open the project MicroPython with PyCharm and mark *src* and *ulib_mocks* direct
## Cloud service provider:
### - KAA
### KAA
Make sure that your KAA cloud is configured. For more information please go to README in "KAA" directory [here](../KAA/README.md).
By now, you should have four things:
Expand All @@ -48,15 +48,19 @@ By now, you should have four things:
- username
- password
### - AWS
---
### AWS
Make sure that your AWS cloud is configured. For more information please go to
README in "terraform" directory [here](../terraform/README.md).
If you already have configured AWS infrastructure, make sure that:
- terraform exists either in ".terraform" directory or installed through the package manager
- you have configured ssh connections with AWS (aws configure)
### - ThingsBoard
---
### ThingsBoard
Make sure your ThingsBoard server is configured. For more information please go to README in "ThingsBoard" directory [here](../ThingsBoard/README.md)
Now we will make use of credentials we have saved in previous steps:
Expand All @@ -83,8 +87,18 @@ You'll need to also provide new credentials for your device:
After you execute the script, you should see "Provisioning successful!" message. If something went wrong, please try again, validate your provision keys and make sure that the device you're trying to register is not already taken (both client ID and its name).
---
### Blynk
Make sure that your Blynk cloud is configured. For more information please go to README in "Blynk" directory [here](../Blynk/README.md).
By now, you should have three things:
- Virtual pin for temperature
- Virtual pin for humidity
- Device auth token
### Basic Setup of the ESP32
## Basic Setup of the ESP32
To set up a new board or flash the old one. <br>
Make sure that your cloud is configured and in case of using **AWS** make sure that your computer has AWS credentials.
Expand Down Expand Up @@ -112,7 +126,7 @@ After finding the correct port, execute:
```bash
python scripts/upload_all.py -p <port> -c <cloud> -s <sensor>
```
where \<cloud\> is your chosen cloud service provider (KAA, AWS or THINGSBOARD).<br>
where \<cloud\> is your chosen cloud service provider (KAA, AWS, THINGSBOARD or BLYNK).<br>
where \<sensor\> is your currently used sensor (DHT11, DHT22 or BME280). Defaults to DHT22.<br>
After flashing the board please reset it using button EN button.

Expand Down
43 changes: 35 additions & 8 deletions MicroPython/scripts/cloud_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
from common.cloud_providers import Providers
from common.utilities import file_exists

KAA_CONFIG_SRC_PATH = 'src/kaa_config.json'
THINGSBOARD_CONFIG_SRC_PATH = 'src/thingsboard_config.json'
CLOUD_CONFIG_PATH = "src/{}_config.json"


def set_credentials(cloud):
"""
Asks user for credentials for cloud similar to "awscli"
"""
cloud_config_path = CLOUD_CONFIG_PATH.format(cloud.lower())
if cloud == Providers.KAA:
if file_exists(KAA_CONFIG_SRC_PATH):
with open(KAA_CONFIG_SRC_PATH, 'r', encoding='utf8') as infile:
if file_exists(cloud_config_path):
with open(cloud_config_path, 'r', encoding='utf8') as infile:
config = json.load(infile)
else:
config = {}
Expand All @@ -39,12 +39,12 @@ def set_credentials(cloud):
if password:
config['kaa_password'] = password

with open(KAA_CONFIG_SRC_PATH, 'w', encoding='utf8') as outfile:
with open(cloud_config_path, 'w', encoding='utf8') as outfile:
json.dump(config, outfile)

elif cloud == Providers.THINGSBOARD:
if file_exists(THINGSBOARD_CONFIG_SRC_PATH):
with open(THINGSBOARD_CONFIG_SRC_PATH, 'r', encoding='utf8') as infile:
if file_exists(cloud_config_path):
with open(cloud_config_path, 'r', encoding='utf8') as infile:
config = json.load(infile)
else:
config = {}
Expand Down Expand Up @@ -84,7 +84,34 @@ def set_credentials(cloud):
if password:
config['thingsboard_password'] = password

with open(THINGSBOARD_CONFIG_SRC_PATH, 'w', encoding='utf8') as outfile:
with open(cloud_config_path, 'w', encoding='utf8') as outfile:
json.dump(config, outfile)

elif cloud == Providers.BLYNK:
if file_exists(cloud_config_path):
with open(cloud_config_path, 'r', encoding='utf8') as infile:
config = json.load(infile)
else:
config = {}

print("Please provide Blynk credentials:")
old_auth_token = config.get('blynk_auth_token', None)
old_temperature_pin = config.get('blynk_temperature_pin', None)
old_humidity_pin = config.get('blynk_humidity_pin', None)

auth_token = input("Authentication token [{}]: ".format(old_auth_token))
temperature_pin = input("Temperature virtual pin [{}]: ".format(old_temperature_pin))
humidity_pin = input("Humidity virtual pin [{}]: ".format(old_humidity_pin))

# If values were not updated; leave the old ones
if auth_token:
config['blynk_auth_token'] = auth_token
if temperature_pin:
config['blynk_temperature_pin'] = temperature_pin
if humidity_pin:
config['blynk_humidity_pin'] = humidity_pin

with open(cloud_config_path, 'w', encoding='utf8') as outfile:
json.dump(config, outfile)


Expand Down
8 changes: 5 additions & 3 deletions MicroPython/scripts/common/cloud_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class Providers:
AWS = "AWS"
KAA = "KAA"
THINGSBOARD = "THINGSBOARD"
BLYNK = "BLYNK"

@classmethod
def print_providers(cls) -> str:
return "{}, {}, {}".format(cls.AWS, cls.KAA, cls.THINGSBOARD)
return "{}, {}, {}, {}".format(
cls.AWS, cls.KAA, cls.THINGSBOARD, cls.BLYNK)

@classmethod
def get_providers(cls) -> Tuple[str, str, str]:
return cls.AWS, cls.KAA, cls.THINGSBOARD
def get_providers(cls) -> Tuple[str, ...]:
return cls.AWS, cls.KAA, cls.THINGSBOARD, cls.BLYNK
16 changes: 5 additions & 11 deletions MicroPython/scripts/upload_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from upload_micropython import erase_chip, flash_micropython
from upload_scripts import flash_scripts

TERRAFORM_OUTPUT_PATH = "src/aws_config.json"
KAA_CONFIG_PATH = 'src/kaa_config.json'
THINGSBOARD_CONFIG_PATH = 'src/thingsboard_config.json'
CLOUD_CONFIG_PATH = "src/{}_config.json"
CONFIG_OUTPUT_PATH = "src/config.json"


Expand Down Expand Up @@ -45,16 +43,12 @@ def save_additional_arguments(cloud_provider, sensor_type):
if __name__ == '__main__':
args = parse_arguments()

cloud_config_file_path = CLOUD_CONFIG_PATH.format(args['cloud'].lower())
if args['cloud'] == Providers.AWS:
if not os.path.isfile(TERRAFORM_OUTPUT_PATH):
if not os.path.isfile(cloud_config_file_path):
print("Generating terraform output..")
save_terraform_output_as_file(TERRAFORM_OUTPUT_PATH)
cloud_config_file_path = TERRAFORM_OUTPUT_PATH
elif args['cloud'] == Providers.KAA:
cloud_config_file_path = KAA_CONFIG_PATH
set_credentials(args['cloud'])
elif args['cloud'] == Providers.THINGSBOARD:
cloud_config_file_path = THINGSBOARD_CONFIG_PATH
save_terraform_output_as_file(cloud_config_file_path)
elif args['cloud'] in (Providers.KAA, Providers.THINGSBOARD, Providers.BLYNK):
set_credentials(args['cloud'])
else:
raise Exception("Wrong cloud provider! Only: {} are valid".format(
Expand Down
2 changes: 1 addition & 1 deletion MicroPython/src/cloud/AWS_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cloud.cloud_interface import CloudProvider


class AWS_cloud(CloudProvider):
class AWSCloud(CloudProvider):
def device_configuration(self, data: list[dict]) -> int:
"""
Configures device in the cloud. Function used as hook to web_app.
Expand Down
Loading

0 comments on commit d30fb98

Please sign in to comment.