The MetaWear interface is a software representation of the MetaWear boards and is the central class of the MetaWear API. It contains methods for connecting, disconnecting, saving and restoring state.
Bluetooth LE Connection¶
Before using any API features, you must first connect to the board with
from mbientlab.metawear import MetaWear from mbientlab.metawear.cbindings import * from mbientlab.warble import * device = MetaWear(address) device.connect()
disconnect to close the connection.
Watching for Disconnects¶
It is often useful to handle BLE disconnection events. The MetaWear interface has a
d = MetaWear(address) d.connect() d.on_disconnect = lambda status: print("disconnected")
If you expect to re-connect to a specific MetaWear device, you should remember it.
# for loop for the argv which is multiple MAC addresses of MetaWear devices for i in range(len(argv) - 1): d = MetaWear(argv[i + 1]) d.connect() print("Connected to " + d.address) states.append(State(d)) for s in states: print("Configuring %s" % (s.device.address)) s.setup() for s in states: print("Starting %s" % (s.device.address)) s.start()
Get the state of the SDK connection.
d = MetaWear(address) d.connect() print((State(d)))
Apple generates a unique identifier for each BLE device. Note, two different Apple devices will generate two different identifiers for the same MetaWear. It might be useful to use
print("Connected to " + d.address)
To fully reset your MetaWear board: