tinyb icon indicating copy to clipboard operation
tinyb copied to clipboard

ble temperature reader application gives constant readings which doesn't reflect the actual temperature variation

Open kiran-g opened this issue 6 years ago • 0 comments

I am trying to read temperature values from a BLE Temperature sensor (bluemaestro tempo disc)

I am developing in c++ using tinyb library.

Relevant code snippet:

using Iter = std::vector<std::unique_ptr<tinyb::BluetoothDevice>>::const_iterator;
while (true)
{
    for (Iter it = sensor_tag_array.begin(); it != sensor_tag_array.end(); ++it)
    {
        std::string address_ = (*it)->get_address();

        std::map<uint16_t, std::vector<uint8_t>> mfg__ = (*it)->get_manufacturer_data();
        for (auto it : mfg__)
        {
            if (it.second.empty())
                logger_->error("{}, {} :Empty mfg for : {}", __FILENAME__, __func__, bleMap[address_].sensor_name);
            else
            {
                if (it.second.front() == 23)
                {
                    battery_lvl = it.second[1];
                    first_byte = it.second[6];
                    second_byte = it.second[7];
                    temperature = convert_to_actual(first_byte, second_byte) / 10.0;
                    std::cout << "\nTemperature is for : " << bleMap[address_].sensor_name << " : " << temperature << "\n";
                }
            }
        }
}

This code was properly giving the correct relatime values until now. But suddenly it started printing a single constant reading each time the application is restarted. Whatever temperature value is first read at application startup is repeated throughout the application runtime. I used the tempo utility app to verify that the sensor is actually reporting the correct realtime values.

I tried re-installing the OS (Ubuntu 18.04.1), tried multple version of bluez ( 5.48 which is pre-installed,5.39 and 5.37) but the issue is still there. Tinyb file :libtinyb.so.0.5.1

I also changed the advertisement frequency in the bluemaestro device.

Any idea how to resolve this ?

kiran-g avatar May 21 '19 05:05 kiran-g