Hi all,
I’m running HA under docker running under WSL2 (Windows Subsystem for Linux). This means no Bluetooth at all so I can’t use mitemp_bt or https://github.com/custom-components/sensor.mitemp_bt.
After some research I was able to put together some working Win10 C++ code. It’s just bits and pieces ported from Python and glued together but it works without issues since a couple of days. The code detects BLE devices and connects to them (you can also connect on demand without BLE advertisements and scanning), authorizes with the Xiaomi Sensor (otherwise it drops the connection after 10 seconds), and relays temperature and humidity readings to the MQTT broker. Additionally it polls for the battery level once an hour and also sends that via MQTT.
https://github.com/dzwiedzmin/win-ble-to-mqtt-cpp
Should be easy to add support for other BLE devices and the authorization should work with other Xiaomi products (just change the ProductID)
Hope somebody will find this useful 
3 Likes
Hi, thanks for your effort!
I’ve been trying for the past hours to compile the solution but it always fails.
I’ve installed the dependencies such as SDK 10.0.15063.0 and VS 2017 but it always fails with
"could not find assembly 'platform.winmd': please specify the assembly search path using /AI or by setting the LIBPATH environment variable BLEScanner c:\users\administrator\ble\blescanner\stdafx.cpp
I have changed the lib paths but no success. I am not at all familiar with Visual Studio, so any help would be appreciated!
Thanks
Hi,
I had the same issue. After failing to setup the project dirs I simple copied platform.winmd
and Windows.winmd
files from c:\Program Files (x86)\Windows Kits\10\UnionMetadata\
directly to the project dir and that helped.
Thanks for the replay, I managed to compile it successfully.
However, how do I actually run it?
Do I pass commands from the command line or do I have to edit the file before compiling it? For example, to specify the mqtt server etc
Yeah, all in the code. Look for
mqtt = new mqtt_temphumid(“192.168.68.125”);
change that to
mqtt = new mqtt_temphumid(“YOUR_MQTT_BROKER_IP”, PORT);
Don’t hesitate to ask if you have any more problems, I know this is not documented well,
1 Like