fix: NimBLE 128-bit UUID scan response + Android key/UUID loading
- Firmware: add explicit setScanResponseData with setCompleteServices for 128-bit service UUID so Android ScanFilter finds the device - Android: hexStringToBytes accepts any even-length hex (fixes UUID=32chars failing the hardcoded 64-char check) - Android: onActivityResult matches SettingsActivity.RESULT_SCAN instead of Activity.RESULT_OK
This commit is contained in:
parent
96d3620535
commit
d6e37322f3
3 changed files with 12 additions and 5 deletions
Binary file not shown.
|
|
@ -213,7 +213,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if (requestCode == REQUEST_SETTINGS && resultCode == Activity.RESULT_OK) {
|
if (requestCode == REQUEST_SETTINGS && resultCode == SettingsActivity.RESULT_SCAN) {
|
||||||
stopScan()
|
stopScan()
|
||||||
bluetoothGatt?.close()
|
bluetoothGatt?.close()
|
||||||
bluetoothGatt = null
|
bluetoothGatt = null
|
||||||
|
|
@ -260,7 +260,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun hexStringToBytes(hex: String): ByteArray? {
|
private fun hexStringToBytes(hex: String): ByteArray? {
|
||||||
val cleaned = hex.uppercase().filter { it in "0123456789ABCDEF" }
|
val cleaned = hex.uppercase().filter { it in "0123456789ABCDEF" }
|
||||||
if (cleaned.length != 64) return null
|
if (cleaned.isEmpty() || cleaned.length % 2 != 0) return null
|
||||||
return cleaned.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
return cleaned.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
src/main.cpp
13
src/main.cpp
|
|
@ -1,5 +1,6 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <NimBLEDevice.h>
|
#include <NimBLEDevice.h>
|
||||||
|
#include <NimBLEAdvertising.h>
|
||||||
|
|
||||||
#include <mbedtls/md.h>
|
#include <mbedtls/md.h>
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
|
@ -202,13 +203,19 @@ void setup() {
|
||||||
pUuidChar->setValue(deviceUuid, ESP_UUID_LEN);
|
pUuidChar->setValue(deviceUuid, ESP_UUID_LEN);
|
||||||
|
|
||||||
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
|
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
|
||||||
|
pAdvertising->setName("SylDa_Server");
|
||||||
pAdvertising->addServiceUUID(SERVICE_UUID);
|
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||||
|
|
||||||
|
NimBLEAdvertisementData scanResp;
|
||||||
|
scanResp.setCompleteServices(NimBLEUUID(SERVICE_UUID));
|
||||||
|
pAdvertising->setScanResponseData(scanResp);
|
||||||
pAdvertising->enableScanResponse(true);
|
pAdvertising->enableScanResponse(true);
|
||||||
|
|
||||||
pAdvertising->setMinInterval(32);
|
pAdvertising->setMinInterval(32);
|
||||||
pAdvertising->setMaxInterval(64);
|
pAdvertising->setMaxInterval(64);
|
||||||
NimBLEDevice::startAdvertising();
|
bool advOk = pAdvertising->start();
|
||||||
|
Serial.printf("BLE: advertising started as 'SylDa_Server' (start=%d, isAdv=%d)\n",
|
||||||
Serial.println("BLE: advertising started as 'SylDa_Server'");
|
advOk, pAdvertising->isAdvertising());
|
||||||
|
|
||||||
if (keyProvisioned) {
|
if (keyProvisioned) {
|
||||||
Serial.print("HMAC Key: ");
|
Serial.print("HMAC Key: ");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue