17
17
/* Health Thermometer Service Definitions
18
18
* Health Thermometer Service: 0x1809
19
19
* Temperature Measurement Char: 0x2A1C
20
- * Temperature Type Char: 0x2A1D
21
20
*/
22
21
BLEService htms = BLEService(UUID16_SVC_HEALTH_THERMOMETER);
23
22
BLECharacteristic htmc = BLECharacteristic(UUID16_CHR_TEMPERATURE_MEASUREMENT);
24
- BLECharacteristic ttype = BLECharacteristic(UUID16_CHR_TEMPERATURE_TYPE);
25
23
26
24
BLEDis bledis; // DIS (Device Information Service) helper class instance
27
25
@@ -102,8 +100,8 @@ void setupHTM(void)
102
100
// Name UUID Requirement Properties
103
101
// ---------------------------- ------ ----------- ----------
104
102
// Temperature Measurement 0x2A1C Mandatory Indicate
105
- // Temperature Type 0x2A1D Optional Read
106
- //
103
+ //
104
+ // Temperature Type 0x2A1D Optional Read <-- Not used here
107
105
// Intermediate Temperature 0x2A1E Optional Read, Notify <-- Not used here
108
106
// Measurement Interval 0x2A21 Optional Read, Write, Indicate <-- Not used here
109
107
htms.begin ();
@@ -116,27 +114,25 @@ void setupHTM(void)
116
114
// Configure the Temperature Measurement characteristic
117
115
// See:https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.temperature_measurement.xml
118
116
// Properties = Indicte
119
- // Min Len = 5
120
- // Max Len = 5
117
+ // Min Len = 6
118
+ // Max Len = 6
121
119
// B0 = UINT8 - Flag (MANDATORY)
122
120
// b3:7 = Reserved
123
121
// b2 = Temperature Type Flag (0 = Not present, 1 = Present)
124
122
// b1 = Timestamp Flag (0 = Not present, 1 = Present)
125
123
// b0 = Unit Flag (0 = Celsius, 1 = Fahrenheit)
126
124
// B4:1 = FLOAT - IEEE-11073 32-bit FLOAT measurement value
125
+ // B5 = Temperature Type
127
126
htmc.setProperties (CHR_PROPS_INDICATE);
128
127
htmc.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
129
- htmc.setFixedLen (5 );
128
+ htmc.setFixedLen (6 );
130
129
htmc.setCccdWriteCallback (cccd_callback); // Optionally capture CCCD updates
131
130
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
134
133
135
- // Configure the Temperature Type characteristic
134
+ // Temperature Type Value
136
135
// 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
140
136
// B0 = UINT8 - Temperature Type
141
137
// 0 = Reserved
142
138
// 1 = Armpit
@@ -149,11 +145,6 @@ void setupHTM(void)
149
145
// 8 = Toe
150
146
// 9 = Tympanum (ear drum)
151
147
// 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)
157
148
}
158
149
159
150
void connect_callback (uint16_t conn_handle)
@@ -198,7 +189,7 @@ void loop()
198
189
digitalToggle (LED_RED);
199
190
200
191
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)
202
193
203
194
float2IEEE11073 (tempvalue, &htmdata[1 ]);
204
195
0 commit comments