ESPHome 2026.4.0-dev
Loading...
Searching...
No Matches
internal_temperature_rp2040.cpp
Go to the documentation of this file.
1#ifdef USE_RP2040
2
3#include "esphome/core/log.h"
5
6#include "Arduino.h"
7
9
10static const char *const TAG = "internal_temperature.rp2040";
11
13 float temperature = NAN;
14 bool success = false;
15
16 temperature = analogReadTemp();
17 success = (temperature != 0.0f);
18
19 if (success && std::isfinite(temperature)) {
20 this->publish_state(temperature);
21 } else {
22 ESP_LOGD(TAG, "Ignoring invalid temperature (success=%d, value=%.1f)", success, temperature);
23 if (!this->has_state()) {
24 this->publish_state(NAN);
25 }
26 }
27}
28
29} // namespace esphome::internal_temperature
30
31#endif // USE_RP2040
bool has_state() const
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
uint16_t temperature
Definition sun_gtil2.cpp:12