Skip to main content

Aliot-py is the python implementation of the Aliot library, an IOT library made to work with the ALIVEIoT ecosystem (see https://alivecode.ca/iot)

Project description

ALIOT-PY: The python implementation of the Aliot library!

What is Aliot?

Before everything else, aliot is a fancy websocket written in python that aims to facilitate iot focused exchanges between a server and a client

Installation

  1. create a python virtual environment
    • run the command py -m venv venv
  2. add aliot in a folder in your project (replace $FOLDER in the command by the name of your folder)
  3. run the command pip install ./$FOLDER

Creating my first Aliot program

  1. create an object ObjConnecte

Creating an endpoint (or, like we call it here, a protocol)

  1. Create a function that takes some parameters

    # my function will take money ($) and give cookies for every 2$ received
    def give_cookies_for_money(money: int):
        return {"cookies": money // 2}
    
  2. Register your function as a protocol by decorating it with the on_recv decorator in your ObjConnecte that you created for your project and pass the id of your protocol in the argument of the decorator

    # here, I chose that my function will be protocol 34
    @my_iot.on_recv(action_id=34)
    def give_cookies_for_money(money: int):
        return {"cookies": money // 2}
    
  3. As of now, my function give_cookies_for_money doesn't return anything to the server, if I want to send back my cookies, I have to ways:

    1. use the function my_iot.send()
    @my_iot.on_recv(action_id=34)
    def give_cookies_for_money(money: int):
        my_iot.send({"cookies": money // 2})
    
    1. set the convenience parameter send_result to True in the decorator
    @my_iot.on_recv(action_id=34, send_result=True)
    def give_cookies_for_money(money: int):
        return {"cookies": money // 2}
    
    1. You're all set! Now repeat and enjoy! 🎉

Order of execution (once run() is called)

  1. obj.on_start()
  • On receive:
    1. [ interceptor.intercept_recv() ]
    2. decoder.decode_event(event: dict) -> AliotEvent
    3. controller.handle_event(event: AliotEvent) -> None
    4. decoder.decode_data(data: dict) -> T
  • On send:
    1. encoder.encode_data(data: Any) -> dict
    2. encode.encode_event()
    3. obj.__send_event() -> None

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aliot-py-1.0.5.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

aliot_py-1.0.5-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file aliot-py-1.0.5.tar.gz.

File metadata

  • Download URL: aliot-py-1.0.5.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for aliot-py-1.0.5.tar.gz
Algorithm Hash digest
SHA256 a382a4330501124fb04e98631c3bb73f3f742fb24f41e8bbf3b04842a9089c17
MD5 268a3065d6b8a4d11e2f436db01e206d
BLAKE2b-256 07bafd4cb8e46edd5a05e9e6e4206d51c560af33ac39186111df89a42ea8f67b

See more details on using hashes here.

File details

Details for the file aliot_py-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: aliot_py-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for aliot_py-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 20ec5b949b6c65c9bfdd4a8b3a056f7f9bf567a62caf6fa957786f88df1f5f32
MD5 86fb193fc923d935d1bb3cb09f6d7de0
BLAKE2b-256 ae5912fa731f814b5b94d1d7b0e3eac44eb82c3b4add1018499e96498bfb4f15

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page