bleConnect (Function) |
Top Previous Next |
This function makes the Bluetooth interface start connecting to a peripheral device.
The default parameters should work in most cases, so it is normally only necessary to provide the mac and dev parameters.
Once this function has returned successfully, the function bleDeviceStatus can be used to monitor the actual status of the peripheral device.
For advanced usage, some of the other connection parameters can be adjusted.
Scan interval and window These parameters determine how it searches for the device to connect to, if they are set to the same value, it will search continuously.
Connection interval This is how often the central asks the connected peripheral for data (connection event), which determines how often data can be transferred. A longer connection interval can reduce the power consumption of the peripheral but increases the latency and reduces the throughput.
Latency The latency determines how many connection events the peripheral is allowed to skip before it must respond. This enables the peripheral to sleep through events if it does not have anything to send, reducing the power consumption.
Supervision timeout The supervision timeout specifies how much time may pass without receiving a packet before considering the connection lost. Must be larger than (1 + latency_max) * con_interval_max * 2.
Connection length The connection length is used to indicate how long the connection must be, to plan the time allocation for multiple connections.
Note: Scanning must be stopped before it is possible to connect.
Input: mac: STRING The MAC address of the device to connect to.
scan_interval: UINT (4..16384) (default 16384, 10.24ms) The time interval from from one scan is started until the next is started. The time is provided in ticks of 0.625 ms. This gives a range from 2.5ms to 10.24 s.
scan_window: UINT (4..16384) (default 16384, 10.24ms) The duration to scan for. Must be less than or equal to the scan interval. The time is provided in ticks of 0.625 ms. This gives a range from 2.5ms to 10.24 s.
con_interval_min: UINT (6..3200) (default 24, 30ms) The minimum connection interval. The time is provided in ticks of 1.25 ms. This gives a range from 7.5ms to 4 s.
con_interval_max: UINT (6..3200) (default 40, 50ms) The maximum connection interval. The time is provided in ticks of 1.25 ms. This gives a range from 7.5ms to 4 s.
latency_max: UINT (0..499) (default 0) The maximum latency for the connection. If set to 0, the peripheral must respond to every event.
supervision_timeout: UINT (10..3200) (default 3200) If more than this time has elapsed since the most recent packet, the connection will be terminated. The value will be multiplied by 10 ms. This gives a range from 100ms to 32s.
con_length_min: UINT (0..65535) (default 16, 10ms) The minimum length of the connection needed. The time is provided in ticks of 0.625 ms. This gives a range from 0ms to 40.96 s.
con_length_max: UINT (0..65535) (default 16, 10ms) The maximum length of the connection needed. The time is provided in ticks of 0.625 ms. This gives a range from 0ms to 40.96 s.
Output: dev : SYSHANDLE A handle to the device.
Returns: INT
Declaration: FUNCTION bleConnect : INT;
Example: ... |