forked from arendst/Tasmota
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
track BLE devices with RPA (arendst#22300)
- Loading branch information
Showing
47 changed files
with
991 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
...p32_div/esp-nimble-cpp/examples/NimBLE_active_passive_scan/NimBLE_active_passive_scan.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +0,0 @@ | ||
/* | ||
* NimBLE Scan active/passive switching demo | ||
* | ||
* Demonstrates the use of the scan callbacks while alternating between passive and active scanning. | ||
*/ | ||
|
||
#include "NimBLEDevice.h" | ||
int scanTime = 5 * 1000; // In milliseconds, 0 = scan forever | ||
BLEScan* pBLEScan; | ||
|
||
bool active = false; | ||
|
||
class scanCallbacks: public NimBLEScanCallbacks { | ||
|
||
void onDiscovered(NimBLEAdvertisedDevice* advertisedDevice) { | ||
Serial.printf("Discovered Advertised Device: %s \n", advertisedDevice->toString().c_str()); | ||
} | ||
|
||
void onResult(NimBLEAdvertisedDevice* advertisedDevice) { | ||
Serial.printf("Advertised Device Result: %s \n", advertisedDevice->toString().c_str()); | ||
} | ||
|
||
void onScanEnd(NimBLEScanResults results){ | ||
Serial.println("Scan Ended"); | ||
active = !active; | ||
pBLEScan->setActiveScan(active); | ||
Serial.printf("scan start, active = %u\n", active); | ||
pBLEScan->start(scanTime); | ||
} | ||
}; | ||
|
||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.println("Scanning..."); | ||
|
||
NimBLEDevice::init(""); | ||
pBLEScan = NimBLEDevice::getScan(); | ||
pBLEScan->setScanCallbacks(new scanCallbacks()); | ||
pBLEScan->setActiveScan(active); | ||
pBLEScan->setInterval(100); | ||
pBLEScan->setWindow(99); | ||
pBLEScan->start(scanTime); | ||
} | ||
|
||
void loop() { | ||
} | ||
7 changes: 7 additions & 0 deletions
7
lib/libesp32_div/esp-nimble-cpp/examples/NimBLE_server_get_client_name/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
set(SUPPORTED_TARGETS esp32) | ||
project(NimBLE_server_get_client_name) |
4 changes: 4 additions & 0 deletions
4
lib/libesp32_div/esp-nimble-cpp/examples/NimBLE_server_get_client_name/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(COMPONENT_SRCS "main.cpp") | ||
set(COMPONENT_ADD_INCLUDEDIRS ".") | ||
|
||
register_component() |
83 changes: 83 additions & 0 deletions
83
lib/libesp32_div/esp-nimble-cpp/examples/NimBLE_server_get_client_name/main/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** NimBLE_server_get_client_name | ||
* | ||
* Demonstrates 2 ways for the server to read the device name from the connected client. | ||
* | ||
* Created: on June 24 2024 | ||
* Author: H2zero | ||
* | ||
*/ | ||
|
||
#include <NimBLEDevice.h> | ||
|
||
// See the following for generating UUIDs: | ||
// https://www.uuidgenerator.net/ | ||
|
||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" | ||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" | ||
#define ENC_CHARACTERISTIC_UUID "9551f35b-8d91-42e4-8f7e-1358dfe272dc" | ||
|
||
NimBLEServer* pServer; | ||
|
||
class ServerCallbacks : public NimBLEServerCallbacks { | ||
// Same as before but now includes the name parameter | ||
void onConnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, std::string& name) override { | ||
printf("Client address: %s Name: %s\n", connInfo.getAddress().toString().c_str(), name.c_str()); | ||
} | ||
|
||
// Same as before but now includes the name parameter | ||
void onAuthenticationComplete(const NimBLEConnInfo& connInfo, const std::string& name) override { | ||
if (!connInfo.isEncrypted()) { | ||
NimBLEDevice::getServer()->disconnect(connInfo.getConnHandle()); | ||
printf("Encrypt connection failed - disconnecting client\n"); | ||
return; | ||
} | ||
|
||
printf("Encrypted Client address: %s Name: %s\n", connInfo.getAddress().toString().c_str(), name.c_str()); | ||
} | ||
}; | ||
|
||
extern "C" void app_main(void) { | ||
printf("Starting BLE Server!\n"); | ||
|
||
NimBLEDevice::init("Connect to me!"); | ||
NimBLEDevice::setSecurityAuth(true, false, true); // Enable bonding to see full name on phones. | ||
|
||
pServer = NimBLEDevice::createServer(); | ||
NimBLEService* pService = pServer->createService(SERVICE_UUID); | ||
NimBLECharacteristic* pCharacteristic = | ||
pService->createCharacteristic(CHARACTERISTIC_UUID, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE); | ||
pCharacteristic->setValue("Hello World says NimBLE!"); | ||
|
||
NimBLECharacteristic* pEncCharacteristic = pService->createCharacteristic( | ||
ENC_CHARACTERISTIC_UUID, | ||
(NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC)); | ||
pEncCharacteristic->setValue("Hello World says NimBLE Encrypted"); | ||
|
||
pService->start(); | ||
|
||
pServer->setCallbacks(new ServerCallbacks()); | ||
pServer->getPeerNameOnConnect(true); // Setting this will enable the onConnect callback that provides the name. | ||
|
||
BLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising(); | ||
pAdvertising->addServiceUUID(SERVICE_UUID); | ||
pAdvertising->setScanResponse(true); | ||
|
||
pAdvertising->start(); | ||
printf("Advertising started, connect with your phone.\n"); | ||
|
||
while (true) { | ||
auto clientCount = pServer->getConnectedCount(); | ||
if (clientCount) { | ||
printf("Connected clients:\n"); | ||
for (auto i = 0; i < clientCount; ++i) { | ||
NimBLEConnInfo peerInfo = pServer->getPeerInfo(i); | ||
printf("Client address: %s Name: %s\n", peerInfo.getAddress().toString().c_str(), | ||
// This function blocks until the name is retrieved, so cannot be used in callback functions. | ||
pServer->getPeerName(peerInfo).c_str()); | ||
|
||
} | ||
} | ||
|
||
vTaskDelay(pdMS_TO_TICKS(10000)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.