Understanding The s2aiomulti Architecture - MrYsLab/s2aiomulti GitHub Wiki
s2aiomulti is a pure Python 3.5 asyncio application that allows the user to connect to, control and monitor several Arduino boards from a single instance of a Scratch 2.0 off-line project.
It consists of 2 major software components:
- The s2aior router (1 per system)
- The s2aios Arduino server
- One per Arduino.
Both of these components are based on s2aio
The diagram below shows the typical s2aiomulti dataflow.
Scratch Command Block Processing
The router and associated servers communicate via HTTP Scratch extension messages. The command messages from Scratch contain a "board identifier" field, and the router uses this field to forward the message to the appropriate Arduino Server/board. The server converts these messages to Firmata protocol messages by using the pymata_aio API.
So for example, when Scratch executes a command block, such as writing to a digital pin, or moving a servo, it sends an HTTP extension message to the router. The message contains a board identifier, and the router uses this identifier to forward the message to the server. The server then translates the message into pymata_aio API calls to control the Arduino board.
Arduino Data Update Processing
Messages originated from the Arduino board (reporter messages) are received as Firmata protocol messages. These messages are received by pymata_aio and the server translates these messages into HTTP messages that contain a board identifier. They are forwarded to the router, which in turn forwards the messages to Scratch.
When an Arduino board reports a data change, it sends the Arduino server a Firmata protocol message. The server then translates this message into an HTTP reporter message, attaches a board identifier and then forwards it to the router. The router sends the data update to Scratch which can display it on the screen.