BLE cannot send the correct temperature measurement char value 0x2A1C
Posted: Mon Oct 28, 2024 2:26 pm
Hi,
Hardware (BLE server): ESP32-C3-DevKitM-1
Mobile App (BLE client): nRF Connect
Example code: Gatt_Server_Service_Table
I would like to BLE standard Environmental Sensing Service (ESS 0x181A), Temperature Measurement Characteristic (0x2A1C)
How to send the temperature float value such as 25.63℃ in the correct format? If I use uint8_t ess_temperature[] = {0x00, 0x03, 0x0A, 0x00,0x00}; It will show 2563.00℃, but I want to show 25.63℃.
But on nRF Connect App in mobile phone, it shows the result is -0.00℃. How to send the temperature float value such as 25.6℃ in the correct format? Thanks
Hardware (BLE server): ESP32-C3-DevKitM-1
Mobile App (BLE client): nRF Connect
Example code: Gatt_Server_Service_Table
I would like to BLE standard Environmental Sensing Service (ESS 0x181A), Temperature Measurement Characteristic (0x2A1C)
How to send the temperature float value such as 25.63℃ in the correct format? If I use uint8_t ess_temperature[] = {0x00, 0x03, 0x0A, 0x00,0x00}; It will show 2563.00℃, but I want to show 25.63℃.
Code: Select all
[Codebox=c file=Untitled.c]
enum{
ESS_SERVICE,
ESS_TEMPERATURE_CHAR,
ESS_TEMPERATURE_VALUE,
ESS_TEMPERATURE_CFG,
ESS_HUMIDITY_SERVICE,
ESS_HUMIDITY_VAL,
ESS_HUMIDITY_CFG,
ESS_IDX_NB,
};
// =============== ESS Service ===============
static const uint16_t GATTS_SERVICE_UUID_ESS = 0x181A;
static const uint16_t GATTS_CHAR_UUID_ESS_TEMPERATURE = 0x2A1C;
static const uint16_t GATTS_CHAR_UUID_ESS_HUMIDITY = 0x2A6F;
//static const uint8_t ess_temperature[2] = {0x19, 0x05}; // = 25.5 degC
// static const uint8_t ess_temperature_ccc[2] = {0x00, 0x00};
//static const uint8_t ess_humidity[2] = {0x0B, 0x05}; // = 11.5%
// static const uint8_t ess_humidity_ccc[2] = {0x00, 0x00};
uint8_t ess_temperature[5] = {0x00,0x41, 0x33, 0xB9, 0xD7};
static const uint16_t ess_humidity = 3556; // nRF Connect App will divide this value by 100. For example, if we use 3654, App will show 36.54% humidity
static const esp_gatts_attr_db_t ess_gatt_db[ESS_IDX_NB] =
{
[ESS_SERVICE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_ESS), (uint8_t *)&GATTS_SERVICE_UUID_ESS}},
// Temperature -------------------------------------------------
[ESS_TEMPERATURE_CHAR] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read}},
[ESS_TEMPERATURE_VALUE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_ESS_TEMPERATURE, ESP_GATT_PERM_READ,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(ess_temperature), (uint8_t *)&ess_temperature}},
[ESS_TEMPERATURE_CFG] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(uint16_t), sizeof(cccd_disable_notify_indicate), (uint8_t *)cccd_disable_notify_indicate}},
// Humidity -------------------------------------------
[ESS_HUMIDITY_SERVICE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read}},
[ESS_HUMIDITY_VAL] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_ESS_HUMIDITY, ESP_GATT_PERM_READ,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(ess_humidity), (uint8_t *)&ess_humidity}},
[ESS_HUMIDITY_CFG] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(uint16_t), sizeof(cccd_disable_notify_indicate), (uint8_t *)cccd_disable_notify_indicate}},
};
[/Codebox]
But on nRF Connect App in mobile phone, it shows the result is -0.00℃. How to send the temperature float value such as 25.6℃ in the correct format? Thanks