If a device configuration is not provided on startup, generate a random
BT address instead of using a default static value of
"F0:F1:F2:F3:F4:F5". This is helpful to avoid colisions when there are
two instances of console.py running nearby.
Testing:
Started console.py and began advertising a few times. Scanned from a
second instance of console.py and observed that the advertising address
changed with each restart.
Add command to clear scan results and known addresses. Useful for
determining if a peripheral has stopped advertising.
Also, check if a scan is in progress before connecting. If it is, stop
scanning. Some BT controllers will fail to connect while scanning.
Testing:
Can clear scan results before, during, and after scan. Can clear scan
results while disconnected and connected.
Subscribe command will enable notify or indicate events from the
characteristic, depending on supported characteristic properties, and
print received values to the output window.
Unsubscribe will stop notify or indicate events.
Rename find_attribute() to find_characteristic() and return a
characteristic for a set of UUIDS, a characteristic for an attribute
handle, or None.
Print read and received values has a hex string.
Add an unsubscribe implementation to gatt_client.py. Reset the CCCD bits
to 0x0000. Remove a matching subsciber, if one is provided. Otherwise
remove all subscribers for a characteristic, since no more notify or
indicates events will be comming.
authored-by: Michael Mogenson <mogenson@google.com>
Syntax is `write <attribute> <value>`. Supports a value of type string,
hexadecimal string, or integer.
Ex:
- `write 180D.2A38 hello`
- `write 180D.2A38 0xbeef`
- `write 180D.2A38 123`
Write with response method is used if supported by characteristic,
otherwise write without response.
Add a find_attribute() method to consolidate common logic of finding a
characteristic or attribute handle in `do_read()` and `do_write()`.
Tested with run_gatt_server.py example to verify sent data.