ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
sntp_component.h
Go to the documentation of this file.
1#pragma once
2
5#include <array>
6
7namespace esphome::sntp {
8
9// Server count is calculated at compile time by Python codegen
10// SNTP_SERVER_COUNT will always be defined
11
19 public:
20 SNTPComponent(const std::array<const char *, SNTP_SERVER_COUNT> &servers) : servers_(servers) {}
21
22 void setup() override;
23 void dump_config() override;
24 float get_setup_priority() const override { return setup_priority::BEFORE_CONNECTION; }
25
26 void update() override;
27 void loop() override;
28
29 void time_synced();
30
31 protected:
32 // Store const char pointers to string literals
33 // ESP8266: strings in rodata (RAM), but avoids std::string overhead (~24 bytes each)
34 // Other platforms: strings in flash
35 std::array<const char *, SNTP_SERVER_COUNT> servers_;
36 bool has_time_{false};
37
38#if defined(USE_ESP32)
39 private:
40 static SNTPComponent *instance;
41#endif
42};
43
44} // namespace esphome::sntp
The SNTP component allows you to configure local timekeeping via Simple Network Time Protocol.
std::array< const char *, SNTP_SERVER_COUNT > servers_
SNTPComponent(const std::array< const char *, SNTP_SERVER_COUNT > &servers)
float get_setup_priority() const override
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
constexpr float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
Definition component.h:51