@@ -98,39 +98,44 @@ int prst_ble_encode_service_data(const prst_sensors_t* sensors,
98
98
// Service header - no encryption, bt home v2.
99
99
out [2 ] = 0x40 ;
100
100
101
+ // Battery percentage.
102
+ out [3 ] = 0x01 ;
103
+ // Value. Factor 1 over 100%
104
+ uint8_t batt_percentage_val = 100 * sensors -> batt .percentage + 0.5f ;
105
+ out [4 ] = batt_percentage_val ;
106
+
101
107
// Temperature.
102
- out [3 ] = 0x02 ;
108
+ out [5 ] = 0x02 ;
103
109
int16_t temp_val = 100 * sensors -> shtc3 .temp_c ;
104
- out [4 ] = temp_val & 0xff ;
105
- out [5 ] = temp_val >> 8 ;
106
- // Humidity.
107
- out [6 ] = 0x2E ;
108
- // Value. Factor 1 over 100%.
109
- uint8_t humi_val = 100 * sensors -> shtc3 .rel_humi + 0.5f ;
110
- out [7 ] = humi_val ;
110
+ out [6 ] = temp_val & 0xff ;
111
+ out [7 ] = temp_val >> 8 ;
112
+
111
113
// Illuminance.
112
114
out [8 ] = 0x05 ;
113
115
// Value. Factor of 0.01.
114
116
uint32_t lux_val = sensors -> photo .brightness * 100 ;
115
117
out [9 ] = lux_val & 0xff ;
116
118
out [10 ] = (lux_val >> 8 ) & 0xff ;
117
119
out [11 ] = (lux_val >> 16 ) & 0xff ;
120
+
118
121
// Battery voltage.
119
122
out [12 ] = 0x0c ;
120
123
// Value. Factor of 0.001.
121
124
uint16_t batt_val = sensors -> batt .adc_read .millivolts ;
122
125
out [13 ] = batt_val & 0xff ;
123
126
out [14 ] = batt_val >> 8 ;
127
+
128
+ // Humidity.
129
+ out [15 ] = 0x2E ;
130
+ // Value. Factor 1 over 100%.
131
+ uint8_t humi_val = 100 * sensors -> shtc3 .rel_humi + 0.5f ;
132
+ out [16 ] = humi_val ;
133
+
124
134
// Soil moisture.
125
- out [15 ] = 0x2F ;
135
+ out [17 ] = 0x2F ;
126
136
// Factor of 1 over 100%
127
137
uint8_t soil_val = 100 * sensors -> soil .percentage + 0.5f ;
128
- out [16 ] = soil_val ;
129
- // Battery percentage.
130
- out [17 ] = 0x01 ;
131
- // Value. Factor 1 over 100%
132
- uint8_t batt_percentage_val = 100 * sensors -> batt .percentage + 0.5f ;
133
- out [18 ] = batt_percentage_val ;
138
+ out [18 ] = soil_val ;
134
139
135
140
#endif // Encoding protocols
136
141
0 commit comments