@@ -98,39 +98,44 @@ int prst_ble_encode_service_data(const prst_sensors_t* sensors,
9898 // Service header - no encryption, bt home v2.
9999 out [2 ] = 0x40 ;
100100
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+
101107 // Temperature.
102- out [3 ] = 0x02 ;
108+ out [5 ] = 0x02 ;
103109 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+
111113 // Illuminance.
112114 out [8 ] = 0x05 ;
113115 // Value. Factor of 0.01.
114116 uint32_t lux_val = sensors -> photo .brightness * 100 ;
115117 out [9 ] = lux_val & 0xff ;
116118 out [10 ] = (lux_val >> 8 ) & 0xff ;
117119 out [11 ] = (lux_val >> 16 ) & 0xff ;
120+
118121 // Battery voltage.
119122 out [12 ] = 0x0c ;
120123 // Value. Factor of 0.001.
121124 uint16_t batt_val = sensors -> batt .adc_read .millivolts ;
122125 out [13 ] = batt_val & 0xff ;
123126 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+
124134 // Soil moisture.
125- out [15 ] = 0x2F ;
135+ out [17 ] = 0x2F ;
126136 // Factor of 1 over 100%
127137 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 ;
134139
135140#endif // Encoding protocols
136141
0 commit comments