Skip to content

Commit

Permalink
Add BLE application
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Mar 23, 2022
1 parent 4301067 commit 1463b41
Showing 1 changed file with 62 additions and 15 deletions.
77 changes: 62 additions & 15 deletions user/tests/app/ble/prov_mode/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,82 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

// ***********
// IN PROGRESS
// ***********

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

Serial1LogHandler log(115200, LOG_LEVEL_ALL);

// Serial1LogHandler logHandler(115200, LOG_LEVEL_ALL);
STARTUP(System.enableFeature(FEATURE_DISABLE_LISTENING_MODE));

const char* advServiceUuid = "6E460120-B5A3-F393-E0A9-E50E24DCCA9E";
const char* serviceUuid = "6E400021-B5A3-F393-E0A9-E50E24DCCA9E";
const char* rxUuid = "6E400022-B5A3-F393-E0A9-E50E24DCCA9E";
const char* txUuid = "6E400023-B5A3-F393-E0A9-E50E24DCCA9E";
const char* versionUuid = "6E400024-B5A3-F393-E0A9-E50E24DCCA9E";

// 16-bit UUIDs can also be used
// BleUuid serviceUuid(0x1234);
// BleUuid txUuid(0x5678);
// BleUuid rxUuid(0x9123);
// BleUuid versionUuid(0x8123);

void ble_prov_mode_handler(system_event_t evt, int param) {
if (param == ble_prov_mode_connected) {
Log.info("BLE Event detected: ble_prov_mode_connected");
}
if (param == ble_prov_mode_disconnected) {
Log.info("BLE Event detected: ble_prov_mode_disconnected");
}
if (param == ble_prov_mode_handshake_failed) {
Log.info("BLE Event detected: ble_prov_mode_handshake_failed");
}
if (param == ble_prov_mode_handshake_done) {
Log.info("BLE Event detected: ble_prov_mode_handshake_done");
}
}

void nw_creds_handler(system_event_t evt, int param) {
if (param == network_credentials_added) {
Log.info("BLE Event detected: network_crendetials_added");
}
}

void setup() {
Serial.begin(115200);
// ---------System Events---------
System.on(ble_prov_mode, ble_prov_mode_handler);
System.on(network_credentials, nw_creds_handler);

// ---------Control request filter---------
// System.setControlRequestFilter(SystemControlRequestAclAction::ACCEPT, {
// {CTRL_REQUEST_DFU_MODE, SystemControlRequestAclAction::DENY},
// {CTRL_REQUEST_RESET, SystemControlRequestAclAction::DENY}
// });
System.setControlRequestFilter(SystemControlRequestAclAction::ACCEPT);

// ---------Provisioning Service and Characteristic UUIDs---------
// Provisioning UUIDs must be set before initialising BLE for the first time
BLE.setProvisioningSvcUuid(serviceUuid);
BLE.setProvisioningTxUuid(txUuid);
BLE.setProvisioningRxUuid(rxUuid);
BLE.setProvisioningVerUuid(versionUuid);

LOG(TRACE, "Application started.");
// ---------Custom mobile secret---------
// Uncomment the following three lines with user defined custom mobile secret as needed
// char arr[HAL_DEVICE_SECRET_SIZE] = {};
// memcpy(arr, "0123456789abcde", HAL_DEVICE_SECRET_SIZE);
// hal_set_device_secret(arr, sizeof(arr), nullptr);
// To clear device secret and use default, run this API -> hal_clear_device_secret(nullptr);

// Must run before initialising BLE for the first time
// Even better to call in STARTUP()
BLE.setProvisioningUuids(serviceUuid, txUuid, rxUuid);
// ---------Setup device name---------
BLE.setDeviceName("aabbccdd", 8);

// ---------Set company ID---------
BLE.setProvisioningCompanyId(0x1234);

// ---------BLE provisioning mode---------
BLE.provisioningMode(true);
LOG(TRACE, "BLE prov mode status: %d", BLE.provisioningStatus());
LOG(TRACE, "BLE prov mode status: %d", BLE.getProvisioningStatus());
// To exit provisioning mode, run this API -> BLE.provisioningMode(false);

}

void loop() {
}
}

0 comments on commit 1463b41

Please sign in to comment.