mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-09-15 02:52:41 +00:00
ev3dev/bluetooth: update examples for api changes
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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!')
|
||||
|
||||
Reference in New Issue
Block a user