@@ -45,8 +45,11 @@ void app_main(void)
4545 search_result = onewire_device_iter_get_next (iter , & next_onewire_device );
4646 if (search_result == ESP_OK ) { // found a new device, let's check if we can upgrade it to a DS18B20
4747 ds18b20_config_t ds_cfg = {};
48- if (ds18b20_new_device (& next_onewire_device , & ds_cfg , & ds18b20s [ds18b20_device_num ]) == ESP_OK ) {
49- ESP_LOGI (TAG , "Found a DS18B20[%d], address: %016llX" , ds18b20_device_num , next_onewire_device .address );
48+ onewire_device_address_t address ;
49+ // wrap the generic 1-wire device into a DS18B20 sensor device
50+ if (ds18b20_new_device_from_enumeration (& next_onewire_device , & ds_cfg , & ds18b20s [ds18b20_device_num ]) == ESP_OK ) {
51+ ds18b20_get_device_address (ds18b20s [ds18b20_device_num ], & address );
52+ ESP_LOGI (TAG , "Found a DS18B20[%d], address: %016llX" , ds18b20_device_num , address );
5053 ds18b20_device_num ++ ;
5154 if (ds18b20_device_num >= EXAMPLE_ONEWIRE_MAX_DS18B20 ) {
5255 ESP_LOGI (TAG , "Max DS18B20 number reached, stop searching..." );
@@ -70,9 +73,10 @@ void app_main(void)
7073 float temperature ;
7174 while (1 ) {
7275 vTaskDelay (pdMS_TO_TICKS (200 ));
73-
76+ // trigger temperature conversion for all DS18B20s on the bus
77+ ESP_ERROR_CHECK (ds18b20_trigger_temperature_conversion_for_all (bus ));
78+ // read temperature from each DS18B20
7479 for (int i = 0 ; i < ds18b20_device_num ; i ++ ) {
75- ESP_ERROR_CHECK (ds18b20_trigger_temperature_conversion (ds18b20s [i ]));
7680 ESP_ERROR_CHECK (ds18b20_get_temperature (ds18b20s [i ], & temperature ));
7781 ESP_LOGI (TAG , "temperature read from DS18B20[%d]: %.2fC" , i , temperature );
7882 }
0 commit comments