Improve manufacturer data discovery on Windows (#38)
* Improve manufacturer data discovery on Windows * Switch pairing protection level to encrypted in Windows * Minor UI improvement in example app * Update windows/src/universal_ble_plugin.h * Remove minimum DevicePairingProtectionLevel * Improve logging * Bump version --------- Co-authored-by: Rohit Sangwan <rohitsangwan647@gmail.com>
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.9.8
|
||||||
|
* Improve manufacturer data discovery on Windows
|
||||||
|
* Example app improvements
|
||||||
|
|
||||||
## 0.9.7
|
## 0.9.7
|
||||||
* Fix characteristic keying on linux allowing receiving data from multiple BLE devices at the same time
|
* Fix characteristic keying on linux allowing receiving data from multiple BLE devices at the same time
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ class ScannedItemWidget extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(scanResult.deviceId),
|
Text(scanResult.deviceId),
|
||||||
// Show manufacturer data only on web and desktop
|
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: (Platform.isWeb || Platform.isDesktop) &&
|
visible: scanResult.manufacturerData?.isNotEmpty == true,
|
||||||
scanResult.manufacturerData?.isNotEmpty == true,
|
|
||||||
child: Text(
|
child: Text(
|
||||||
ManufacturerData.fromData(scanResult.manufacturerData!)
|
Platform.isWeb || Platform.isDesktop
|
||||||
.toString(),
|
? ManufacturerData.fromData(scanResult.manufacturerData!)
|
||||||
|
.toString()
|
||||||
|
: 'ManufacturerCompanyId: ${ManufacturerData.fromData(scanResult.manufacturerData!).companyIdRadix16}',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Visibility(
|
Visibility(
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
|||||||
|
|
||||||
void _addLog(String type, dynamic data) {
|
void _addLog(String type, dynamic data) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_logs.add('$type : ${data.toString()}');
|
_logs.add('$type: ${data.toString()}');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
|||||||
void _handlePairingStateChange(
|
void _handlePairingStateChange(
|
||||||
String deviceId, bool isPaired, String? error) {
|
String deviceId, bool isPaired, String? error) {
|
||||||
print('OnPairStateChange $deviceId, $isPaired');
|
print('OnPairStateChange $deviceId, $isPaired');
|
||||||
if (error != null) {
|
if (error != null && error.isNotEmpty) {
|
||||||
_addLog("PairStateChangeError", "(Paired: $isPaired): $error ");
|
_addLog("PairStateChangeError", "(Paired: $isPaired): $error ");
|
||||||
} else {
|
} else {
|
||||||
_addLog("PairStateChange", isPaired);
|
_addLog("PairStateChange", isPaired);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: universal_ble
|
name: universal_ble
|
||||||
description: A cross-platform (Android/iOS/macOS/Windows/Linux/Web) Bluetooth Low Energy (BLE) plugin for Flutter
|
description: A cross-platform (Android/iOS/macOS/Windows/Linux/Web) Bluetooth Low Energy (BLE) plugin for Flutter
|
||||||
version: 0.9.7
|
version: 0.9.8
|
||||||
homepage: https://navideck.com
|
homepage: https://navideck.com
|
||||||
repository: https://github.com/Navideck/universal_ble
|
repository: https://github.com/Navideck/universal_ble
|
||||||
issue_tracker: https://github.com/Navideck/universal_ble/issues
|
issue_tracker: https://github.com/Navideck/universal_ble/issues
|
||||||
|
|||||||
@@ -411,6 +411,7 @@ namespace universal_ble
|
|||||||
auto customPairing = deviceInformation.Pairing().Custom();
|
auto customPairing = deviceInformation.Pairing().Custom();
|
||||||
winrt::event_token token = customPairing.PairingRequested([this](const Enumeration::DeviceInformationCustomPairing &sender, const Enumeration::DevicePairingRequestedEventArgs &eventArgs)
|
winrt::event_token token = customPairing.PairingRequested([this](const Enumeration::DeviceInformationCustomPairing &sender, const Enumeration::DevicePairingRequestedEventArgs &eventArgs)
|
||||||
{
|
{
|
||||||
|
std::cout << "PairLog: Pairing requested" << std::endl;
|
||||||
// eventArgs.AcceptWithPasswordCredential(nullptr, nullptr);
|
// eventArgs.AcceptWithPasswordCredential(nullptr, nullptr);
|
||||||
// eventArgs.Pin();
|
// eventArgs.Pin();
|
||||||
// Accept all pairing request
|
// Accept all pairing request
|
||||||
@@ -419,8 +420,7 @@ namespace universal_ble
|
|||||||
// DevicePairingProtectionLevel => Default, None, Encryption, EncryptionAndAuthentication
|
// DevicePairingProtectionLevel => Default, None, Encryption, EncryptionAndAuthentication
|
||||||
std::cout << "PairLog: Trying to pair" << std::endl;
|
std::cout << "PairLog: Trying to pair" << std::endl;
|
||||||
auto async_c = customPairing.PairAsync(
|
auto async_c = customPairing.PairAsync(
|
||||||
Enumeration::DevicePairingKinds::ConfirmOnly,
|
Enumeration::DevicePairingKinds::ConfirmOnly);
|
||||||
Enumeration::DevicePairingProtectionLevel::None);
|
|
||||||
async_c.Completed([this, customPairing, token, device_id](IAsyncOperation<DevicePairingResult> const &sender, AsyncStatus const args)
|
async_c.Completed([this, customPairing, token, device_id](IAsyncOperation<DevicePairingResult> const &sender, AsyncStatus const args)
|
||||||
{
|
{
|
||||||
auto result = sender.GetResults();
|
auto result = sender.GetResults();
|
||||||
@@ -549,7 +549,7 @@ namespace universal_ble
|
|||||||
|
|
||||||
// Send device to callback channel
|
// Send device to callback channel
|
||||||
// if device is already discovered in deviceWatcher then merge the scan result
|
// if device is already discovered in deviceWatcher then merge the scan result
|
||||||
void UniversalBlePlugin::pushUniversalScanResult(UniversalBleScanResult scanResult)
|
void UniversalBlePlugin::pushUniversalScanResult(UniversalBleScanResult scanResult, bool isConnectable)
|
||||||
{
|
{
|
||||||
auto it = scanResults.find(scanResult.device_id());
|
auto it = scanResults.find(scanResult.device_id());
|
||||||
if (it != scanResults.end())
|
if (it != scanResults.end())
|
||||||
@@ -590,8 +590,11 @@ namespace universal_ble
|
|||||||
scanResults.insert(std::make_pair(scanResult.device_id(), scanResult));
|
scanResults.insert(std::make_pair(scanResult.device_id(), scanResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiThreadHandler_.Post([scanResult]
|
if (isConnectable)
|
||||||
{ callbackChannel->OnScanResult(scanResult, SuccessCallback, ErrorCallback); });
|
{
|
||||||
|
uiThreadHandler_.Post([scanResult]
|
||||||
|
{ callbackChannel->OnScanResult(scanResult, SuccessCallback, ErrorCallback); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UniversalBlePlugin::setupDeviceWatcher()
|
void UniversalBlePlugin::setupDeviceWatcher()
|
||||||
@@ -690,7 +693,7 @@ namespace universal_ble
|
|||||||
universalScanResult.set_rssi(rssi);
|
universalScanResult.set_rssi(rssi);
|
||||||
}
|
}
|
||||||
|
|
||||||
pushUniversalScanResult(universalScanResult);
|
pushUniversalScanResult(universalScanResult, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,10 +702,6 @@ namespace universal_ble
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Avoid devices if they are not connectable
|
|
||||||
if (!args.IsConnectable())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Apply ManufacturerData filter
|
// Apply ManufacturerData filter
|
||||||
if (!manufacturerScanFilter.empty())
|
if (!manufacturerScanFilter.empty())
|
||||||
{
|
{
|
||||||
@@ -717,6 +716,7 @@ namespace universal_ble
|
|||||||
auto deviceId = _mac_address_to_str(args.BluetoothAddress());
|
auto deviceId = _mac_address_to_str(args.BluetoothAddress());
|
||||||
auto universalScanResult = UniversalBleScanResult(deviceId);
|
auto universalScanResult = UniversalBleScanResult(deviceId);
|
||||||
std::string name = winrt::to_string(args.Advertisement().LocalName());
|
std::string name = winrt::to_string(args.Advertisement().LocalName());
|
||||||
|
auto manufacturerData = parseManufacturerDataHead(args.Advertisement(), deviceId);
|
||||||
|
|
||||||
auto dataSection = args.Advertisement().DataSections();
|
auto dataSection = args.Advertisement().DataSections();
|
||||||
for (auto &&data : dataSection)
|
for (auto &&data : dataSection)
|
||||||
@@ -737,8 +737,9 @@ namespace universal_ble
|
|||||||
if (!name.empty())
|
if (!name.empty())
|
||||||
universalScanResult.set_name(name);
|
universalScanResult.set_name(name);
|
||||||
|
|
||||||
auto manufacturerData = parseManufacturerDataHead(args.Advertisement(), deviceId);
|
if (!manufacturerData.empty())
|
||||||
universalScanResult.set_manufacturer_data_head(manufacturerData);
|
universalScanResult.set_manufacturer_data_head(manufacturerData);
|
||||||
|
|
||||||
universalScanResult.set_rssi(args.RawSignalStrengthInDBm());
|
universalScanResult.set_rssi(args.RawSignalStrengthInDBm());
|
||||||
|
|
||||||
// Add services
|
// Add services
|
||||||
@@ -765,7 +766,7 @@ namespace universal_ble
|
|||||||
universalScanResult.set_name(winrt::to_string(deviceInfo.Name()));
|
universalScanResult.set_name(winrt::to_string(deviceInfo.Name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pushUniversalScanResult(universalScanResult);
|
pushUniversalScanResult(universalScanResult, args.IsConnectable());
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace universal_ble
|
|||||||
|
|
||||||
void setupDeviceWatcher();
|
void setupDeviceWatcher();
|
||||||
void disposeDeviceWatcher();
|
void disposeDeviceWatcher();
|
||||||
void pushUniversalScanResult(UniversalBleScanResult scanResult);
|
void pushUniversalScanResult(UniversalBleScanResult scanResult, bool isConnectable);
|
||||||
void BluetoothLEWatcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args);
|
void BluetoothLEWatcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args);
|
||||||
void onDeviceInfoReceived(DeviceInformation deviceInfo);
|
void onDeviceInfoReceived(DeviceInformation deviceInfo);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user