ESPHome 2025.11.4
Loading...
Searching...
No Matches
sntp_component.h
Go to the documentation of this file.
1#pragma once
2
5#include <array>
6
7namespace esphome {
8namespace sntp {
9
10// Server count is calculated at compile time by Python codegen
11// SNTP_SERVER_COUNT will always be defined
12
20 public:
21 SNTPComponent(const std::array<const char *, SNTP_SERVER_COUNT> &servers) : servers_(servers) {}
22
23 void setup() override;
24 void dump_config() override;
25 float get_setup_priority() const override { return setup_priority::BEFORE_CONNECTION; }
26
27 void update() override;
28 void loop() override;
29
30 void time_synced();
31
32 protected:
33 // Store const char pointers to string literals
34 // ESP8266: strings in rodata (RAM), but avoids std::string overhead (~24 bytes each)
35 // Other platforms: strings in flash
36 std::array<const char *, SNTP_SERVER_COUNT> servers_;
37 bool has_time_{false};
38
39#if defined(USE_ESP32)
40 private:
41 static SNTPComponent *instance;
42#endif
43};
44
45} // namespace sntp
46} // namespace esphome
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.
const float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
Definition component.cpp:65
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7