Before everything else, aliot is a fancy websocket written in python that aims to facilitate iot focused exchanges between a server and a client
- 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
- create an object ObjConnecte
-
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
- obj.on_start()
- On receive:
- [ interceptor.intercept_recv() ]
- decoder.decode_event(event: dict) -> AliotEvent
- controller.handle_event(event: AliotEvent) -> None
- decoder.decode_data(data: dict) -> T
- On send:
- encoder.encode_data(data: Any) -> dict
- encode.encode_event()
- obj.__send_event() -> None