None of the existing DS18B20/OneWire libraries will work on the P2/Photon 2 (RTL872x). The GPIO on that MCU is very, very, slow and cannot read and write the data line fast enough for the OneWire protocol.
One option is to use a DS248
2-100 I2C to OneWire bridge. It’s inexpensive and there’s a library that works well on Particle. The caveat is that it’s been impossible to get during the silicon shortage, but finally Mouser will be getting a bunch in June 2023. Using a bridge chip removes all of the interrupt and timing-sensitive code and the library makes it non-blocking.
Another benefit is that you can use a PCA9306 or other I2C level-shifter to run the DS2472 at 5V on a 5V I2C bus. The OneWire protocol works much better at 5V over long distances.
In the future there could be a library that uses the SPI or UART peripheral on the P2/Photon 2 for OneWire, sort of like how the new NeoPixel support works, to get around the GPIO speed limitation.
The alternative I use now is to just not use DS18B20s. If you’re looking for a sensor with a cable the SHT30 is good. There are also cheaper clones, but the Adafruit one works well. Just make sure you get a SHT3x that has true I2C. The SHT1x chips use a proprietary protocol that will have the same problem as OneWire. On a circuit board (SMD) I use the SHTC3 because it’s easier to solder than the SHT30. Plus the SHT3x also has a humidity sensor and is cheaper than a DS18B20 and does not require a bridge.
To get around I2C address limitations, I’ve also added a TCA9548APWR which works well to split a single I2C bus into 8 busses when needed.