Skip to content

Conversation

geza-pycom
Copy link
Contributor

@geza-pycom geza-pycom commented Feb 25, 2020

To be merged when the 2 features from the beginning of the list below are released in a stable release.

In this PR the currently latest version of Bluetooth documentation from "development-publish" is synchronized with "publish" branch as there were lots of not documented, but already released, changes:

  • Documentation of feature "BLE characteristic update messages are lost if they sent too frequently", released as beta in: v1.20.2.rc2, publish-development PR: PYFW-395: BLE characteristic update messages are lost if they sent too frequently #215
  • Documentation of feature "Implemented configuration options for BLE security", not released yet in any development version, publish-development PR: Updated bluetooth.init(), added set_pin() #225
  • Documentation of the following, already officially released in 1.20.1, changes:
    • Adding "modem_sleep" parameter to Bluetooth.init()
    • Adding "timeout" parameter to Bluetooth.connect()
    • Adding documentation of Bluetooth.set_advertisement_params() new API
    • Adding documentation of Bluetooth.tx_power() new API
@geza-pycom geza-pycom requested a review from Xykon February 25, 2020 06:53
@jirkadev jirkadev requested a review from lilycey February 25, 2020 11:13
Copy link
Contributor

@lilycey lilycey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes for readability

* `id` Only one Bluetooth peripheral available so must always be 0.
* `mode` currently the only supported mode is `Bluetooth.BLE`.
* `antenna` selects between the internal and the external antenna. Can be either `Bluetooth.INT_ANT`, `Bluetooth.EXT_ANT`.
* `modem_sleep` Enables or Disables BLE modem sleep, Disable modem sleep as a workaround when having Crashes due to flash cache being disabled, as this prevents BLE task saving data in external RAM while accesing external flash for R/W.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st: Enables or Disables BLE modem sleep. Disable modem sleep is a workaround when experiencing crashes due to the flash cache being disabled. It prevents the BLE task saving data in the external RAM while accessing the external flash for R/W.

* `mode` currently the only supported mode is `Bluetooth.BLE`.
* `antenna` selects between the internal and the external antenna. Can be either `Bluetooth.INT_ANT`, `Bluetooth.EXT_ANT`.
* `modem_sleep` Enables or Disables BLE modem sleep, Disable modem sleep as a workaround when having Crashes due to flash cache being disabled, as this prevents BLE task saving data in external RAM while accesing external flash for R/W.
* `pin` a one to six digit number (`0`-`9`) to connect to the GATT Sever. Setting any valid pin, GATT Server security features are activated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd: By setting a valid pin, the GATT Server security features are activated.

* `antenna` selects between the internal and the external antenna. Can be either `Bluetooth.INT_ANT`, `Bluetooth.EXT_ANT`.
* `modem_sleep` Enables or Disables BLE modem sleep, Disable modem sleep as a workaround when having Crashes due to flash cache being disabled, as this prevents BLE task saving data in external RAM while accesing external flash for R/W.
* `pin` a one to six digit number (`0`-`9`) to connect to the GATT Sever. Setting any valid pin, GATT Server security features are activated.
* `privacy` Enables or Disables local privacy settings so address will be random or public.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3rd: Enables or disables the local privacy settings so the address will be random or public.

* `mtu` Maximum Transmission Unit (MTU) is the maximum length of an ATT packet. Value must be between `23` and `200`.

With our development boards it defaults to using the internal antenna, but in the case of an OEM module, the antenna pin (`P12`) is not used, so it's free to be used for other things.
With our development boards it defaults to using the internal antenna, but in the case of an OEM module, the antenna pin (`P12`) is not used, so it's free to be used for other things.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4th: Our development boards' default is to use the internal antenna. However, with the OEM module, the antenna pin (P12) is not used so it's free to be used for other things.

### bluetooth.start\_scan(timeout)
#### bluetooth.start\_scan(timeout)

Starts performing a scan listening for BLE devices sending advertisements. This function always returns immediately, the scanning will be performed on the background. The return value is `None`. After starting the scan the function `get_adv()` can be used to retrieve the advertisements messages from the FIFO. The internal FIFO has space to cache 16 advertisements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5th: Starts performing a scan, listening for BLE devices sending advertisements. This function always returns immediately and the scanning will be performed in the background. The return value is None.
After starting the scan, the function get_adv() can be used to retrieve the advertisement's messages from the FIFO. The internal FIFO has space to cache 16 advertisements.

### bluetooth.set\_advertisement(\* , name=None, manufacturer\_data=None, service\_data=None, service\_uuid=None)
#### bluetooth.set\_advertisement(\* , name=None, manufacturer\_data=None, service\_data=None, service\_uuid=None)

Configure the data to be sent while advertising. If left with the default of `None` the data won't be part of the advertisement message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13th: Configures the data to be sent whilst advertising. If left with the default of None, the data won't be part of the advertisement message.

* `adv_int_min` is the minimum advertising interval for undirected and low duty cycle directed advertising.
* `adv_int_max` is the maximum advertising interval for undirected and low duty cycle directed advertising.
* `adv_type` is the advertising type.
* `own_addr_type` is the owner bluetooth device address type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14th: is the owner's bluetooth device address type.

### bluetooth.tx\_power(type, level)

Gets or sets the TX Power level.
If called with only `type` parameter it returns with the current value belonging to the given type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15th: If called with only type parameter, it returns with the current value belonging to the given type.

#### characteristic.events()

Returns a value with bit flags identifying the events that have occurred since the last call. Calling this function clears the events.
We recommend getting both the `event` and new `value` of the characteristic via this tuple, and not via `characteristic.event()` and `characteristic.value()` calls in the context of the `handler` to make sure no event and value is lost.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16th: We recommend getting both the event and new value of the characteristic via this tuple, and not via characteristic.event() and characteristic.value() calls in the context of the handler. This is to make sure that no event and value is lost.


* `uuid` is the UUID of the service. Can take an integer or a 16 byte long string or bytes object.
* `permissions` configures the permissions of the characteristic. Takes an integer with a combination of the flags.
* `permissions` configures the permissions of the characteristic. Takes an integer with a combination of the flags. When bluetooth object is initialized with PIN, read and write permissions are set to encrypted. Setting PIN later with set_pin() call does not affect the permissions of the already existing characteristics, thus they will remain not secured.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17th: When the bluetooth object is initialized with the PIN, read and write permissions are set to encrypted. Setting the PIN later with the set_pin() call does not affect the permissions of the already existing characteristics, thus they will remain unsecured.

@geza-pycom
Copy link
Contributor Author

@lilycey : let me not modify these things as this is just a synchronization commit between the documentation of the development release and stable release. These corrections should be made in both documentation.

@peter-pycom peter-pycom merged commit 95dd07f into pycom:publish Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants