Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTP: use sntp app from lwip on latest Cores, replace ntpclientlib #2132

Merged
merged 37 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
705ff03
ntp: try using sntp app from lwip, drop ntpclientlib
mcspr Jan 30, 2020
61c95b3
fix display
mcspr Jan 31, 2020
96ca127
thermostat: fix day and month getters
mcspr Jan 31, 2020
75a7b50
test build sizes with scheduler
mcspr Jan 31, 2020
448b6c8
use system timers for once-a-minute scheduling, no polling
mcspr Jan 31, 2020
9730ff7
tick
mcspr Jan 31, 2020
bef1ede
avoid timestamps, use tm
mcspr Jan 31, 2020
bba1e89
drop utc rpn operator, add utc_hour and utc_dow
mcspr Jan 31, 2020
71a878f
try to build with old implementation too
mcspr Jan 31, 2020
bec4610
dep
mcspr Jan 31, 2020
184c9c2
notify ws
mcspr Jan 31, 2020
746bfa1
progmem
mcspr Jan 31, 2020
038bb8d
cleanup types
mcspr Jan 31, 2020
5230740
offset tm values by 1 to match existing schedules
mcspr Jan 31, 2020
12f377e
avoid using ntpclientlib with rpn
mcspr Jan 31, 2020
ae3868a
test. show debug strings in sch
mcspr Jan 31, 2020
e231140
fix secureclient
mcspr Jan 31, 2020
15bb607
consts, fix unsyncing when changing tz (and not triggering sntp after…
mcspr Feb 1, 2020
f33178d
startup time in seconds
mcspr Feb 1, 2020
9927ff9
same delay as lwip
mcspr Feb 2, 2020
7e71beb
header
mcspr Feb 2, 2020
3d72e09
assume build timestamp is unixtime
mcspr Feb 2, 2020
e7db20f
cache server value
mcspr Feb 2, 2020
3f04c8e
fmt
mcspr Feb 2, 2020
bd1b658
typo
mcspr Feb 2, 2020
ae5e639
handle dhcp request
mcspr Feb 2, 2020
8c63206
rename
mcspr Feb 2, 2020
416ce01
web
mcspr Feb 3, 2020
7811b83
TZ.h
mcspr Feb 3, 2020
0790d51
add notice about what alias means
mcspr Feb 3, 2020
d3aa295
fix disabling NTP_SUPPORT
mcspr Feb 3, 2020
1d3876d
scheduled ticker
mcspr Feb 3, 2020
4732fda
Merge branch 'dev' into ntp/sntp-lwip
mcspr Feb 3, 2020
bc8d384
same behaviour as old module
mcspr Feb 4, 2020
68be7c0
rollback rpn dependency check, utc_ prefixes
mcspr Feb 4, 2020
c4c45c8
...
mcspr Feb 4, 2020
6f6bfe4
comments, refactor naming
mcspr Feb 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/espurna/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ using StatusBroker = TBroker<TBrokerType::STATUS, const String&, unsigned char,
using SensorReadBroker = TBroker<TBrokerType::SENSOR_READ, const String&, unsigned char, double, const char*>;
using SensorReportBroker = TBroker<TBrokerType::SENSOR_REPORT, const String&, unsigned char, double, const char*>;

using TimeBroker = TBroker<TBrokerType::DATETIME, const String&, time_t, const String&>;
using ConfigBroker = TBroker<TBrokerType::CONFIG, const String&, const String&>;

#endif // BROKER_SUPPORT
12 changes: 11 additions & 1 deletion code/espurna/config/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@

#if SCHEDULER_SUPPORT
#undef NTP_SUPPORT
#define NTP_SUPPORT 1 // Scheduler needs NTP
#define NTP_SUPPORT 1 // Scheduler needs NTP to work
#undef BROKER_SUPPORT
#define BROKER_SUPPORT 1 // Scheduler needs Broker to trigger every minute
#endif

#if LWIP_VERSION_MAJOR != 1
Expand Down Expand Up @@ -146,3 +148,11 @@
#define SSDP_SUPPORT 0
#endif

//------------------------------------------------------------------------------
// Change ntp module depending on Core version

#if NTP_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
#define NTP_LEGACY_SUPPORT 1
#else
#define NTP_LEGACY_SUPPORT 0
#endif
39 changes: 26 additions & 13 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -1476,13 +1476,38 @@
// -----------------------------------------------------------------------------

#ifndef NTP_SUPPORT
#define NTP_SUPPORT 1 // Build with NTP support by default (6.78Kb)
#define NTP_SUPPORT 1 // Build with NTP support by default (depends on Core version)
#endif

#ifndef NTP_SERVER
#define NTP_SERVER "pool.ntp.org" // Default NTP server
#endif

#ifndef NTP_TIMEZONE
#define NTP_TIMEZONE TZ_Etc_UTC // POSIX TZ variable. Default to UTC from TZ.h (which is PSTR("UTC0"))
// For the format documentation, see:
// - https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
// ESP8266 Core provides human-readable aliases for POSIX format, see:
// - Latest: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
// - PlatformIO: ~/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/TZ.h
// (or, possibly, c:\.platformio\... on Windows)
// - Arduino IDE: depends on platform, see `/dist/arduino_ide/README.md`
#endif

#ifndef NTP_UPDATE_INTERVAL
#define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes
#endif

#ifndef NTP_START_DELAY
#define NTP_START_DELAY 3 // Delay NTP start for 3 seconds
#endif

#ifndef NTP_WAIT_FOR_SYNC
#define NTP_WAIT_FOR_SYNC 1 // Do not report any datetime until NTP sync'ed
#endif

// WARNING: legacy NTP settings. can be ignored with Core 2.6.2+

#ifndef NTP_TIMEOUT
#define NTP_TIMEOUT 1000 // Set NTP request timeout to 2 seconds (issue #452)
#endif
Expand All @@ -1499,22 +1524,10 @@
#define NTP_SYNC_INTERVAL 60 // NTP initial check every minute
#endif

#ifndef NTP_UPDATE_INTERVAL
#define NTP_UPDATE_INTERVAL 1800 // NTP check every 30 minutes
#endif

#ifndef NTP_START_DELAY
#define NTP_START_DELAY 1000 // Delay NTP start 1 second
#endif

#ifndef NTP_DST_REGION
#define NTP_DST_REGION 0 // 0 for Europe, 1 for USA (defined in NtpClientLib)
#endif

#ifndef NTP_WAIT_FOR_SYNC
#define NTP_WAIT_FOR_SYNC 1 // Do not report any datetime until NTP sync'ed
#endif

// -----------------------------------------------------------------------------
// ALEXA
// -----------------------------------------------------------------------------
Expand Down
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.thermostat.html.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions code/espurna/espurna.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "button.h"
#include "debug.h"
#include "led.h"
#include "ntp.h"
#include "relay.h"
#include "rpnrules.h"
#include "settings.h"
#include "system.h"
#include "tuya.h"
Expand Down
4 changes: 4 additions & 0 deletions code/espurna/libs/NtpClientWrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#if NTP_LEGACY_SUPPORT

#include <WiFiUdp.h>
#include <NtpClientLib.h>

Expand All @@ -27,3 +29,5 @@ class NTPClientWrap : public NTPClient {
// NOTE: original NTP should be discarded by the linker
// TODO: allow NTP client object to be destroyed
NTPClientWrap NTPw;

#endif
6 changes: 5 additions & 1 deletion code/espurna/libs/SecureClientHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ struct SecureClientChecks {
client.setFingerprint(_buffer);
}
} else if (check == SECURE_CLIENT_CHECK_CA) {
client.setX509Time(ntpLocal2UTC(now()));
#if NTP_LEGACY_SUPPORT
client.setX509Time(ntpLocal2UTC(now()));
#else
client.setX509Time(now());
#endif
if (!certs.getCount()) {
if (config.on_certificate) certs.append(config.on_certificate());
}
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot
#include <vector>
#include <utility>
#include <Ticker.h>
#include <TimeLib.h>

#include "system.h"
#include "libs/SecureClientHelpers.h"
#include "ntp.h"
#include "ws.h"

#if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT
Expand Down
52 changes: 52 additions & 0 deletions code/espurna/ntp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*

NTP MODULE

*/

#pragma once

#include "broker.h"

// TODO: need this prototype for .ino
struct NtpCalendarWeekday;

#if NTP_SUPPORT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW some benefit of having #if guards in headers is that compilation will fail instead of linker when function is not implemented / supported


#if NTP_LEGACY_SUPPORT // Use legacy TimeLib and NtpClientLib

#include <TimeLib.h>
#include "libs/NtpClientWrap.h"

#else // POSIX time functions + configTime(...)

#include <lwip/apps/sntp.h>
#include <TZ.h>
#include "ntp_timelib.h"

#endif

// --- rest of the module is ESPurna functions

enum class NtpTick {
EveryMinute,
EveryHour
};

struct NtpCalendarWeekday {
int local_wday;
int local_hour;
int local_minute;
int utc_wday;
int utc_hour;
int utc_minute;
};

using NtpBroker = TBroker<TBrokerType::DATETIME, const NtpTick, time_t, const String&>;

String ntpDateTime(time_t ts);
String ntpDateTime();

void ntpSetup();

#endif // NTP_SUPPORT
Loading