ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
gps_time.cpp
Go to the documentation of this file.
1#include "gps_time.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace gps {
6
7static const char *const TAG = "gps.time";
8
9void GPSTime::from_tiny_gps_(TinyGPSPlus &tiny_gps) {
10 if (!tiny_gps.time.isValid() || !tiny_gps.date.isValid() || !tiny_gps.time.isUpdated() ||
11 !tiny_gps.date.isUpdated() || tiny_gps.date.year() < 2025) {
12 return;
13 }
14
15 ESPTime val{};
16 val.year = tiny_gps.date.year();
17 val.month = tiny_gps.date.month();
18 val.day_of_month = tiny_gps.date.day();
19 // Set these to valid value for recalc_timestamp_utc - it's not used for calculation
20 val.day_of_week = 1;
21 val.day_of_year = 1;
22
23 val.hour = tiny_gps.time.hour();
24 val.minute = tiny_gps.time.minute();
25 val.second = tiny_gps.time.second();
26 val.recalc_timestamp_utc(false);
27 this->synchronize_epoch_(val.timestamp);
28 this->has_time_ = true;
29}
30
31} // namespace gps
32} // namespace esphome
void from_tiny_gps_(TinyGPSPlus &tiny_gps)
Definition gps_time.cpp:9
void synchronize_epoch_(uint32_t epoch)
Report a unix epoch as current time.
mopeka_std_values val[4]
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
A more user-friendly version of struct tm from time.h.
Definition time.h:15
uint16_t year
year
Definition time.h:33