ESPHome 2025.5.0
Loading...
Searching...
No Matches
gps_time.cpp
Go to the documentation of this file.
1#ifdef USE_ARDUINO
2
3#include "gps_time.h"
4#include "esphome/core/log.h"
5
6namespace esphome {
7namespace gps {
8
9static const char *const TAG = "gps.time";
10
11void GPSTime::from_tiny_gps_(TinyGPSPlus &tiny_gps) {
12 if (!tiny_gps.time.isValid() || !tiny_gps.date.isValid())
13 return;
14 if (!tiny_gps.time.isUpdated() || !tiny_gps.date.isUpdated())
15 return;
16 if (tiny_gps.date.year() < 2019)
17 return;
18
19 ESPTime val{};
20 val.year = tiny_gps.date.year();
21 val.month = tiny_gps.date.month();
22 val.day_of_month = tiny_gps.date.day();
23 // Set these to valid value for recalc_timestamp_utc - it's not used for calculation
24 val.day_of_week = 1;
25 val.day_of_year = 1;
26
27 val.hour = tiny_gps.time.hour();
28 val.minute = tiny_gps.time.minute();
29 val.second = tiny_gps.time.second();
30 val.recalc_timestamp_utc(false);
31 this->synchronize_epoch_(val.timestamp);
32 this->has_time_ = true;
33}
34
35} // namespace gps
36} // namespace esphome
37
38#endif // USE_ARDUINO
void from_tiny_gps_(TinyGPSPlus &tiny_gps)
Definition gps_time.cpp:11
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