Closed Chreece closed 1 year ago
I did an analyze and the packet corresponds the states and object ids, can't find anything wrong but still got the errors
From the bt home.io
Object ids have to be applied in numerical order (from low to high) in your advertisement. This will make sure that if you have a device (sensor) that is broadcasting a new measurement type that is added in a new (minor) BTHome update, while your BTHome receiver isn't updated yet to the same version, it will still be able to receive the older supported measurement types. A BTHome receiver will stop parsing object ids as soon as it finds an object id that isn't supported.
Try adjust the addMeasurement order by the object_id?
Now I understand what that means... Could we do that sorting in the code?
Like: addmeasurement could collect all the data in an table, sort them, for every line in table check if it could pass in the packet then add it else chop them in to packets
We may sort one m_sensorData array by the object id, but the packet chop logic now is to send packet immediately when the adv data will be overload, it cannot ensure the order of object id in different adv packet.
The simplest method currently is to adjust the order manually. The code side solution may require recording all data and sorting it, which may take up additional ram resource.
If we add a new variable that holds an array of the individual object ids + states. Then it could be easy to sort them and chop them, or not?
If we add a new variable that holds an array of the individual object ids + states. Then it could be easy to sort them and chop them, or not?
It’s so true.
Could we have in this line a sort, checking the first byte without much resources needed?
for (i = 0; i < this->m_sensorDataIdx; i++)
{
serviceData += this->m_sensorData[i]; // Add the sensor data to the Service Data
}
(see lines 170-173 in .cpp)
*Sorry my c++ knowledge is very limited :( I just copy-paste codes...
I may sort one adv packet of the sensorData array with no much ram cost, but I cannot sort it in two or more adv packet, it need additional ram to store all the data.
I thought that the sensor data represent one element in the this->m_sensorData variable which could do the sorting easy, and tried to implement this, but each element on the array is just a byte making it difficult to distinguish every sensor data since they are not the same lenght. So now I understand why you are against of Autosort.
Still I think we must offer this option to users that probably will send 2-3 sensor data and don't care to learn how to manually sort them. Users that just want a simple method to send data to HA. Users that don't care about how effective is the code...
What do you think about it?
I will try to write a fuction call sortsensorData() in this weekend to deal with the order in just one adv packet, even though every object id has different length.
Finally, I use a struct to store each sensor data, sort it,and rewrite to the m_sensorData array.
The code will auto decide if sort the data or not, but I prefer to adjust the order manually.
Finally, I use a struct to store each sensor data, sort it,and rewrite to the m_sensorData array.
The code will auto decide if sort the data or not, but I prefer to adjust the order manually.
Thank you for your hard work! From my side the project is fine as it is now... This repository may be under my name but most of the effort came from you! If you want you can send me your paypal account to add a button on the Readme for spendings for you... I'm closing this issue as resolved!
Finally, I use a struct to store each sensor data, sort it,and rewrite to the m_sensorData array. The code will auto decide if sort the data or not, but I prefer to adjust the order manually.
Thank you for your hard work! From my side the project is fine as it is now... This repository may be under my name but most of the effort came from you! If you want you can send me your paypal account to add a button on the Readme for spendings for you... I'm closing this issue as resolved!
Thanks. As the bthome is an opensoure standard of ble, I think my modifications to this project should be non-profit.
Measurements: