Chreece / BTHomeV2-ESP32-example

An BTHome v2 example with encryption for ESP32
MIT License
35 stars 7 forks source link

Example isn't working for all the sensors at once #3

Closed Chreece closed 1 year ago

Chreece commented 1 year ago

The example works only for the first two sensors (illuminance, pressure), the rest doesn't get recognised in HA.

countrysideboy commented 1 year ago

How about increase the sleep ms from 500 to 1500? I test the example with esp32s and esp32c3.(2.0.8sdk)

Chreece commented 1 year ago

I'm using Firebeetle32 (ESP32-Wroom-32E) The encryption example doesn't work, even for one sensor :(

countrysideboy commented 1 year ago

I'm using Firebeetle32 (ESP32-Wroom-32E) The encryption example doesn't work, even for one sensor :(

Use a shorter device name? ”DIY”

Chreece commented 1 year ago

Yes that did it! Even with one sensor though using only 3 letters is kinda a limitation... I will look into it. My thought adding multisensors are that the user should add them all together ( bthome.addMeasurement)) and the .cpp should count the lenght and "chop" the pakets, sending them seperately. The only input from user, should be the name, bind key and the sensors / states. That's my goal... Will work on that when I have some spare time... Thank you a lot for your hard work!!!

Chreece commented 1 year ago

With one sensor the example works perfect, adding more than one, even with a bigger delay (3000) doesn't make any change in HA

countrysideboy commented 1 year ago

With one sensor the example works perfect, adding more than one, even with a bigger delay (3000) doesn't make any change in HA

My homeassisant will add more than one sensor, it takes some time.And I just delay 500ms in my demo project. Or you can try this way below:

Sensor1 bthome.resetMeasurement(); bthome.addMeasurement... bthome.buildPaket... bthome.start(); delay... bthome.stop();

Sensor2 bthome.resetMeasurement(); bthome.addMeasurement... bthome.buildPaket... bthome.start(); delay... bthome.stop();

countrysideboy commented 1 year ago

Yes that did it! Even with one sensor though using only 3 letters is kinda a limitation... I will look into it. My thought adding multisensors are that the user should add them all together ( bthome.addMeasurement)) and the .cpp should count the lenght and "chop" the pakets, sending them seperately. The only input from user, should be the name, bind key and the sensors / states. That's my goal... Will work on that when I have some spare time... Thank you a lot for your hard work!!!

I prefer to chop the packet manually cause I use the PT_SLEEP(pt, 500) macro from #include "protothreads.h" to make the thread non-block in the loop.

If the .cpp could chop the packet auto, we should find the proper way to avoid using the delay funtion.

Chreece commented 1 year ago

do you have any BTHome related errors in ha?

countrysideboy commented 1 year ago

do you have any BTHome related errors in ha?

No. It works well with my hass.

countrysideboy commented 1 year ago

I think I have solved it with another way.

Chreece commented 1 year ago

I have also found a way to send a String for BIND_KEY I'm waiting for your code first

Chreece commented 1 year ago

That works much better! I will add now the change to the Bind key to be passed as String, making it more user-friendly

Chreece commented 1 year ago

You can test it if you want. My opinion is still that the user shouldn't care about counting the bytes, should just send the values of the sensors and the code should take care of the rest (cropping the pakets and send them so that everything always works) My thought making this example was to be as less complicated and user friendly as it could... I will give it a try to solve this

Thank you once more, you are a great help on this project, most of the code couldn't be here without you!

countrysideboy commented 1 year ago

It would be nice if the code could deal with the data length and chop the adv packet itself. I hope that the bindkey could support not only string but also the char or byte array.

countrysideboy commented 1 year ago

By the way, can your ha display all the sensor entities with the new code?

Chreece commented 1 year ago

Let's continue the discussion here