ev3dev/bluetooth: update examples for api changes

This commit is contained in:
David Lechner
2020-02-11 12:50:52 -06:00
parent fcc8af3381
commit 5ffedc9d51
2 changed files with 13 additions and 11 deletions
+7 -6
View File
@@ -4,21 +4,22 @@
# paired using Bluetooth, but do NOT connect them. The program will take care
# of establishing the connection.
from pybricks.bluetooth import EV3MailboxClient
from pybricks.messaging import BluetoothMailboxClient, TextMailbox
# Replace this with the Bluetooth address of the server. This address can be
# found on the screen of the client EV3 after pairing with the server.
SERVER = '00:17:E7:XX:XX:XX'
client = EV3MailboxClient(SERVER)
client = BluetoothMailboxClient()
mbox = TextMailbox('mbox', client)
# The server must be started before the client!
print('establishing connection...')
client.connect()
client.connect(SERVER)
print('connected!')
# In this program, the client sends the first message and then waits for the
# server to reply.
client.send_text(SERVER, 'msg1', 'hello!')
client.wait_for_update('msg2')
print(client.get_text('msg2'))
mbox.send('hello!')
mbox.wait()
print(mbox.read())
+6 -5
View File
@@ -4,9 +4,10 @@
# paired using Bluetooth, but do NOT connect them. The program will take care
# of establishing the connection.
from pybricks.bluetooth import ALL_BRICKS, EV3MailboxServer
from pybricks.messaging import BluetoothMailboxServer, TextMailbox
server = EV3MailboxServer()
server = BluetoothMailboxServer()
mbox = TextMailbox('mbox', server)
# The server must be started before the client!
print('waiting for connection...')
@@ -15,6 +16,6 @@ print('connected!')
# In this program, the server waits for the client to send the first message
# and then sends a reply.
server.wait_for_update('msg1')
print(server.get_text('msg1'))
server.send_text(ALL_BRICKS, 'msg2', 'hello to you too!')
mbox.wait()
print(mbox.read())
mbox.send('hello to you too!')