I recommend using this library instead of my own: https://github.com/DavidAntliff/esp32-ds18b20, it does everything this library does, plus more!
https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
https://www.maximintegrated.com/en/app-notes/index.mvp/id/187
https://github.com/PaulStoffregen/OneWire https://github.com/milesburton/Arduino-Temperature-Control-Library
From the root directory of your ESP-IDF project
git clone [email protected]:brettanomyces/ds18b20.git
echo "COMPONENT_ADD_INCLUDEDIRS := ../components/ds18b20" > main/components.mk
// main/main.c
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "ds18b20.h"
uint8_t pin = 27;
uint8_t addr1[] = {0x28, 0xff, 0xa5, 0xa0, 0x68, 0x14, 0x04, 0x36 };
uint8_t addr2[] = {0x28, 0xff, 0xb7, 0xa0, 0x68, 0x14, 0x04, 0xc9 };
void mainTask(void * pvParameters){
ow_init(pin);
uint8_t count, result, i;
while (1) {
// display addr of all connected devices
count = 0;
result = ow_first();
while (result)
{
printf("addr%d: ", ++count);
// print addr bytes in hex
for (i = 0; i < 8; i++) {
printf("0x%02x ", ROM_NO[i]);
}
printf("\n");
result = ow_next();
}
// get temp by addr
printf("temp1: %0.3f\n", ds_get_temp(addr1));
printf("temp2: %0.3f\n", ds_get_temp(addr2));
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
xTaskCreatePinnedToCore(&mainTask, "mainTask", 2048, NULL, 5, NULL, 0);
}