Files
pybricks-api/examples/ev3/bluetooth_pc/pcclient.py
T
Laurens Valk bd7806d2d4 all: Format with black.
Also activate auto formatting. Bump flake8 and mark black
disagreements in setup.cfg.
2022-05-27 16:22:05 +02:00

34 lines
1.2 KiB
Python

#!/usr/bin/env python3
from pybricks.messaging import BluetoothMailboxClient, TextMailbox
# This demo makes your PC talk to an EV3 over Bluetooth.
#
# This is identical to the EV3 client example in ../bluetooth_client
#
# The only difference is that it runs in Python3 on your computer, thanks to
# the Python3 implementation of the messaging module that is included here.
# As far as the EV3 is concerned, it thinks it just talks to an EV3 client.
#
# So, the EV3 server example needs no further modifications. The connection
# procedure is also the same as documented in the messaging module docs:
# https://docs.pybricks.com/en/latest/messaging.html
#
# So, turn Bluetooth on on your PC and the EV3. You may need to make Bluetooth
# visible on the EV3. You can skip pairing if you already know the EV3 address.
# This is the address of the server EV3 we are connecting to.
SERVER = "CC:78:AB:D8:4E:F6"
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())