Adds temp and humidity values to the BLE advertisement packet
This commit is contained in:
parent
81b33fbd8c
commit
c2e3723eb0
6 changed files with 29 additions and 12 deletions
|
|
@ -10,7 +10,7 @@
|
|||
#define PRST_DEEP_SLEEP_IN_SECONDS 2
|
||||
|
||||
// BLE.
|
||||
#define PRST_BLE_ADV_NAME "Prst"
|
||||
#define PRST_BLE_ADV_NAME "prst"
|
||||
|
||||
// PWM.
|
||||
#define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 29)
|
||||
|
|
|
|||
|
|
@ -66,19 +66,18 @@ static void rtc_callback() {
|
|||
prst_pwm_start();
|
||||
prst_adc_batt_read_t batt_read = prst_adc_batt_read();
|
||||
prst_pwm_stop();
|
||||
prst_ble_update_adv_data(batt_read.millivolts);
|
||||
prst_ble_update_adv_data(batt_read.millivolts, temp_humi.temp_millicelcius, temp_humi.humidity, 0);
|
||||
prst_adv_start();
|
||||
nrf_delay_ms(200);
|
||||
prst_adv_stop();
|
||||
nrf_gpio_pin_clear(PRST_LED_PIN);
|
||||
UNUSED_VARIABLE(batt_read);
|
||||
// UNUSED_VARIABLE(temp_humi);
|
||||
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(temp_humi.temp_c));
|
||||
NRF_LOG_FLOAT((float) temp_humi.temp_millicelcius / 1000.0));
|
||||
NRF_LOG_INFO("Read humi: " NRF_LOG_FLOAT_MARKER " %%",
|
||||
NRF_LOG_FLOAT(temp_humi.humidity));
|
||||
NRF_LOG_FLOAT(100.0 * temp_humi.humidity / (1 << 16)));
|
||||
NRF_LOG_FLUSH();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
// TODO(rbaron): More info in the adv packet:
|
||||
// - Software version
|
||||
// - Counter
|
||||
|
||||
// We need to pick a service UUID for broadcasting our sensor data.
|
||||
// 0x181a is defined as "environmental sensing", which seems appopriate.
|
||||
|
|
@ -101,10 +102,21 @@ void prst_ble_init() {
|
|||
init_advertisement_data();
|
||||
}
|
||||
|
||||
void prst_ble_update_adv_data(uint16_t batt_millivolts) {
|
||||
void prst_ble_update_adv_data(uint16_t batt_millivolts,
|
||||
uint16_t temp_millicelcius, uint16_t humidity,
|
||||
uint16_t soil_moisture) {
|
||||
service_data[0] = batt_millivolts >> 8;
|
||||
service_data[1] = batt_millivolts & 0xff;
|
||||
|
||||
service_data[2] = temp_millicelcius >> 8;
|
||||
service_data[3] = temp_millicelcius & 0xff;
|
||||
|
||||
service_data[4] = humidity >> 8;
|
||||
service_data[5] = humidity & 0xff;
|
||||
|
||||
service_data[6] = soil_moisture >> 8;
|
||||
service_data[7] = soil_moisture & 0xff;
|
||||
|
||||
// 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);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ void prst_adv_start();
|
|||
|
||||
void prst_adv_stop();
|
||||
|
||||
void prst_ble_update_adv_data(uint16_t batt_millivolts);
|
||||
void prst_ble_update_adv_data(uint16_t batt_millivolts,
|
||||
uint16_t temp_millicelcius, uint16_t humidity,
|
||||
uint16_t soil_moisture);
|
||||
|
||||
#endif // _PRST_BLE_H_
|
||||
|
|
@ -46,9 +46,10 @@ prst_shtc3_read_t prst_shtc3_read() {
|
|||
|
||||
NRF_LOG_INFO("Computing...");
|
||||
double temp_c =
|
||||
-45 + 175 * ((double)((buff[0] << 8) | buff[1])) / ((1 << 16) - 1);
|
||||
double humi = 100 * ((double)((buff[3] << 8) | buff[4])) / ((1 << 16) - 1);
|
||||
-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_c = temp_c, .humidity = humi};
|
||||
prst_shtc3_read_t ret = {.temp_millicelcius = temp_c * 1000, .humidity = humi };
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -13,8 +13,11 @@
|
|||
#define PRST_SHTC3_CMD_MEASURE_TFIRST_LOW_POWER 0x609c
|
||||
|
||||
typedef struct prst_shtc3_values {
|
||||
double temp_c;
|
||||
double humidity;
|
||||
// Temperature in millicelcius. To get the temp in Celcius, divide this by
|
||||
// 1000.0.
|
||||
int16_t temp_millicelcius;
|
||||
// Relative humidity, from 0 to 2^16.
|
||||
uint16_t humidity;
|
||||
} prst_shtc3_read_t;
|
||||
|
||||
void prst_shtc3_init();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue