adabru / BleWinrtDll

BLE for Unity 3d in Windows without UWP.
Do What The F*ck You Want To Public License
169 stars 53 forks source link

Any idea how to add RSSI / signal strength? #10

Closed jadware closed 3 years ago

jadware commented 3 years ago

It is working well for me, thank you. How might it be possible to get RSSI signal strength of the devices that are found in the scan? There may be a property System.Devices.Aep.SignalStrength that can be added to the requested properties list inside StartDeviceScan, but I am not sure how to retrieve its value afterwards.

Much appreciate your help if possible!

adabru commented 3 years ago

Your approach seems good to me.

Add the System.Devices.Aep.SignalStrength property to the requestedProperties in BleWinrtDll.cpp#L268

Add a int32_t signalStrength; property to the DeviceUpdate struct at BleWinrtDll.h#L10.

Populate the field at DeviceWatcher_Updated and DeviceWatcher_Added with:

if (deviceInfoUpdate.Properties().HasKey(L"System.Devices.Aep.SignalStrength")) {
    deviceUpdate.signalStrength = unbox_value<int32_t>(deviceInfoUpdate.Properties().Lookup(L"System.Devices.Aep.SignalStrength"));
}

Add a corresponding C# property at BleApi.cs#L26:

        [MarshalAs(UnmanagedType.I4)]
        public int nameUpdated;

For debugging you can use the DebugBle cli-program or the Microsoft's Bluetooth Low Energy sample.

jadware commented 3 years ago

thanks!! working