From f5ed3a903c391ff068c394816c7e7884d7b0e0ce Mon Sep 17 00:00:00 2001 From: jakub-pliszka-wizzdev Date: Mon, 16 Aug 2021 16:09:33 +0200 Subject: [PATCH] Comments fixed for pull request --- KAA/README.md | 6 ++-- MicroPython/scripts/cloud_credentials.py | 16 ++++++---- MicroPython/src/cloud/AWS_cloud.py | 38 ++++++++++++------------ MicroPython/src/cloud/KAA_cloud.py | 2 +- MicroPython/src/common/utils.py | 2 +- MicroPython/src/lib/bme280.py | 3 ++ 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/KAA/README.md b/KAA/README.md index f689477..19ac1e0 100644 --- a/KAA/README.md +++ b/KAA/README.md @@ -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 @@ -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:** diff --git a/MicroPython/scripts/cloud_credentials.py b/MicroPython/scripts/cloud_credentials.py index d2ee71d..6008520 100644 --- a/MicroPython/scripts/cloud_credentials.py +++ b/MicroPython/scripts/cloud_credentials.py @@ -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) @@ -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" ) diff --git a/MicroPython/src/cloud/AWS_cloud.py b/MicroPython/src/cloud/AWS_cloud.py index 2b6c027..4450e7a 100644 --- a/MicroPython/src/cloud/AWS_cloud.py +++ b/MicroPython/src/cloud/AWS_cloud.py @@ -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 @@ -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)) @@ -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) diff --git a/MicroPython/src/cloud/KAA_cloud.py b/MicroPython/src/cloud/KAA_cloud.py index d58abbc..cc761b5 100644 --- a/MicroPython/src/cloud/KAA_cloud.py +++ b/MicroPython/src/cloud/KAA_cloud.py @@ -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) diff --git a/MicroPython/src/common/utils.py b/MicroPython/src/common/utils.py index f2b2146..90ef84b 100644 --- a/MicroPython/src/common/utils.py +++ b/MicroPython/src/common/utils.py @@ -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: diff --git a/MicroPython/src/lib/bme280.py b/MicroPython/src/lib/bme280.py index 491b51e..8fd49a5 100644 --- a/MicroPython/src/lib/bme280.py +++ b/MicroPython/src/lib/bme280.py @@ -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