Skip to content

all: Rename python package. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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})
....
```

Expand Down
2 changes: 1 addition & 1 deletion aiotcloud/__init__.py → arduino_iot_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
#
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions aiotcloud/ucloud.py → arduino_iot_cloud/ucloud.py
Original file line number Diff line number Diff line change
@@ -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)
#
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion aiotcloud/umqtt.py → arduino_iot_cloud/umqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions aiotcloud/ussl.py → arduino_iot_cloud/ussl.py
Original file line number Diff line number Diff line change
@@ -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)
#
Expand All @@ -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

Expand Down
52 changes: 26 additions & 26 deletions aiotcloud_example.py → example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,72 +48,72 @@
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
execution periodically by calling asyncio.sleep(seconds).
"""
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__":
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="Arduino IoT cloud Python module",
description="Arduino IoT Cloud Python client",
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
Expand Down