Files
pybricks-projects/snippets/ev3/bluetooth_client/client.py
T
2020-02-12 15:50:21 -06:00

25 lines
719 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.
from pybricks.messaging import BluetoothMailboxClient, TextMailbox
# This is the name of the remote EV3 we are connecting to.
SERVER = 'ev3dev'
client = BluetoothMailboxClient()
mbox = TextMailbox('mbox', client)
# The server must be started before the 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())