theengs / app

Theengs mobile application to read BLE sensors and push data to an MQTT broker
https://app.theengs.io
GNU General Public License v3.0
37 stars 7 forks source link

Feature Request: Polar H10 #62

Open Marcel8584 opened 1 year ago

Marcel8584 commented 1 year ago

I really like the idea of the App and the project. Unfortunately I understood the concept wrong and thought that all devices are supported. May be it is possible that a Polar Heart Sensor H10 could be supported also. Especially the mobile app is great for all fitness devices. Thank you for your feedback.

DigiH commented 1 year ago

Hi @Marcel8584

would you be able to help with finding out if and what kind of data the Polar H10 freely broadcasts, which we might be able to then reverse engineer to include the decoding into the App?

For finding these advertising broadcasts you could try Humble Explorer on your PC, or if you already have an MQTT broker running on your set-up Theengs Gateway on your PC or OpenMQTTGateway on an ESP32.

Or alternatively you can see the advertising data through the nRFConnect app on your phone.

Marcel8584 commented 1 year ago

Hi @DigiH Thank you very much for your quick answer. I just installed Humble Explorer and got the following result for the Polar H10 sensor. Is this what you meant? Please let me know if I can get more information about the device.

Screenshot_2023-01-30 20 21 11_znjFEN
DigiH commented 1 year ago

I just installed Humble Explorer and got the following result for the Polar H10 sensor. Is this what you meant?

Yes, this is what I meant, great. Now if you could get some more readings like that along with what the Polar app says at the same times about what your heart rate is, so that we can see if there is a relationship between the heart rate and the manufacturerdata - especially what is shown as

hex -> 27 13 38 35

above.

Marcel8584 commented 1 year ago

I tried to combine the data als follows with Humble Explorer:

Hex 23 14 50 4b --> 67 Heartrate Hex 3f 14 3d 40 --> 63 Heartrate Hex 23 14 3d 40 --> 64 Heartrate

I found also an app called BLE Scanner that is able to read the heartbeat data directly (compare attached picture)

IMG_2598

Within this app the Hartrate is combined as follows:

Ox{length=4,bytes=0x103f4504} —> 63 Oxflength=4,bytes=0x1044f503} —> 68 Ox{length=4,bytes=0x10470703} —> 71 Ox{length=6,bytes=0×106050024a02} —> 96

May be this also helps.

DigiH commented 1 year ago

I found also an app called BLE Scanner that is able to read the heartbeat data directly (compare attached picture)

Yes, this was already visible in the Humble Explorer data, that the H10 has a dedicated Bluetooth Heart Rate service, but this is only accessible when connecting to it, unfortunately out of the scope of Decoder and hence the Theengs App :(

The heart rate is encoded there with the second hex ocetet

Ox{length=4,bytes=0x103f4504} —> 63 Oxflength=4,bytes=0x1044f503} —> 68 Ox{length=4,bytes=0x10470703} —> 71 Ox{length=6,bytes=0×106050024a02} —> 96

and I hoped that the same would be accessible in the freely advertised data, without having to connect, but only one of your previous samples seems to correlate

Hex 3f 14 3d 40 --> 63 Heartrate

with the other two not matching, so this one might have been a fluke.

In the BLE Scanner app, if you go back one page you should also see Advertisment Data, and possible see if there might be more information.

Marcel8584 commented 1 year ago

I collected some more data with two apps in parallel, so the data is more synchronouse. On the left side I connected the sensor and on the right side I just traced the advertisement.

IMG_1145

I collected the following data. In my opinion there is a rough correlation between the heart rate and the last HEX value of the advertised data.

Ox{length=4,bytes=0x103fd003} —> HR 63 = 3F Hex 6B 00 37 16 3F 3E

Ox{length=4,bytes=0x10401004) —> HR 64 = 40 Hex 6B 00 27 16 3D 40

Ox{length=4,bytes=0x10444103) —> HR 68 = 44 Hex 6B 00 33 16 40 43

