diff --git a/README.md b/README.md index 1f4d2a7..87f7b8a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Python AIoT Cloud ☁️🐍☁️ -AIoT cloud implementation for Python and MicroPython. +# Arduino IoT Cloud Micro/Python client ☁️🐍☁️ +Arduino IoT cloud client for Python and MicroPython. ## Testing on Linux -If a crypto device is available, the following steps can be skipped, otherwise AIoT cloud can be tested on Linux using SoftHSM. +If a crypto device is available, the following steps can be skipped, otherwise Arduino IoT cloud can be tested on Linux using SoftHSM. #### Create softhsm token Using the first available slot, in this case 0 @@ -43,12 +43,12 @@ softhsm2-util --delete-token --token "arduino" ``` ### Run the example script -* Set `KEY_URI`, `CERT_URI`, `DEVICE_ID`, `THING_ID` in `aiotcloud_example.py`. +* Set `KEY_URI`, `CERT_URI`, `DEVICE_ID`, `THING_ID` in `example.py`. * Provide a CA certificate in a `ca-root.pem` file or set `CA_PATH` to `None` if it's not used. * Override the default `pin` and provide `ENGINE_PATH` and `MODULE_PATH` in `ssl_params` if needed. * Clone this repository and run the following: ```bash -python aiotcloud_example.py +python example.py ``` ## Testing on MicroPython @@ -69,7 +69,7 @@ CERT_PATH = "cert.der" async def main(): with open(KEY_PATH, "rb") as fin: key = fin.read() with open(CERT_PATH, "rb") as fin: cert = fin.read() - aiot = AIOTCloud(device_id=DEVICE_ID, keepalive=10, ssl_params = {"key":key, "cert":cert}) + client = AIOTClient(device_id=DEVICE_ID, keepalive=10, ssl_params = {"key":key, "cert":cert}) .... ``` diff --git a/aiotcloud/__init__.py b/arduino_iot_cloud/__init__.py similarity index 97% rename from aiotcloud/__init__.py rename to arduino_iot_cloud/__init__.py index a0d6473..897ddca 100644 --- a/aiotcloud/__init__.py +++ b/arduino_iot_cloud/__init__.py @@ -1,4 +1,4 @@ -# This file is part of the Python AIoT Cloud. +# This file is part of the Arduino IoT Cloud Python client. # # The MIT License (MIT) # diff --git a/aiotcloud/ntptime.py b/arduino_iot_cloud/ntptime.py similarity index 100% rename from aiotcloud/ntptime.py rename to arduino_iot_cloud/ntptime.py diff --git a/aiotcloud/ucloud.py b/arduino_iot_cloud/ucloud.py similarity index 95% rename from aiotcloud/ucloud.py rename to arduino_iot_cloud/ucloud.py index 294b65f..0a07041 100644 --- a/aiotcloud/ucloud.py +++ b/arduino_iot_cloud/ucloud.py @@ -1,4 +1,4 @@ -# This file is part of the Python AIoT Cloud. +# This file is part of the Arduino IoT Cloud Python client. # # The MIT License (MIT) # @@ -25,7 +25,7 @@ import time from kpn_senml import SenmlPack from kpn_senml import SenmlRecord -from aiotcloud.umqtt import MQTTClient +from arduino_iot_cloud.umqtt import MQTTClient try: import logging @@ -35,7 +35,7 @@ except ImportError: import ulogging as logging import uasyncio as asyncio - from aiotcloud import ntptime + from arduino_iot_cloud import ntptime from uasyncio.core import CancelledError # MicroPython doesn't have this exception @@ -148,13 +148,13 @@ def senml_callback(self, record, **kwargs): self.updated = False self.on_write_scheduled = True - async def run(self, aiot): + async def run(self, client): while True: if self.on_read is not None: - self.value = self.on_read(aiot) + self.value = self.on_read(client) if self.on_write is not None and self.on_write_scheduled: self.on_write_scheduled = False - self.on_write(aiot, self if isinstance(self.value, dict) else self.value) + self.on_write(client, self if isinstance(self.value, dict) else self.value) await asyncio.sleep(self.interval) @@ -275,7 +275,7 @@ async def mqtt_task(self, interval=0.100): if record.updated: record.add_to_pack(self.senmlpack) if len(self.senmlpack._data): - logging.debug("Pushing records to AIoT Cloud:") + logging.debug("Pushing records to Arduino IoT cloud:") for record in self.senmlpack: logging.debug(f" ==> record: {record.name} value: {str(record.value)[:48]}...") self.mqtt.publish(self.topic_out, self.senmlpack.to_cbor(), qos=True) @@ -287,9 +287,9 @@ async def mqtt_task(self, interval=0.100): await asyncio.sleep(interval) async def run(self, user_main=None): - logging.info("Connecting to AIoT cloud...") + logging.info("Connecting to Arduino IoT cloud...") if not self.mqtt.connect(): - logging.error("Failed to connect AIoT cloud.") + logging.error("Failed to connect Arduino IoT cloud.") return self.mqtt.subscribe(self.device_topic) diff --git a/aiotcloud/umqtt.py b/arduino_iot_cloud/umqtt.py similarity index 99% rename from aiotcloud/umqtt.py rename to arduino_iot_cloud/umqtt.py index cc571a2..4ed78cb 100644 --- a/aiotcloud/umqtt.py +++ b/arduino_iot_cloud/umqtt.py @@ -28,7 +28,7 @@ import socket import struct import logging - from aiotcloud.ussl import wrap_socket + from arduino_iot_cloud.ussl import wrap_socket except ImportError: import usocket as socket import ustruct as struct diff --git a/aiotcloud/ussl.py b/arduino_iot_cloud/ussl.py similarity index 95% rename from aiotcloud/ussl.py rename to arduino_iot_cloud/ussl.py index 2df4294..09fa6ff 100644 --- a/aiotcloud/ussl.py +++ b/arduino_iot_cloud/ussl.py @@ -1,4 +1,4 @@ -# This file is part of the Python AIoT Cloud. +# This file is part of the Arduino IoT Cloud Python client. # # The MIT License (MIT) # @@ -22,7 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -# ussl module with m2crypto backend for HSM support. +# SSL module with m2crypto backend for HSM support. from M2Crypto import Engine, m2, SSL diff --git a/aiotcloud_example.py b/example.py similarity index 70% rename from aiotcloud_example.py rename to example.py index 10715e4..82b0907 100644 --- a/aiotcloud_example.py +++ b/example.py @@ -34,10 +34,10 @@ from time import strftime else: from ulogging.ustrftime import strftime -from aiotcloud import AIOTClient -from aiotcloud import Location -from aiotcloud import Schedule -from aiotcloud import ColoredLight +from arduino_iot_cloud import AIOTClient +from arduino_iot_cloud import Location +from arduino_iot_cloud import Schedule +from arduino_iot_cloud import ColoredLight from random import randint, choice DEBUG_ENABLED = True @@ -48,7 +48,7 @@ DEVICE_ID = b"25deeda1-3fda-4d06-9c3c-dd31be382cd2" -async def user_main(aiot): +async def user_main(client): """ Add your code here. NOTE: To allow other tasks to run, this function must yield @@ -56,64 +56,64 @@ async def user_main(aiot): """ while True: # The composite cloud object's fields can be assigned to individually: - aiot["clight"].hue = randint(0, 100) - aiot["clight"].bri = randint(0, 100) - aiot["user"] = choice(["=^.. ^=", "=^ ..^="]) + client["clight"].hue = randint(0, 100) + client["clight"].bri = randint(0, 100) + client["user"] = choice(["=^.. ^=", "=^ ..^="]) await asyncio.sleep(1.0) -def on_switch_changed(aiot, value): +def on_switch_changed(client, value): """ This is a write callback for the switch that toggles the LED variable. The LED - variable can be accessed via the aiot cloud object passed in the first argument. + variable can be accessed via the client object passed in the first argument. """ if value and not hasattr(on_switch_changed, "init"): on_switch_changed.init = True logging.info("Someone left the lights on!") - aiot["led"] = value + client["led"] = value -def on_clight_changed(aiot, clight): +def on_clight_changed(client, clight): logging.info(f"ColoredLight changed. Swi: {clight.swi} Bri: {clight.bri} Sat: {clight.sat} Hue: {clight.hue}") async def main(): - aiot = AIOTClient( + client = AIOTClient( device_id=DEVICE_ID, ssl_params={"pin": "1234", "keyfile": KEY_URI, "certfile": CERT_URI, "ca_certs": CA_PATH}, ) # This cloud object is initialized with its last known value from the cloud. - aiot.register("sw1", value=None, on_write=on_switch_changed, interval=0.250) + client.register("sw1", value=None, on_write=on_switch_changed, interval=0.250) # This cloud object is initialized with its last known value from the cloud, # and gets manually updated from the switch's on_write_change callback. - aiot.register("led", value=None) + client.register("led", value=None) # This is a periodic cloud object that gets updated every 1 second. - aiot.register("pot", value=None, on_read=lambda x: randint(0, 1024), interval=1.0) + client.register("pot", value=None, on_read=lambda x: randint(0, 1024), interval=1.0) # This is a periodic cloud object that gets updated every 1 second, # with the formatted current time value. - aiot.register("clk", value=None, on_read=lambda x: strftime("%H:%M:%S", time.localtime()), interval=1.0) + client.register("clk", value=None, on_read=lambda x: strftime("%H:%M:%S", time.localtime()), interval=1.0) # This variable is an example for a composite object (a colored light object in this case), # which is composed of multiple variables. Once initialized, the object's variables can be - # accessed as normal attributes, using dot notation (e.g: aiot["clight"].swi = False) - aiot.register(ColoredLight("clight", swi=True, hue=22, sat=75, bri=10, on_write=on_clight_changed)) + # accessed as normal attributes, using dot notation (e.g: client["clight"].swi = False) + client.register(ColoredLight("clight", swi=True, hue=22, sat=75, bri=10, on_write=on_clight_changed)) # This variable is an example for a composite object (a map location). - aiot.register(Location("treasureisland", lat=31.264694, lon=29.979987)) + client.register(Location("treasureisland", lat=31.264694, lon=29.979987)) # This variable is updated manually from user_main. - aiot.register("user", value="") + client.register("user", value="") # This object allows scheduling recurring events from the cloud UI. On activation of the event, if - # on_active callback is provided, it gets called with the aiot object and the schedule object value. - # The activation status of the object can also be polled using aiot["schedule"].active. - aiot.register(Schedule("schedule", on_active=lambda aiot, value: logging.info(f"Schedule activated {value}!"))) + # on_active callback is provided, it gets called with the client object and the schedule object value. + # The activation status of the object can also be polled using client["schedule"].active. + client.register(Schedule("schedule", on_active=lambda client, value: logging.info(f"Schedule activated {value}!"))) - # Start the AIoT client. - await aiot.run(user_main) + # Start the Arduino IoT cloud client. + await client.run(user_main) if __name__ == "__main__": diff --git a/setup.py b/setup.py index a9c3497..36b6624 100644 --- a/setup.py +++ b/setup.py @@ -4,12 +4,12 @@ long_description = fh.read() setuptools.setup( - name="aiotcloud", + name="arduino_iot_cloud", version="0.0.2", - url="https://github.com/bcmi-labs/python-aiotcloud", + url="https://github.com/bcmi-labs/arduino-iot-cloud", author="Ibrahim Abdelkader", author_email="i.abdelkader@arduino.cc", - description="Arduino IoT cloud Python module", + description="Arduino IoT Cloud Python client", long_description=long_description, long_description_content_type="text/markdown", license="MIT",