Skip to content

Commit

Permalink
Merge pull request #20 from wizzdev-pl/devel_master_comments_pr
Browse files Browse the repository at this point in the history
Comments fixed for pull request
  • Loading branch information
damian-kurek-wizzdev authored Aug 16, 2021
2 parents 7748298 + f5ed3a9 commit 3a6af9f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
6 changes: 3 additions & 3 deletions KAA/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Set up account and device on KaaIoT cloud platform
This detailed instruction will walk you through the process of creating your own iot device in just a few steps.
The instruction walks you through the process of creating your own IoT device in just a few steps.

## What is KaaIoT
KaaIoT is a cloud service provider allowing for device management, data collection and its visualization. You can create powerful dashboards in a matter of seconds. It's free of charge with a limit of maximum 5 connected devices.
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

Expand Down Expand Up @@ -100,7 +100,7 @@ After you log in into your new account (as a root user!), familiarize yourself w

1. Hover over the "Device management" option (first one) and select "Applications". In the right top corner click "Add application" and enter the name of your application and (optional) description.
2. Click on the created application to expand it. On the right side look for "epts" and click on it. There you should see an option **"Autoextract"**. Make sure that the checkbox is checked.
3. Go back to the application menu and expand the created application again. On the left side of the expanded window you will see “versions”. Click on the plus sign next to add a new version. You should see the "Name" field with a long sequence of random characters (like this one: c2t3ac6gul4q7qik0ol0-). There you should specify a version of your application. Let's go with something simple, add "v1" at the input field. **It is important for you to write this application version down as we will need it later - in this example it would look like: "c2t3ac6gul4q7qik0ol0-v1"**. You can add some optional display name and description for your convenience. After it is created, repeat step 2. but for the created version.
3. Go back to the application menu and expand the created application again. On the left side of the expanded window you will see “versions”. Click on the plus sign next to add a new version. You should see the "Name" field with a long sequence of random characters (like this one: c2t3ac6gul4q7qik0ol0-). There you should specify a version of your application. Let's go with something simple, add "v1" at the input field. **It is important for you to write this application version down as we will need it later - in this example it looks like: "c2t3ac6gul4q7qik0ol0-v1"**. You can add some optional display name and description for your convenience. After it is created, repeat step 2. but for the created version.

#### **Device endpoint:**

Expand Down
16 changes: 10 additions & 6 deletions MicroPython/scripts/cloud_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ def set_credentials():
print()

# If values were not updated; leave the old ones
config['kaa_endpoint'] = endpoint if endpoint else old_endpoint
config['kaa_app_version'] = app_version if app_version else old_app_version
config['kaa_user'] = user if user else old_user
config['kaa_password'] = password if password else old_password

if endpoint:
config['kaa_endpoint'] = endpoint
if app_version:
config['kaa_app_version'] = app_version
if user:
config['kaa_user'] = user
if password:
config['kaa_password'] = password

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

Expand All @@ -49,7 +53,7 @@ def parse_arguments():
parser = argparse.ArgumentParser()

parser.add_argument(
'--set-credentials', required=True, action='store_true',
'--set-credentials', action='store_true',
dest='creds', help="Set credentials needed for cloud service"
)

Expand Down
38 changes: 19 additions & 19 deletions MicroPython/src/cloud/AWS_cloud.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import gc
import logging
import urequests
import machine
from ujson import dumps, load
from os import mkdir

import machine
import urequests
from common import config, utils
from communication import wirerless_connection_controller
from controller.main_controller_event import (MainControllerEvent,
MainControllerEventType)
from ujson import dumps, load

from controller.main_controller_event import MainControllerEvent, MainControllerEventType
from cloud.cloud_interface import CloudProvider


Expand Down Expand Up @@ -166,11 +164,12 @@ def authorization_request(self) -> str:
logging.debug("Authorization request function")
headers = config.DEFAULT_JSON_HEADER
url = config.cfg.api_url + config.AWS_API_AUTHORIZATION_URL
body = {}
body['is_removed'] = True
body['created_at'] = 0
body['username'] = config.cfg.api_login
body['password'] = config.cfg.api_password
body = {
'is_removed': True,
'created_at': 0,
'username': config.cfg.api_login,
'password': config.cfg.api_password
}

logging.debug('LOGIN: {}, password: {}'.format(
config.cfg.api_login, config.cfg.api_password))
Expand Down Expand Up @@ -202,14 +201,15 @@ def configuration_request(self, _jwt_token: str) -> dict:
headers = config.ESPConfig.get_header_with_authorization(_jwt_token)
url = config.cfg.api_url + config.AWS_API_CONFIG_URL
thing_name = config.AWS_THING_NAME_PREFIX + config.cfg.device_uid
body = {}
body['is_removed'] = True
body['created_at'] = 0
body['device_id'] = thing_name
body['description'] = 'Full configuration test'
body['device_type'] = 'configuration_test'
body['device_group'] = 'configuration_test'
body['settings'] = {}
body = {
'is_removed': True,
'created_at': 0,
'device_id': thing_name,
'description': 'Full configuration test',
'device_type': 'configuration_test',
'device_group': 'configuration_test',
'settings': {}
}

body = dumps(body)
response = urequests.post(url, data=body, headers=headers)
Expand Down
2 changes: 1 addition & 1 deletion MicroPython/src/cloud/KAA_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def publish_data(self, data):
logging.error(
"Error subscribing to topics with MQTT in publish_data()")

# TODO: Certificates?
# TODO: Add SSL connection

data = self._format_data(data)

Expand Down
2 changes: 1 addition & 1 deletion MicroPython/src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_wifi_and_cloud_handlers(sync_time: bool = False) -> (WirelessConnectionC
timeout=config.cfg.mqtt_timeout)

while not wireless_controller.sta_handler.isconnected():
pass
utime.sleep_ms(1)

mqtt_communicator.connect()
except Exception as e:
Expand Down
3 changes: 3 additions & 0 deletions MicroPython/src/lib/bme280.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Library copied from https://github.com/RuiSantosdotme/ESP-MicroPython/blob/master/code/WiFi/HTTP_Client_IFTTT_BME280/BME280.py
"""
from machine import I2C
import time

Expand Down

0 comments on commit 3a6af9f

Please sign in to comment.