Ox{length=4,bytes=0x10456c03) —> HR 69 = 45 Hex 6B 00 37 16 41 45

Ox{length=4,bytes=0x10469903) —> HR 70 = 46 Hex 6B 00 3B 16 44 46

Ox{length=4,bytes=0x10474703) —>HR 71 = 47 Hex 6B 00 37 16 49 46

Ox{length=6,bytes=0x1057aa029d02} —> HR 87 = 57 Hex 6B 00 2B 16 56 57

Ox{length=4,bytes=0x1059a102) —> HR 89 = 59 Hex 6B 00 2F 16 5A 59

Ox(length=4,bytes=0x105ade02) —> HR 90 6B 00 3F 16 58 59

Oxilength=4,bytes=0x105cbc02) —> HR 92 6B 00 27 16 5E 5D

Oxflength=6,bytes=0x10607f028602] —>HR 96 = 60 Hex 6B 00 33 16 5F 61

0x{length=6,bytes=0x106958025a02} —> HR 105 = 69 Hex 6B 00 2F 16 6B 68

DigiH commented 1 year ago

Great with the additional data.

Did you have to jump back and forth with the screens to record the hex data and then the heart rate? This could explain the slight deviations of the suspected last hex octet with the recorded heart rate, depending on how short a broadcast interval the H10 has.

Just thinking how to best supply a test decoder for you to try out …

@Marcel8584 , you do not have access to an ESP32, do you? Or which desktop PC OS do you use?

Marcel8584 commented 1 year ago

Today I borrowed an ESP32 and already installed the firmware. I am just playing around with the configuration. May be we can test it with this setting?

DigiH commented 1 year ago

Sure, that would be the easiest way, with an ESP32 :)

When you tried OpenMQTTGateway with it, did you have an MQTT broker implemented to connect to and be able to connect to the broker to view its messages?

How did you install the OpenMQTTGateway? Through the web install or a binary install?

I'm just starting a test build which includes the test H10 decoder …

Marcel8584 commented 1 year ago

Yes I have a MQTT broker to view the messages. For the installation I chose the web installation (esp32dev-ble-openhab) Thanks for the great support.

DigiH commented 1 year ago

It'll run for about an hour, then you can go to the test web install page I'll post here once its ready …

Marcel8584 commented 1 year ago

Great, I will try it this evening. Did I understand it correct, that it is also possible to integrate new devices by its own? Based on the "decoder" explanation "ADVANCED: Setting up an external decoder"?

Is there any possibility to access the esp32 via the Mac terminal? Or another question, what is the default user and password of the ESP32 with your firmware? I would love to play around and try to get access to some other ble devices without borrowing you to much. There is a lot of fitness equipment that is broadcasting data via standardized ble protocols. Might be a very nice use case for your project.

DigiH commented 1 year ago

Did I understand it correct, that it is also possible to integrate new devices by its own? Based on the "decoder" explanation "ADVANCED: Setting up an external decoder"?

Correct, for Bluetooth devices Theengs Decoder allows anyone to submit pull requests for new decoders as explained at https://decoder.theengs.io/participate/adding-decoders.html

with Theengs Decoder library then being used for BLE decoding in OpenMQTTGateway, Theengs Gateway, Theengs Explorer, Theengs App …

Is there any possibility to access the esp32 via the Mac terminal?

Not for accessing the interface settings, depending on where and which MQTT broker you are using, but for viewing and also publishing commands to the ESP32 gateway one of the best applications to use is MQTT Explorer

Or another question, what is the default user and password of the ESP32 with your firmware?

https://docs.openmqttgateway.com/upload/portal.html#wifi-and-mqtt-configuration-portal-for-wifi-boards

With the above mentioned MQTT Explorer you can also pubslish different setting commands to the gateway, as explained from https://docs.openmqttgateway.com/use/ble.html#setting-a-white-or-black-list onwards.

I would love to play around and try to get access to some other ble devices without borrowing you to much. There is a lot of fitness equipment that is broadcasting data via standardized ble protocols. Might be a very nice use case for your project.

