From 2aa0ffc27b6dc8eb93ba25e365684d302979dc2b Mon Sep 17 00:00:00 2001 From: rbaron Date: Fri, 26 Mar 2021 11:43:55 +0100 Subject: [PATCH] Some debugging info --- code/b-parasite/src/main.c | 13 +++++++------ code/b-parasite/src/prst/ble.c | 9 ++++++++- code/b-parasite/src/prst/shtc3.c | 9 ++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/code/b-parasite/src/main.c b/code/b-parasite/src/main.c index 0f57e7a..7f33453 100644 --- a/code/b-parasite/src/main.c +++ b/code/b-parasite/src/main.c @@ -67,17 +67,18 @@ static void rtc_callback() { prst_adc_batt_read_t batt_read = prst_adc_batt_read(); prst_pwm_stop(); prst_ble_update_adv_data(batt_read.millivolts, temp_humi.temp_millicelcius, temp_humi.humidity, 0); + NRF_LOG_FLUSH(); prst_adv_start(); nrf_delay_ms(200); prst_adv_stop(); nrf_gpio_pin_clear(PRST_LED_PIN); UNUSED_VARIABLE(batt_read); - NRF_LOG_INFO("Read batt: " NRF_LOG_FLOAT_MARKER " V (%d), %u mV", - NRF_LOG_FLOAT(batt_read.voltage), batt_read.raw, batt_read.millivolts); - NRF_LOG_INFO("Read temp: " NRF_LOG_FLOAT_MARKER " oC", - NRF_LOG_FLOAT((float) temp_humi.temp_millicelcius / 1000.0)); - NRF_LOG_INFO("Read humi: " NRF_LOG_FLOAT_MARKER " %%", - NRF_LOG_FLOAT(100.0 * temp_humi.humidity / (1 << 16))); + // NRF_LOG_INFO("Read batt: " NRF_LOG_FLOAT_MARKER " V (%d), %u mV", + // NRF_LOG_FLOAT(batt_read.voltage), batt_read.raw, batt_read.millivolts); + // NRF_LOG_INFO("Read temp: " NRF_LOG_FLOAT_MARKER " oC", + // NRF_LOG_FLOAT((float) temp_humi.temp_millicelcius / 1000.0)); + // NRF_LOG_INFO("Read humi: " NRF_LOG_FLOAT_MARKER " %%", + // NRF_LOG_FLOAT(100.0 * temp_humi.humidity / (1 << 16))); NRF_LOG_FLUSH(); } diff --git a/code/b-parasite/src/prst/ble.c b/code/b-parasite/src/prst/ble.c index dd3fa6e..8050ff5 100644 --- a/code/b-parasite/src/prst/ble.c +++ b/code/b-parasite/src/prst/ble.c @@ -23,7 +23,7 @@ #define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS) // Sensor data payload that will go into the advertisement message. -#define SERVICE_DATA_LEN 8 +#define SERVICE_DATA_LEN 16 static uint8_t service_data[SERVICE_DATA_LEN]; // Stores the encoded advertisement data. As per BLE spec, 31 bytes max. @@ -117,10 +117,17 @@ void prst_ble_update_adv_data(uint16_t batt_millivolts, service_data[6] = soil_moisture >> 8; service_data[7] = soil_moisture & 0xff; + NRF_LOG_INFO("LETS SEE"); + // Encodes adv_data_ into .gap_adv_data_. uint32_t err_code = ble_advdata_encode( &adv_data_, gap_adv_data_.adv_data.p_data, &gap_adv_data_.adv_data.len); APP_ERROR_CHECK(err_code); + + // NRF_LOG_INFO("Encoded BLE adv packket:"); + // for (int i = 0; i < sizeof(encoded_adv_data_); i++) { + // NRF_LOG_INFO("0x%x ", encoded_adv_data_[i]); + // } } void prst_adv_start() { diff --git a/code/b-parasite/src/prst/shtc3.c b/code/b-parasite/src/prst/shtc3.c index fd9bd29..9cc4eda 100644 --- a/code/b-parasite/src/prst/shtc3.c +++ b/code/b-parasite/src/prst/shtc3.c @@ -44,12 +44,15 @@ prst_shtc3_read_t prst_shtc3_read() { // Uninit i2c. nrf_drv_twi_uninit(&twi_); + // TODO(rbaron): verify the CRC of the measurements. The function is described + // in the datasheet. + NRF_LOG_INFO("Computing..."); - double temp_c = - -45 + 175 * ((double)((buff[0] << 8) | buff[1])) / (1 << 16); + double temp_c = -45 + 175 * ((double)((buff[0] << 8) | buff[1])) / (1 << 16); // double humi = ((double)((buff[3] << 8) | buff[4])) / ((1 << 16) - 1); uint16_t humi = (buff[3] << 8) | buff[4]; - prst_shtc3_read_t ret = {.temp_millicelcius = temp_c * 1000, .humidity = humi }; + prst_shtc3_read_t ret = {.temp_millicelcius = temp_c * 1000, + .humidity = humi}; return ret; } \ No newline at end of file