Part 2: take the control
1. Introductionβ
This is the remote control part of this tutorial, for you to control the Matrix π: The service gate running on your board allows you to take control through a computer of any service loaded on your device.
2. Set up your development environmentβ
We will use Python to control your board running Luos engine with a library called pyluos.
In order to install it, run the following command in the terminal:
pip install pyluos
As you need to use a pip
command in your terminal, make sure to have a working pip environment.
Depending on your version of Python, you may need to use the command pip3
instead of pip
.
If you already have Pyluos installed on your computer, please make sure it is up to date by using this prompt in your terminal: pip install pyluos --upgrade
3. Connecting and controlling your deviceβ
- Board
- No board
Pyluos provides a set of application programming interfaces (APIs). To control your device, connect the same board you flashed in Part 1 and run the following command in the terminal:
pyluos-shell
This command will find the serial port of your device and mount it into a βdeviceβ object.
When using ESP32-DevKit, the USB serial's baudrate must be 115200 by default. Use the command pyluos-shell --baudrate 115200
to set it.
For example:
**$ pyluos-shell**
Searching for a gate available
Testing /dev/cu.usbserial-D308N885
Testing /dev/cu.usbmodem13102
Connected to "/dev/cu.usbmodem13102".
Sending detection signal.
Waiting for routing table...
Device setup.
Hit Ctrl-D to exit this interpreter.
Your luos device have been successfully mounted into a "device" object:
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β βnode 1 /!\ Not certified β
β β Type Alias ID β
β β> State led 2 β
β β> Pipe Pipe 3 β
β β> Gate gate 1 β
β β°> Unknown blinker 4 β
β>ββββββββββββββββββββββββββββββββββββββββββββββββββββ
Pyluos provides a set of application programming interfaces (APIs). Keep program.exe running in a terminal, and in a new tab or in another terminal start Pyluos with the following command:
`pyluos-shell -p 'localhost'`
This command will find your device through a web socket, and mount it into a "device" object.
For example:
**$ pyluos-shell -p 'localhost'**
Connected to "localhost".
Sending detection signal.
Waiting for routing table...
Sending telemetry...
Device setup.
Hit Ctrl-D to exit this interpreter.
Your luos device has been successfully mounted into a "device" object:
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β βnode 1 /!\ Not certified β
β β Type Alias ID β
β β> State led 2 β
β β> Pipe Pipe 3 β
β β> Gate gate 1 β
β β°> Unknown blinker 4 β
β>ββββββββββββββββββββββββββββββββββββββββββββββββββββ
You will see Pyluos connected through the web socket on the terminal where you ran program.exe.
In some cases, you may encounter an error message at this point. Most of the time, this is related to IPython. Installation or performing a new installation solves the problem. Type the command pip install ipython
in the terminal.
The device
object is an object representation of your actual device displayed by pyluos-shell.
Now that you have opened an IPython session, you are able to execute Python commands line by line. By doing so, you can interact with your actual device directly into the pyluos-shell interface.
In the device object, there are multiple services. Each of those services will have special capabilities depending on their type.
For example, try to execute these lines one by one:
- Set up the blinking timing to 250ms (you should see the LED blink faster):
device.blinker.time=0.25
- Pause the blinking of the LED:
device.blinker.pause()
- Turn on the LED:
device.led.state=True
- Turn off the LED:
device.led.state=False
- Restart the blinking of the LED:
device.blinker.play()
You can always check the list of the commands available for all services using your tab
key:
See Pyluos documentation for more information.
4. Next stepsβ
With your development environment installed in Part 1, you have now taken the control of a Luos app running on your MCU, with Python. The next part of this section deals with creating your first Luos network.