Any new devices which freely broadcast BLE advertisements and don't require connections we'll be interested in including in Decoder :) Any queries with other new devices, feel free to post in the Theengs Decoder discussions.

The test build is also ready for downloading. If you could install esp32dev-ble-datatest instead of your previously used esp32dev-ble-openhab. It won't have the OpenHAB auto-discovery included, but for test purposes it has more information in the MQTT messages and will scan continuously as to get more frequent updates.

https://docs.openmqttgateway.com/dev/upload/web-install.html

If you could then post a few messages here for confirmation, possibly copied and pasted from MQTT Explorer.

Additionally it would also be good to confirm that the H10 will also still be picked up with passive scanning, which can be set as follows https://docs.openmqttgateway.com/use/ble.html#setting-if-the-gateway-use-active-or-passive-scanning

Marcel8584 commented 1 year ago

In my opinion it is working well. The bpm topic correlates with the heart rate. Attached I send you two messages out of the MQTT Explorer.

Related to the passive scanning, I did not understand how to change the setting. What do I have to do with the command: mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"activescan":false}' Could you probably give me a hint how to do it? Thanks in advance.

{"id":"F5:8B:B4:DC:74:6B","mac_type":1,"adv_type":3,"name":"Polar H10 75087320","manufacturerdata":"6b00331d3637","rssi":-71,"brand":"Polar","model":"Heart Rate Sensor","model_id":"H10","bpm":55}

{"id":"F5:8B:B4:DC:74:6B","mac_type":1,"adv_type":3,"name":"Polar H10 75087320","manufacturerdata":"6b00271d3e3d","rssi":-60,"brand":"Polar","model":"Heart Rate Sensor","model_id":"H10","bpm":61}

DigiH commented 1 year ago

In my opinion it is working well. The bpm topic correlates with the heart rate.

Great, thanks for the confirmation! This new H10 decoder will be included and appear in a future update of the Theengs App as well.

Related to the passive scanning, I did not understand how to change the setting. What do I have to do with the command: mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"activescan":false}' Could you probably give me a hint how to do it? Thanks in advance.

Since you have downloaded MQTT Explorer these commands can easily be published in the applicaiton. Have a look on the right side under the Publish section - as the topic you enter

home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoBT/config

and as content to publish in json format

{"activescan":false}

Screenshot 2023-01-31 at 21 03 28

Hit Publish, and under the BTtoMQTT message heading on the left you should see the included changed … ,"activescan":false, … as a confirmation.

We then just like to know if the recognition and decoding is still the same as above with passive scanning.

Marcel8584 commented 1 year ago

Ok that works and the messages are still good.

May be one final question. I read in a discussion that it is also possible to post all ble data. For example all advertised data without any decoding via Mqtt

Make it possible to get all data?

How would I change the setting or option on the esp32? Thanks for you support and I am looking forward to the update.

DigiH commented 1 year ago

Thanks, so passive scanning is also fine for the H10, and it avoids more battery drain on the devices.

May be one final question. I read in a discussion that it is also possible to post all ble data. For example all advertised data without any decoding via Mqtt

With actually using the esp32dev-ble-datatest web install above, it has the best of both worlds, the decoded information, but also the raw BLE advertisment data, which is the "manufacturerdata":"6b00271d3e3d" part.

If no decoder is found for a device this information with just the manufacturerdata, servicedata and uuid can be published anyway for undecoded devices with setting pubadvdata to true https://docs.openmqttgateway.com/use/ble.html#advanced-publishing-advertisement-data-default-false

If you want a gateway which only transmits undecoded BLE data you can https://docs.openmqttgateway.com/use/ble.html#advanced-setting-up-an-external-decoder or chose the esp32dev-ble-mqtt-undecoded binary/web install.

Thanks for your collaboration on getting this new decoder implemented.

Marcel8584 commented 1 year ago

Thank you too for your support and your work.

1technophile commented 1 year ago

@Marcel8584 if you are interested in testing the new version of the app, could you send an email to florian@theengs.io