Some debugging info

This commit is contained in:
rbaron 2021-03-26 11:43:55 +01:00
parent c2e3723eb0
commit 2aa0ffc27b
3 changed files with 21 additions and 10 deletions

View file

@ -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();
}

View file

@ -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() {

View file

@ -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;
}