Skip to content

Commit 10fd3e2

Browse files
authored
Fix NTP with lwIP 1.4 (#44)
* Fix month (was 0 index) * Add timezone support * Update copyright date * Allow disabling editor: * Remove some debug * Remove editor * Print millis() before time hack is received * Get rid of unneeded code * Return to upstream * Remove unused variable * Remove redeclarations * Add Day of Week * Set proper timezone * Add warking about lwIP * Add ntp configuration for lwIP 1.x * Promote 2.2.3beta for #43
1 parent e94d7bd commit 10fd3e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+152
-148
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Brew Bubbles is Copyright (c) 2019-2020 Lee C. Bussy
3+
Brew Bubbles is Copyright (c) 2019-2021 Lee C. Bussy
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

data/about.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ <h4 class="card-title">
128128

129129
<footer class="footer mt-auto py-3">
130130
<div class="container text-center">
131-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
131+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
132132
</div>
133133
</footer>
134134

data/help.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ <h4 class="card-title">Brew Bubbles Support</h4>
119119

120120
<footer class="footer mt-auto py-3">
121121
<div class="container text-center">
122-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
122+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
123123
</div>
124124
</footer>
125125

data/index.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ <h4 class="card-title">Current Readings</h4>
126126

127127
<footer class="footer mt-auto py-3">
128128
<div class="container text-center">
129-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
129+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
130130
</div>
131131
</footer>
132132

data/license.htm

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<h4 class="card-title">Brew Bubbles License</h4>
9191
</div>
9292
<div class="card-body">
93-
<p>Copyright 2019-2020 Lee C. Bussy</p>
93+
<p>Copyright 2019-2021 Lee C. Bussy</p>
9494

9595
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
9696
of this software and associated documentation files (the "Software"), to deal
@@ -119,7 +119,7 @@ <h4 class="card-title">Brew Bubbles License</h4>
119119

120120
<footer class="footer mt-auto py-3">
121121
<div class="container text-center">
122-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
122+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
123123
</div>
124124
</footer>
125125

data/ota.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ <h4 class="card-title">Firmware Update In Progress, please Wait ...</h4>
124124

125125
<footer class="footer mt-auto py-3">
126126
<div class="container text-center">
127-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
127+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
128128
</div>
129129
</footer>
130130

data/reset.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h4 class="card-title">Controller Reset</h4>
103103

104104
<footer class="footer mt-auto py-3">
105105
<div class="container text-center">
106-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
106+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
107107
</div>
108108
</footer>
109109

data/settings.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ <h4 class="card-title">Reset Wifi Settings</h4>
599599

600600
<footer class="footer mt-auto py-3">
601601
<div class="container text-center">
602-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
602+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
603603
</div>
604604
</footer>
605605

data/wifi.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ <h4 class="card-title">Reset WiFi: Confirmation</h4>
108108

109109
<footer class="footer mt-auto py-3">
110110
<div class="container text-center">
111-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
111+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
112112
</div>
113113
</footer>
114114

data/wifi2.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ <h4 class="card-title">Resetting WiFi Configuration</h4>
109109

110110
<footer class="footer mt-auto py-3">
111111
<div class="container text-center">
112-
<span class="text-muted">Copyright © 2019-2020, Lee C. Bussy</span>
112+
<span class="text-muted">Copyright © 2019-2021, Lee C. Bussy</span>
113113
</div>
114114
</footer>
115115

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# -- Project information -----------------------------------------------------
2424

2525
project = u'Brew Bubbles'
26-
copyright = u'2019-2020, Lee C. Bussy'
26+
copyright = u'2019-2021, Lee C. Bussy'
2727
author = u'Lee C. Bussy'
2828

2929
# Get 0.0.0 version from latest Git tag

platformio.ini

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
; https://docs.platformio.org/page/projectconf.html
1010

1111
[common_env_data]
12-
upload_speed = 460800 ; 921600
12+
upload_speed = 460800 ; 921600 // MacBook can't handle the heat!
1313
monitor_speed = 74880
1414
framework = arduino
1515
platform = espressif8266
1616
build_unflags =
1717
build_flags =
1818
!python tools/git_rev.py
19-
-D PIO_SRC_TAG=2.2.2
19+
-D PIO_SRC_TAG=2.2.3Beta
2020
-D BAUD=${common_env_data.monitor_speed}
21-
-DDEBUG_ESP_PORT=Serial
21+
; -DDEBUG_ESP_PORT=Serial
2222
; -D DEBUG_ESP_WIFI
2323
; -D DEBUG_ESP_HTTP_UPDATE
2424
; -D DEBUG_ESP_HTTP_CLIENT
@@ -33,26 +33,26 @@ build_flags =
3333
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH ; v2 Higher Bandwidth (no features)
3434
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY ; v2 IPv6 Lower Memory
3535
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_HIGHER_BANDWIDTH ; v2 IPv6 Higher Bandwidth
36-
-D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH ; v1.4 Higher Bandwidth
36+
-D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH ; v1.4 Higher Bandwidth (Needed because of stream errors getting Filesystem OTA)
3737
extra_scripts = ; pre:python tools\name_firmware.py
3838
lib_deps =
3939
ArduinoJson
4040
https://github.com/lbussy/OneWire.git
4141
https://github.com/lbussy/DS18B20.git
4242
https://github.com/lbussy/Arduino-Log.git
43+
https://github.com/lbussy/ESPAsyncTCP
4344
https://github.com/lbussy/ESPAsyncWebServer.git
4445
https://github.com/lbussy/AsyncWiFiManager.git
45-
https://github.com/lbussy/ESPAsyncTCP
4646
https://github.com/lbussy/asyncHTTPrequest.git
4747
https://github.com/lbussy/CircularBuffer.git
4848
https://github.com/lbussy/LCBUrl.git
4949
https://github.com/lbussy/esptelnet.git
50-
https://github.com/lbussy/ESP_DoubleResetDetector
50+
khoih-prog/ESP_WiFiManager
5151
https://github.com/lbussy/ThingSpeak
5252
monitor_filters =
53-
esp8266_exception_decoder
53+
; esp8266_exception_decoder
5454
; log2file
55-
build_type = release
55+
build_type = release ; Cannot use debug with Wemos D1
5656

5757
[env:d1_mini]
5858
board_build.filesystem = littlefs

src/brewersfriend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/brewersfriend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/brewfather.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/brewfather.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/bubbles.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/bubbles.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/config.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44
@@ -65,7 +65,7 @@ SOFTWARE. */
6565
// Use SPIFFS Editor
6666
//
6767
#ifndef SPIFFSEDIT
68-
#define SPIFFSEDIT
68+
// #define SPIFFSEDIT
6969
#endif
7070
//
7171
//////////////////////////////////////////////////////////////////////////
@@ -427,7 +427,9 @@ SOFTWARE. */
427427
// NTP Server
428428
//
429429
#ifndef TIMESERVER
430-
#define TIMESERVER "pool.ntp.org"
430+
#define TIMESERVER "pool.ntp.org", "time.nist.gov"
431+
#define THISTZ TZ_Etc_GMT
432+
// #define THISTZ TZ_America_Chicago
431433
#endif
432434
//
433435
//////////////////////////////////////////////////////////////////////////

src/execota.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44
@@ -22,6 +22,10 @@ SOFTWARE. */
2222

2323
#include "execota.h"
2424

25+
#if LWIP_VERSION_MAJOR == 2
26+
#warning "Remember: You are using lwIP v2.x and this causes filesystem OTA tp act weird."
27+
#endif
28+
2529
void execfw()
2630
{
2731
Log.notice(F("Starting the Firmware OTA pull, will reboot without notice." CR));

src/execota.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/jsonconfig.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/jsonconfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/main.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/mdns.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/mdns.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44

src/ntp.cpp

+41-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
1+
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
22
33
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
44
@@ -20,34 +20,56 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE. */
2222

23+
// NTP Examples in:
24+
// https://github.com/esp8266/Arduino/blob/master/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino
25+
2326
#include "ntp.h"
2427

28+
#if LWIP_VERSION_MAJOR == 1
29+
#warning "Remember: You are using lwIP v1.x and this causes ntp time to act weird."
30+
#endif
31+
32+
static const int __attribute__((unused)) SECS_1_1_2019 = 1546300800; //1546300800 = 01/01/2019 @ 12:00am (UTC)
33+
static const char __attribute__((unused)) * DAY_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
34+
static const char __attribute__((unused)) * DAY_OF_WEEK_SHORT[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
35+
2536
void setClock()
2637
{
2738
Ticker blinker;
2839
Log.notice(F("Entering blocking loop to get NTP time."));
2940
blinker.attach_ms(NTPBLINK, ntpBlinker);
30-
time_t startSecs = time(nullptr);
41+
unsigned long startSecs = millis() / 1000;
3142
int cycle = 0;
32-
while (time(nullptr) < EPOCH_1_1_2019)
43+
#if LWIP_VERSION_MAJOR == 1
44+
sntp_setservername(0, (char *)"pool.ntp.org");
45+
sntp_setservername(0, (char *)"time.nist.gov");
46+
sntp_set_timezone(0);
47+
while (sntp_get_current_timestamp() == 0)
48+
{
49+
sntp_stop();
50+
sntp_init();
51+
#else
52+
while (time(nullptr) < SECS_1_1_2019)
3353
{
34-
configTime("GMT", "pool.ntp.org", "time.nist.gov");
35-
if (time(nullptr) - startSecs > 9)
54+
configTime(THISTZ, TIMESERVER);
55+
#endif
56+
if ((millis() / 1000) - startSecs > 9)
3657
{
3758
if (cycle > 9)
3859
{
3960
#ifdef LOG_LEVEL
4061
myPrintln();
4162
#endif
42-
Log.warning(F("Unable to get time hack from %s, starting with epoch." CR), TIMESERVER);
63+
Log.warning(F("Unable to get time hack from server, restarting." CR));
4364
blinker.detach();
65+
ESP.restart();
4466
return;
4567
}
4668
#ifdef LOG_LEVEL
4769
myPrintln();
4870
#endif
4971
Log.verbose(F("Re-requesting time hack."));
50-
startSecs = time(nullptr);
72+
startSecs = millis() / 1000;
5173
cycle++;
5274
}
5375
#ifdef LOG_LEVEL
@@ -60,18 +82,13 @@ void setClock()
6082
#ifdef LOG_LEVEL
6183
myPrintln();
6284
#endif
63-
lastNTPUpdate = millis();
6485
Log.notice(F("NTP time set." CR));
65-
struct tm timeinfo;
66-
time_t nowSecs = time(nullptr);
67-
gmtime_r(&nowSecs, &timeinfo);
6886
}
6987

7088
String getDTS()
7189
{
7290
// Returns JSON-type string = 2019-12-20T13:59:39Z
73-
/// Also:
74-
// sprintf(dts, "%04u-%02u-%02uT%02u:%02u:%02uZ", getYear(), getMonth(), getDate(), getHour(), getMinute(), getSecond());
91+
// Also: sprintf(dta, "%04u-%02u-%02uT%02u:%02u:%02uZ", getYear(), getMonth(), getDate(), getHour(), getMinute(), getSecond());
7592
time_t now;
7693
time_t rawtime = time(&now);
7794
struct tm ts;
@@ -100,7 +117,7 @@ int getMonth()
100117
struct tm *ts;
101118
time(&rawtime);
102119
ts = gmtime(&rawtime);
103-
int month = ts->tm_mon;
120+
int month = ts->tm_mon + 1;
104121
return month;
105122
}
106123

@@ -126,6 +143,16 @@ int getWday()
126143
return wday;
127144
}
128145

146+
String getDayofWeek()
147+
{
148+
return DAY_OF_WEEK[getWday()];
149+
}
150+
151+
String getShortDayofWeek()
152+
{
153+
return DAY_OF_WEEK_SHORT[getWday()];
154+
}
155+
129156
int getHour()
130157
{
131158
// tm_hour = hours since midnight (0-23)

0 commit comments

Comments
 (0)