Files
pybricks-api/examples/ev3/bluetooth_client/client.py
T
Laurens Valk b0ffb24a2e examples: import snippets from pybricks-projects
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
2020-11-04 10:17:33 +01:00

26 lines
730 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 BluetoothMailboxClient, TextMailbox
# This is the name of the remote EV3 or PC we are connecting to.
SERVER = 'ev3dev'
client = BluetoothMailboxClient()
mbox = TextMailbox('greeting', client)
print('establishing connection...')
client.connect(SERVER)
print('connected!')
# In this program, the client sends the first message and then waits for the
# server to reply.
mbox.send('hello!')
mbox.wait()
print(mbox.read())