I am not clear what you mean by " incorporate the python code ". If you mean somehow executing in HTML, you can't, however, you can use websockets. I did this for one of my projects and is shown in the get_message method of this file https://github.com/MrYsLab/pymata-aio/b ... iot.py#L72
The file is huge, but you can ignore most of it since it uses a web page to control an Arduino. You can view the matching web page here:
https://github.com/MrYsLab/pymata-aio/b ... ester.html
Just look for JSON in the html file to see the messages being assembled and sent or received.
The messages are JSON messages, but on the python side, you can view them as Python dictionaries.
If you want to see a simple interaction, here is the code for a very simple python websocket server. Start this up, bring up the webpage above and click around and you will the messages printed in the python console. Pick the second tab, UNO Digital/PWM Output, since it sends messages.
Code: Select all
async def hello(websocket, path):
data = await websocket.recv()
start_server = websockets.serve(hello, '127.0.0.1', 9000)
start_server = websockets.serve(hello, 'localhost', 9000)