Merge pull request #188 from jrhbcn/main

Report battery percentage in BLE BTHOME_V2 protocol
This commit is contained in:
rbaron 2024-04-20 13:49:11 +02:00 committed by GitHub
commit e7e4b77eef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -104,30 +104,33 @@ int prst_ble_encode_service_data(const prst_sensors_t* sensors,
out[4] = temp_val & 0xff;
out[5] = temp_val >> 8;
// Humidity.
out[6] = 0x03;
// Value. Factor 0.01, over 100%.
uint16_t humi_val = 10000 * sensors->shtc3.rel_humi;
out[7] = humi_val & 0xff;
out[8] = humi_val >> 8;
out[6] = 0x2E;
// Value. Factor 1 over 100%.
uint8_t humi_val = 100 * sensors->shtc3.rel_humi + 0.5f;
out[7] = humi_val;
// Illuminance.
out[9] = 0x05;
out[8] = 0x05;
// Value. Factor of 0.01.
uint32_t lux_val = sensors->photo.brightness * 100;
out[10] = lux_val & 0xff;
out[11] = (lux_val >> 8) & 0xff;
out[12] = (lux_val >> 16) & 0xff;
out[9] = lux_val & 0xff;
out[10] = (lux_val >> 8) & 0xff;
out[11] = (lux_val >> 16) & 0xff;
// Battery voltage.
out[13] = 0x0c;
out[12] = 0x0c;
// Value. Factor of 0.001.
uint16_t batt_val = sensors->batt.adc_read.millivolts;
out[14] = batt_val & 0xff;
out[15] = batt_val >> 8;
out[13] = batt_val & 0xff;
out[14] = batt_val >> 8;
// Soil moisture.
out[16] = 0x14;
// Factor of 0.01, so we need to multiply our the value in 100% by 1/0.01 = 100.
uint16_t soil_val = 10000 * sensors->soil.percentage;
out[17] = soil_val & 0xff;
out[18] = soil_val >> 8;
out[15] = 0x2F;
// Factor of 1 over 100%
uint8_t soil_val = 100 * sensors->soil.percentage + 0.5f;
out[16] = soil_val;
// Battery percentage.
out[17] = 0x01;
// Value. Factor 1 over 100%
uint8_t batt_percentage_val = 100 * sensors->batt.percentage + 0.5f;
out[18] = batt_percentage_val;
#endif // Encoding protocols