diff --git a/snippets/ev3/bluetooth_client/client.py b/snippets/ev3/bluetooth_client/client.py index 97de2ce..a893a23 100644 --- a/snippets/ev3/bluetooth_client/client.py +++ b/snippets/ev3/bluetooth_client/client.py @@ -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()) diff --git a/snippets/ev3/bluetooth_server/server.py b/snippets/ev3/bluetooth_server/server.py index 3267328..7ef9e44 100644 --- a/snippets/ev3/bluetooth_server/server.py +++ b/snippets/ev3/bluetooth_server/server.py @@ -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!')