01-06-2021 12:31 PM
Hi,
I am working a project with BME680 and MKL27 microcontroller. I am trying to get VOC and CO2 values.
But the values are not changed also after long time, and also IAQ.
I am not sure, but I guess the problem from timestamp. I found some examples of the function. But they are not declared in my program.
Can you help me about that or give me some other examples in c?
Under the text, I added my log of outputs and timestamp function.
The result :
2021-01-06 11:13:06,[Timestamp(88840)],[IAQ (0)]: 25.000000,[T degC]: 28.299999,[H %rH]: 20.97,[P hPa]: 1008.84,[G Ohms]: 13053,[S]: 0,[static IAQ]: 25.00,[eCO2 ppm]: 500.000000000000000,[bVOCe ppm]: 0.4999999403953552246093750
2021-01-06 11:13:10,[Timestamp(88840)],[IAQ (0)]: 25.000000,[T degC]: 28.307171,[H %rH]: 21.15,[P hPa]: 1008.90,[G Ohms]: 7311,[S]: 0,[static IAQ]: 25.00,[eCO2 ppm]: 500.000000000000000,[bVOCe ppm]: 0.4999999403953552246093750
2021-01-06 11:15:04,[Timestamp(88840)],[IAQ (0)]: 25.000000,[T degC]: 28.411655,[H %rH]: 20.38,[P hPa]: 1008.78,[G Ohms]: 7079,[S]: 0,[static IAQ]: 25.00,[eCO2 ppm]: 500.000000000000000,[bVOCe ppm]: 0.4999999403953552246093750
2021-01-06 11:15:05,[Timestamp(88840)],[IAQ (0)]: 25.000000,[T degC]: 29.838865,[H %rH]: 19.25,[P hPa]: 1008.86,[G Ohms]: 8275,[S]: 0,[static IAQ]: 25.00,[eCO2 ppm]: 500.000000000000000,[bVOCe ppm]: 0.4999999403953552246093750
2021-01-06 11:15:07,[Timestamp(88840)],[IAQ (0)]: 25.000000,[T degC]: 28.525309,[H %rH]: 20.44,[P hPa]: 1008.78,[G Ohms]: 9109,[S]: 0,[static IAQ]: 25.00,[eCO2 ppm]: 500.000000000000000,[bVOCe ppm]: 0.4999999403953552246093750
2021-01-06 11:15:10,[Timestamp(88840)],[IAQ (0)]: 25.000000,[T degC]: 28.405308,[H %rH]: 20.41,[P hPa]: 1008.78,[G Ohms]: 10129,[S]: 0,[static IAQ]: 25.00,[eCO2 ppm]: 500.000000000000000,[bVOCe ppm]: 0.4999999403953552246093750
get_timestamp_us function :
int64_t get_timestamp_us()
{
struct timeval tv;
uint64_t ret;
if(gettimeofday(&tv, NULL) < 0)
{
printf("gettimeofday() error\r\n");
return -1;
}
uint64_t millis = (tv.tv_sec) * 1000000 + (tv.tv_usec);//uint64_t millis = (tv.tv_sec) * 1000 + (tv.tv_usec)/1000;
return millis;
}
tv_sec value is for example, 1609930499 and tv_usec 0 or under 0. I see just 0x0.
I got the value of millis 662800064. I am not sure, whether it is right.
Solved! Go to Solution.
01-06-2021 10:30 PM
Hello Physolo,
As you guess, your problem could be the get_timestamp_us function.
The function shall be your system timestamp based on micro second unit. 🙂
So, if the program call the function twice, it can measure some system time between it.
Thanks,
01-07-2021 10:41 AM
Hello Minhwan,
thank you for your answer.
I have more question.
Does the function, get_timestamp_us, mean time in epoch, realtime or time from starting the program, I mean 0us?
Should the value of this change while running?
Thanks
01-07-2021 07:29 PM
Hello Physolo,
As timestamp, the value should be changing during runtime.
Thanks,
01-07-2021 09:26 PM - edited 01-08-2021 09:42 AM
Hello Minhwan,
I corrected that function like as start time in us - run time in us. The value of IAQ accuracy was 1 after 5 minutes and rise to 2 after 10 minutes. I saw the value 3 after 13 minutes.
Does it mean that it works?
And I have one more question. If the return value of the function, timestamp_us, is over 1000000, Should it initialise as 0? I mean, Whether I just check microseconds.
Thanks a lot for your help