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
- create a python virtual environment
- run the command
py -m venv venv
- run the command
- add aliot in a folder in your project (replace $FOLDER in the command by the name of your folder)
- run the command
pip install ./$FOLDER
Creating my first Aliot program
- create an object ObjConnecte
Creating an endpoint (or, like we call it here, a protocol)
-
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}
-
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}
-
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:- 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})
- 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}
- You're all set! Now repeat and enjoy! 🎉
- use the function
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aliot-py-0.1.0.tar.gz
.
File metadata
- Download URL: aliot-py-0.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 283ce1da59bde5f96f2038938d4c7efe355a7c97bc5c045cfafd5e331d43e9de |
|
MD5 | b5e0ab4f28c1944837e71a1b98fa5874 |
|
BLAKE2b-256 | bc1b7b0ba32757ac6a2115c7719a5f3a194579f259f58b416f4fd5d7b6c93bc3 |
File details
Details for the file aliot_py-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: aliot_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7a7cd0127be0869b95bd7633e4c3a5439e9545f1f1e37b23167b5455f445f22 |
|
MD5 | cee3bd4e25a807d9beac3ea20932ee58 |
|
BLAKE2b-256 | 213d36a76b4c4e296d946d222e28e70899975cede0f6063616096d0423b5046f |