BLE
Devices that support RUI3 BLE API
RAK Modules |
---|
RAK4630 |
RAK11720 |
RUI BLE Data Type
Enumerations
RAK_BLE_SERVICE_MODE
enum RAK_BLE_SERVICE_MODE
Mode | Comment |
---|---|
RAK_BLE_UART_MODE | Switch to BLE UART mode |
RAK_BLE_SERVICE_MODE | Switch to Beacon Mode. |
RAK_CHARS_SECURITY_REQ
enum RAK_CHARS_SECURITY_REQ
Mode | Comment |
---|---|
RAK_SET_OPEN | Set sec_mode pointed to by ptr to require no protection, open link. |
RAK_SET_ENC_NO_MITM | Set sec_mode pointed to by ptr to require encryption, but no MITM protection. |
RAK_SET_ENC_WITH_MITM | Set sec_mode pointed to by ptr to require encryption and MITM protection. |
RAK_CHARS_PROPERTIES
Property | Comment |
---|---|
RAK_CHR_PROPS_READ | Set the characteristic property to be Read. |
RAK_CHR_PROPS_NOTIFY | Set the characteristic property to be Notify. |
BLE_HANDLER
typedef void(* BLE_HANDLER) (void)
Event
enum Event
Enumerator | |
---|---|
BLE_CONNECTED | Set callback for connection event. |
BLE_DISCONNECTED | Set callback for disconnect event. |
BLE
The following commands are the generic BLE commands:
stop()
Disconnect an existing BLE connection.
api.ble.stop()
Function | void stop(void) |
---|---|
Returns | void |
registerCallback
Set a callback function when a bluetooth connection is established or disconnected.
api.ble.registerCallback()
Function | void registerCallback (Event event, BLE_HANDLER callback) |
---|---|
Parameters | event - set connect or disconnect event callback - callback function |
Returns | void |
BLE UART
Serial6 is the UART interface for BLE. To enable AT commands via BLE, you can use Serial6.begin(115200, RAK_AT_MODE);
.
start()
This API is used to start the BLE UART Service.
api.ble.uart.start()
Function | void start(uint8_t adv_time) |
---|---|
Parameters | adv_time - advertising timeout in seconds. If x = 0, advertising never stops |
Returns | void |
stop()
This API is used to stop the BLE UART Service.
api.ble.uart.stop()
Function | void stop(void) |
---|---|
Returns | void |
Click to view the code
void setup()
{
api.ble.uart.stop();
}
void loop()
{
}
available()
This API is used to check if there is any incoming Byte from BLE UART Service.
api.ble.uart.available()
Function | bool available(void) |
---|---|
Returns | bool |
Return Values | TRUE - receive data from the ble device FALSE - nothing to get |
read()
This API is used to read incoming Byte from BLE UART Service.
api.ble.uart.read()
Function | char read(void) |
---|---|
Returns | The first byte of incoming BLE data available (Type: char) |
write()
This API is used to write data and send it to the connected device via BLE.
api.ble.uart.write(data, size)
Function | void write(uint8_t * data, uint16_t size = 6) |
---|---|
Parameters | data - an array to send as a series of bytes size - length of the data that will be written to the ble device |
Returns | void |
setPIN()
This API is used to set the passkey with BLE pairing.
api.ble.uart.setPIN(key, size)
Function | void setPIN(uint8_t * key, uint16_t size) |
---|---|
Parameters | key - the key to set the passkey (6 digits only) size - the length of key (can only be 6) |
Returns | void |
setPermission()
This API is used to access BLE UART to require man-in-the-middle protection.
api.ble.uart.setPermission(permission)
Function | void setPermission(RAK_CHARS_SECURITY_REQ permission) |
---|---|
Parameters | permission - This will cause apps to perform pairing with static PIN you set RAK_SET_ENC_WITH_MITM RAK_SET_ENC_NO_MITM |
Returns | void |
BLE Setting
mac
get()
This API is used to get the current Device MAC Address.
api.ble.mac.get()
api.ble.mac.get(pos)
If MAC is 6 bytes and x is passed as 2, the return value will be position [2] in the array. If x is NOT passed, the function will default to returning a string, all uppercase.
Function | char* get(uint8_t pos) |
---|---|
Parameters | pos - single byte, array location |
Returns | The current BLE MAC Address |