mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 09:37:25 +00:00
These code samples are rendered in the docs, so we include them here. For the git history of these snippets, see: https://github.com/pybricks/pybricks-projects/commits/f4914069aaacfd9ab1e0dd6f05524f62cfc56b29/snippets
24 lines
713 B
Python
24 lines
713 B
Python
#!/usr/bin/env pybricks-micropython
|
|
|
|
# Before running this program, make sure the client and server EV3 bricks are
|
|
# paired using Bluetooth, but do NOT connect them. The program will take care
|
|
# of establishing the connection.
|
|
|
|
# The server must be started before the client!
|
|
|
|
from pybricks.messaging import BluetoothMailboxServer, TextMailbox
|
|
|
|
server = BluetoothMailboxServer()
|
|
mbox = TextMailbox('greeting', server)
|
|
|
|
# The server must be started before the client!
|
|
print('waiting for connection...')
|
|
server.wait_for_connection()
|
|
print('connected!')
|
|
|
|
# In this program, the server waits for the client to send the first message
|
|
# and then sends a reply.
|
|
mbox.wait()
|
|
print(mbox.read())
|
|
mbox.send('hello to you!')
|