set ntp parameters via config file
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
namespace drivers
|
||||
{
|
||||
|
||||
Ethernet::Ethernet(const std::string hostname) : m_hostname(hostname), m_connected(false), m_localIP(IPAddress()), m_udp(NetworkUDP()), m_timeClient(m_udp)
|
||||
Ethernet::Ethernet(const std::string &hostname, const std::string &ntpPool, const int8_t tz, const uint16_t updateInterval) : m_hostname(hostname), m_ntpPool(ntpPool), m_connected(false), m_localIP(IPAddress()), m_udp(NetworkUDP()), m_timeClient(m_udp)
|
||||
{
|
||||
SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
|
||||
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
|
||||
|
||||
m_timeClient = std::move(NTPClient(m_udp, "pool.ntp.org", 0, 3600)); // NTP server, time offset in seconds, update interval
|
||||
m_timeClient = std::move(NTPClient(m_udp, m_ntpPool.c_str(), tz * 3600, updateInterval)); // NTP server, time offset in seconds, update interval
|
||||
m_timeClient.begin();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,17 @@ namespace drivers
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool Ethernet::setNtpTimeOffset(const int8_t tz)
|
||||
{
|
||||
if (m_connected)
|
||||
{
|
||||
m_timeClient.setTimeOffset(tz * 3600);
|
||||
LOG_DEBUG("Time zone UTC ", tz);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool Ethernet::isConnected()
|
||||
{
|
||||
return m_connected;
|
||||
|
||||
Reference in New Issue
Block a user