LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2019, 01:37 AM   #1
ba_kirang
LQ Newbie
 
Registered: Apr 2012
Posts: 18

Rep: Reputation: Disabled
C++ Tinyb ble temperature reader application gives constant readings which doesn't reflect the actual temperature variation


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

I am developing in c++ using intel's tinyb library which requires bluez.

Relevant code snippet:
Code:
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 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.

I also changed the advertisement frequency in the bluemaestro device.

How to resolve this ?
 
Old 05-27-2019, 03:33 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by ba_kirang View Post
This 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.
Then the obvious question to ask is what changed between when it worked, and when it no longer worked.

Did you make a change to your application code, intentionally or otherwise? Something obviously changed and it is possible but unlikely to be due to the operating system.

Review your code carefully and verify that each variable and your loop parameters are what you think they are at each point. Use a few printfs or couts to see the values at each point, and/or use gdb to trace the internal state if necessary.

Set up a minimal test case which demonstrates the unexpected behavior and verify that you have correctly polled the sensor according to its documentation, and that you correctly handle the resulting data array it returns.

Last edited by astrogeek; 05-27-2019 at 03:34 PM. Reason: tpoys
 
  


Reply

Tags
bluetooth, bluez, iot, sensor, ubuntu 18.04



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lubuntu 15.04 "error: invalid string constant "thunar-statusbar", expected valid string constant" error knobby67 Ubuntu 1 12-09-2016 12:19 AM
Does iwconfig reflect a wireless network's actual speed? julianvb Linux - Software 2 02-06-2015 05:59 PM
LXer: Linux-friendly Sitara COM adds MIMO WiFi, BLE 4.0 LXer Syndicated Linux News 0 07-31-2014 07:50 PM
Slackware 13. Which Variation Are You Running? cwizardone Slackware 58 01-04-2010 10:17 AM
"CPU temperature above threshold" readings are wrong i think akudewan Linux - Hardware 18 04-08-2009 08:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration