forked from h2zero/esp-nimble-cpp
[Breaking] Change all time input parameters to milliseconds. (#78)
Changes all functions that accept a time parameter to use milliseconds instead of seconds. * Adds duration input to NimBLEDevice::startAdvertising and NimBLEServer::startAdvertising.
This commit is contained in:
@@ -16,7 +16,7 @@ void scanEndedCB(NimBLEScanResults results);
|
||||
static NimBLEAdvertisedDevice* advDevice;
|
||||
|
||||
static bool doConnect = false;
|
||||
static uint32_t scanTime = 0; /** 0 = scan forever */
|
||||
static uint32_t scanTime = 0; /** scan time in milliseconds, 0 = scan forever */
|
||||
|
||||
|
||||
/** None of these are required as they will be handled by the library with defaults. **
|
||||
|
||||
@@ -18,7 +18,7 @@ void scanEndedCB(NimBLEScanResults results);
|
||||
|
||||
static NimBLEAdvertisedDevice* advDevice;
|
||||
static bool doConnect = false;
|
||||
static uint32_t scanTime = 10; /* 0 = scan forever */
|
||||
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
|
||||
|
||||
/* Define the PHY's to use when connecting to peer devices, can be 1, 2, or all 3 (default).*/
|
||||
static uint8_t connectPhys = BLE_GAP_LE_PHY_CODED_MASK | BLE_GAP_LE_PHY_1M_MASK /*| BLE_GAP_LE_PHY_2M_MASK */ ;
|
||||
@@ -79,8 +79,8 @@ bool connectToServer() {
|
||||
*/
|
||||
pClient->setConnectPhy(connectPhys);
|
||||
|
||||
/** Set how long we are willing to wait for the connection to complete (seconds), default is 30. */
|
||||
pClient->setConnectTimeout(10);
|
||||
/** Set how long we are willing to wait for the connection to complete (milliseconds), default is 30000. */
|
||||
pClient->setConnectTimeout(10 * 1000);
|
||||
|
||||
if (!pClient->connect(advDevice)) {
|
||||
/* Created a client but failed to connect, don't need to keep it as it has no data */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* updated by chegewara
|
||||
* updated for NimBLE by H2zero
|
||||
*/
|
||||
|
||||
|
||||
/** NimBLE differences highlighted in comment blocks **/
|
||||
|
||||
/*******original********
|
||||
@@ -38,7 +38,7 @@ static void notifyCallback(
|
||||
}
|
||||
|
||||
/** None of these are required as they will be handled by the library with defaults. **
|
||||
** Remove as you see fit for your needs */
|
||||
** Remove as you see fit for your needs */
|
||||
class MyClientCallback : public BLEClientCallbacks {
|
||||
void onConnect(BLEClient* pclient) {
|
||||
}
|
||||
@@ -120,9 +120,9 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||
/**
|
||||
* Called for each advertising BLE server.
|
||||
*/
|
||||
|
||||
|
||||
/*** Only a reference to the advertised device is passed now
|
||||
void onResult(BLEAdvertisedDevice advertisedDevice) { **/
|
||||
void onResult(BLEAdvertisedDevice advertisedDevice) { **/
|
||||
void onResult(BLEAdvertisedDevice* advertisedDevice) {
|
||||
printf("BLE Advertised Device found: %s\n", advertisedDevice->toString().c_str());
|
||||
|
||||
@@ -171,7 +171,7 @@ void connectTask (void * parameter){
|
||||
/*** Note: write value now returns true if successful, false otherwise - try again or disconnect ***/
|
||||
pRemoteCharacteristic->writeValue((uint8_t*)buf, strlen(buf), false);
|
||||
}else if(doScan){
|
||||
BLEDevice::getScan()->start(0); // this is just eample to start scan after disconnect, most likely there is better way to do it in arduino
|
||||
BLEDevice::getScan()->start(0); // this is just eample to start scan after disconnect, most likely there is better way to do it
|
||||
}
|
||||
|
||||
vTaskDelay(1000/portTICK_PERIOD_MS); // Delay a second between loops.
|
||||
@@ -195,6 +195,6 @@ void app_main(void) {
|
||||
pBLEScan->setActiveScan(true);
|
||||
|
||||
xTaskCreate(connectTask, "connectTask", 5000, NULL, 1, NULL);
|
||||
pBLEScan->start(5, false);
|
||||
pBLEScan->start(5 * 1000, false);
|
||||
} // End of setup.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
extern "C"{void app_main(void);}
|
||||
|
||||
int scanTime = 5; //In seconds
|
||||
int scanTime = 5 * 1000; // In milliseconds, 0 = scan forever
|
||||
BLEScan* pBLEScan;
|
||||
|
||||
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||
|
||||
Reference in New Issue
Block a user