Languages

Menu
Sites
Language
Sensor recorder time period doesn't follow query settings

I am trying to use the PEDOMETER on Tizen wearable 5.5. I can get the listener to work and return the data. But the data is aggregated to something I can't find documentation about.

I found that I need to do the calculation myself (and found a few samples in here and github) but the behaviour I am expecting when using the recorder is quite weird. Here is my code:


void get_initial_pedometer_data() {
        bool recorderSupported;
	sensor_recorder_is_supported(SENSOR_HUMAN_PEDOMETER, &recorderSupported);
	if (!recorderSupported) {
		dlog_print(DLOG_WARN, LOG_TAG, "Recorder not supported.");
		return;
	}

	sensor_recorder_create_option(&option);
	sensor_recorder_option_set_int(option, SENSOR_RECORDER_OPTION_RETENTION_PERIOD, 24);
	sensor_recorder_start(SENSOR_HUMAN_PEDOMETER, option);
	sensor_recorder_query_h query;
	if (sensor_recorder_create_query(&query) != SENSOR_ERROR_NONE) {
		dlog_print(DLOG_WARN, LOG_TAG, "Cannot create query");
		return;
	}

	time_t nowTimeStamp, midnightTimestamp;
	nowTimeStamp = time(NULL);
	struct tm *tmNow = localtime(&nowTimeStamp);
	midnightTimestamp = nowTimeStamp - (tmNow->tm_hour * 3600) - (tmNow->tm_min * 60) - (tmNow->tm_sec);

    // Here I have checked I have time period from 00h00m to current time

	if (sensor_recorder_query_set_time(query, SENSOR_RECORDER_QUERY_START_TIME,
			(time_t) (time(NULL) - (7 * 24 * 3600))) != SENSOR_ERROR_NONE) {
		dlog_print(DLOG_WARN, LOG_TAG, "Cannot set query START option: %ld.",
				midnightTimestamp);
		return;
	}
	if (sensor_recorder_query_set_time(query, SENSOR_RECORDER_QUERY_END_TIME,
			time(NULL)) != SENSOR_ERROR_NONE) {
		dlog_print(DLOG_WARN, LOG_TAG, "Cannot set query END option: %ld.",
				nowTimeStamp);
		return;
	}
	if (sensor_recorder_query_set_int(query,
			SENSOR_RECORDER_QUERY_TIME_INTERVAL, 24 * 60)
			!= SENSOR_ERROR_NONE) {
		dlog_print(DLOG_WARN, LOG_TAG, "Cannot set query INTERVAL option: %d.",
				24 * 60);
		return;
	}

	if (sensor_recorder_query_set_time(query, SENSOR_RECORDER_QUERY_ANCHOR_TIME,
			midnightTimestamp) != SENSOR_ERROR_NONE) {
		dlog_print(DLOG_WARN, LOG_TAG, "Cannot set query ANCHOR option: %ld.",
				(time_t) (7 * 3600));
		return;
	}

	int error = sensor_recorder_read_sync(SENSOR_HUMAN_PEDOMETER, query,
			sensor_pedometer_data_cb, NULL);
	if (error != SENSOR_ERROR_NONE) {
		dlog_print(DLOG_WARN, LOG_TAG, "Cannot read query: %d", error);
	}
}

 

Then the callback method is:


bool sensor_pedometer_data_cb(sensor_type_e type, sensor_recorder_data_h data, int remains, sensor_error_e error, void *user_data) {
	if (type != SENSOR_HUMAN_PEDOMETER) {
		return true;
	}
	int step;
	time_t start;
	time_t end;

	sensor_recorder_data_get_time(data, &start, &end);
	struct tm *tmStart = localtime(&start);
	dlog_print(DLOG_INFO, LOG_TAG, "Start time: %d %d:%d:%d", tmStart->tm_mday,
			tmStart->tm_hour, tmStart->tm_min, tmStart->tm_sec);
	struct tm *tmEnd = localtime(&end);
	dlog_print(DLOG_INFO, LOG_TAG, "End time: %d %d:%d:%d", tmEnd->tm_mday,
			tmEnd->tm_hour, tmEnd->tm_min, tmEnd->tm_sec);

	sensor_recorder_data_get_int(data, SENSOR_RECORDER_DATA_STEPS, &step);
	step_count += step;
	if (remains == 0) {
		total_steps = step_count;
		step_count = 0;
		int error = sensor_listener_start(listener);
		if (error != SENSOR_ERROR_NONE) {
			dlog_print(DLOG_WARN, LOG_TAG, "Cannot start listener. Error: %d",
					error);
		}
	}
	dlog_print(DLOG_INFO, LOG_TAG, "Step count: %d", total_steps);
	return true;
}

The log printout of the start and end dates are always the same value a any time I run the app, and it is not from midnight to current time, but 2.45pm to 2.46pm (just 1 minute apart). Therefore the "Step count" value is low.

What am I doing wrong?