1717/* Health Thermometer Service Definitions
1818 * Health Thermometer Service: 0x1809
1919 * Temperature Measurement Char: 0x2A1C
20- * Temperature Type Char: 0x2A1D
2120 */
2221BLEService htms = BLEService(UUID16_SVC_HEALTH_THERMOMETER);
2322BLECharacteristic htmc = BLECharacteristic(UUID16_CHR_TEMPERATURE_MEASUREMENT);
24- BLECharacteristic ttype = BLECharacteristic(UUID16_CHR_TEMPERATURE_TYPE);
2523
2624BLEDis bledis; // DIS (Device Information Service) helper class instance
2725
@@ -102,8 +100,8 @@ void setupHTM(void)
102100 // Name UUID Requirement Properties
103101 // ---------------------------- ------ ----------- ----------
104102 // Temperature Measurement 0x2A1C Mandatory Indicate
105- // Temperature Type 0x2A1D Optional Read
106- //
103+ //
104+ // Temperature Type 0x2A1D Optional Read <-- Not used here
107105 // Intermediate Temperature 0x2A1E Optional Read, Notify <-- Not used here
108106 // Measurement Interval 0x2A21 Optional Read, Write, Indicate <-- Not used here
109107 htms.begin ();
@@ -116,27 +114,25 @@ void setupHTM(void)
116114 // Configure the Temperature Measurement characteristic
117115 // See:https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.temperature_measurement.xml
118116 // Properties = Indicte
119- // Min Len = 5
120- // Max Len = 5
117+ // Min Len = 6
118+ // Max Len = 6
121119 // B0 = UINT8 - Flag (MANDATORY)
122120 // b3:7 = Reserved
123121 // b2 = Temperature Type Flag (0 = Not present, 1 = Present)
124122 // b1 = Timestamp Flag (0 = Not present, 1 = Present)
125123 // b0 = Unit Flag (0 = Celsius, 1 = Fahrenheit)
126124 // B4:1 = FLOAT - IEEE-11073 32-bit FLOAT measurement value
125+ // B5 = Temperature Type
127126 htmc.setProperties (CHR_PROPS_INDICATE);
128127 htmc.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
129- htmc.setFixedLen (5 );
128+ htmc.setFixedLen (6 );
130129 htmc.setCccdWriteCallback (cccd_callback); // Optionally capture CCCD updates
131130 htmc.begin ();
132- uint8_t htmdata[5 ] = { 0b00000001 , 0 }; // Set the characteristic to use Fahrenheit, without type, timestamp field
133- htmc.write (htmdata, 5 ); // Use .write for init data
131+ uint8_t htmdata[6 ] = { 0b00000101 , 0 , 0 , 0 , 0 , 2 }; // Set the characteristic to use Fahrenheit, with type (body) but no timestamp field
132+ htmc.write (htmdata, sizeof (htmdata) ); // Use .write for init data
134133
135- // Configure the Temperature Type characteristic
134+ // Temperature Type Value
136135 // See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.temperature_type.xml
137- // Properties = Read
138- // Min Len = 1
139- // Max Len = 1
140136 // B0 = UINT8 - Temperature Type
141137 // 0 = Reserved
142138 // 1 = Armpit
@@ -149,11 +145,6 @@ void setupHTM(void)
149145 // 8 = Toe
150146 // 9 = Tympanum (ear drum)
151147 // 10:255 = Reserved
152- ttype.setProperties (CHR_PROPS_READ);
153- ttype.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
154- ttype.setFixedLen (1 );
155- ttype.begin ();
156- ttype.write8 (2 ); // Set the characteristic to 'Body' (2)
157148}
158149
159150void connect_callback (uint16_t conn_handle)
@@ -198,7 +189,7 @@ void loop()
198189 digitalToggle (LED_RED);
199190
200191 if ( Bluefruit.connected () ) {
201- uint8_t htmdata[5 ] = { 0b00000001 }; // Fahrenheit unit
192+ uint8_t htmdata[6 ] = { 0b00000101 , 0 , 0 , 0 , 0 , 2 }; // Fahrenheit unit, temperature type = body (2)
202193
203194 float2IEEE11073 (tempvalue, &htmdata[1 ]);
204195
0 commit comments