Skip to content

Commit

Permalink
Fix NTP with lwIP 1.4 (#44)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lbussy committed Feb 21, 2021
1 parent 6ba9e7b commit e0b7429
Show file tree
Hide file tree
Showing 60 changed files with 153 additions and 149 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion data/about.htm
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h4 class="card-title">

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

Expand Down
2 changes: 1 addition & 1 deletion data/help.htm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h4 class="card-title">Brew Bubbles Support</h4>

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

Expand Down
2 changes: 1 addition & 1 deletion data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h4 class="card-title">Current Readings</h4>

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

Expand Down
4 changes: 2 additions & 2 deletions data/license.htm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<h4 class="card-title">Brew Bubbles License</h4>
</div>
<div class="card-body">
<p>Copyright 2019-2020 Lee C. Bussy</p>
<p>Copyright 2019-2021 Lee C. Bussy</p>

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

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

Expand Down
2 changes: 1 addition & 1 deletion data/ota.htm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h4 class="card-title">Firmware Update In Progress, please Wait ...</h4>

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

Expand Down
2 changes: 1 addition & 1 deletion data/reset.htm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h4 class="card-title">Controller Reset</h4>

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

Expand Down
2 changes: 1 addition & 1 deletion data/settings.htm
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ <h4 class="card-title">Reset Wifi Settings</h4>

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

Expand Down
2 changes: 1 addition & 1 deletion data/wifi.htm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h4 class="card-title">Reset WiFi: Confirmation</h4>

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

Expand Down
2 changes: 1 addition & 1 deletion data/wifi2.htm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ <h4 class="card-title">Resetting WiFi Configuration</h4>

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

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# -- Project information -----------------------------------------------------

project = u'Brew Bubbles'
copyright = u'2019-2020, Lee C. Bussy'
copyright = u'2019-2021, Lee C. Bussy'
author = u'Lee C. Bussy'

# Get 0.0.0 version from latest Git tag
Expand Down
Binary file added firmware/firmware.bin
Binary file not shown.
Binary file added firmware/littlefs.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion firmware/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "2.2.2"}
{"version": "2.2.3beta"}
16 changes: 8 additions & 8 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
; https://docs.platformio.org/page/projectconf.html

[common_env_data]
upload_speed = 460800 ; 921600
upload_speed = 460800 ; 921600 // MacBook can't handle the heat!
monitor_speed = 74880
framework = arduino
platform = espressif8266
build_unflags =
build_flags =
!python tools/git_rev.py
-D PIO_SRC_TAG=2.2.2
-D PIO_SRC_TAG=2.2.3Beta
-D BAUD=${common_env_data.monitor_speed}
-DDEBUG_ESP_PORT=Serial
; -DDEBUG_ESP_PORT=Serial
; -D DEBUG_ESP_WIFI
; -D DEBUG_ESP_HTTP_UPDATE
; -D DEBUG_ESP_HTTP_CLIENT
Expand All @@ -33,26 +33,26 @@ build_flags =
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH ; v2 Higher Bandwidth (no features)
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY ; v2 IPv6 Lower Memory
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_HIGHER_BANDWIDTH ; v2 IPv6 Higher Bandwidth
-D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH ; v1.4 Higher Bandwidth
-D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH ; v1.4 Higher Bandwidth (Needed because of stream errors getting Filesystem OTA)
extra_scripts = ; pre:python tools\name_firmware.py
lib_deps =
ArduinoJson
https://github.com/lbussy/OneWire.git
https://github.com/lbussy/DS18B20.git
https://github.com/lbussy/Arduino-Log.git
https://github.com/lbussy/ESPAsyncTCP
https://github.com/lbussy/ESPAsyncWebServer.git
https://github.com/lbussy/AsyncWiFiManager.git
https://github.com/lbussy/ESPAsyncTCP
https://github.com/lbussy/asyncHTTPrequest.git
https://github.com/lbussy/CircularBuffer.git
https://github.com/lbussy/LCBUrl.git
https://github.com/lbussy/esptelnet.git
https://github.com/lbussy/ESP_DoubleResetDetector
khoih-prog/ESP_WiFiManager
https://github.com/lbussy/ThingSpeak
monitor_filters =
esp8266_exception_decoder
; esp8266_exception_decoder
; log2file
build_type = release
build_type = release ; Cannot use debug with Wemos D1

[env:d1_mini]
board_build.filesystem = littlefs
Expand Down
2 changes: 1 addition & 1 deletion src/brewersfriend.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/brewersfriend.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/brewfather.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/brewfather.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/bubbles.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/bubbles.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
8 changes: 5 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
Expand Down Expand Up @@ -65,7 +65,7 @@ SOFTWARE. */
// Use SPIFFS Editor
//
#ifndef SPIFFSEDIT
#define SPIFFSEDIT
// #define SPIFFSEDIT
#endif
//
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -427,7 +427,9 @@ SOFTWARE. */
// NTP Server
//
#ifndef TIMESERVER
#define TIMESERVER "pool.ntp.org"
#define TIMESERVER "pool.ntp.org", "time.nist.gov"
#define THISTZ TZ_Etc_GMT
// #define THISTZ TZ_America_Chicago
#endif
//
//////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 5 additions & 1 deletion src/execota.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand All @@ -22,6 +22,10 @@ SOFTWARE. */

#include "execota.h"

#if LWIP_VERSION_MAJOR == 2
#warning "Remember: You are using lwIP v2.x and this causes filesystem OTA tp act weird."
#endif

void execfw()
{
Log.notice(F("Starting the Firmware OTA pull, will reboot without notice." CR));
Expand Down
2 changes: 1 addition & 1 deletion src/execota.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
Expand Down
2 changes: 1 addition & 1 deletion src/jsonconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/jsonconfig.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
Expand Down
2 changes: 1 addition & 1 deletion src/mdns.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand Down
2 changes: 1 addition & 1 deletion src/mdns.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)
This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).
Expand Down
55 changes: 41 additions & 14 deletions src/ntp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019-2020 Lee C. Bussy (@LBussy)
/* Copyright (C) 2019-2021 Lee C. Bussy (@LBussy)

This file is part of Lee Bussy's Brew Bubbles (brew-bubbles).

Expand All @@ -20,34 +20,56 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

// NTP Examples in:
// https://github.com/esp8266/Arduino/blob/master/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino

#include "ntp.h"

#if LWIP_VERSION_MAJOR == 1
#warning "Remember: You are using lwIP v1.x and this causes ntp time to act weird."
#endif

static const int __attribute__((unused)) SECS_1_1_2019 = 1546300800; //1546300800 = 01/01/2019 @ 12:00am (UTC)
static const char __attribute__((unused)) * DAY_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
static const char __attribute__((unused)) * DAY_OF_WEEK_SHORT[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

void setClock()
{
Ticker blinker;
Log.notice(F("Entering blocking loop to get NTP time."));
blinker.attach_ms(NTPBLINK, ntpBlinker);
time_t startSecs = time(nullptr);
unsigned long startSecs = millis() / 1000;
int cycle = 0;
while (time(nullptr) < EPOCH_1_1_2019)
#if LWIP_VERSION_MAJOR == 1
sntp_setservername(0, (char *)"pool.ntp.org");
sntp_setservername(0, (char *)"time.nist.gov");
sntp_set_timezone(0);
while (sntp_get_current_timestamp() == 0)
{
sntp_stop();
sntp_init();
#else
while (time(nullptr) < SECS_1_1_2019)
{
configTime("GMT", "pool.ntp.org", "time.nist.gov");
if (time(nullptr) - startSecs > 9)
configTime(THISTZ, TIMESERVER);
#endif
if ((millis() / 1000) - startSecs > 9)
{
if (cycle > 9)
{
#ifdef LOG_LEVEL
myPrintln();
#endif
Log.warning(F("Unable to get time hack from %s, starting with epoch." CR), TIMESERVER);
Log.warning(F("Unable to get time hack from server, restarting." CR));
blinker.detach();
ESP.restart();
return;
}
#ifdef LOG_LEVEL
myPrintln();
#endif
Log.verbose(F("Re-requesting time hack."));
startSecs = time(nullptr);
startSecs = millis() / 1000;
cycle++;
}
#ifdef LOG_LEVEL
Expand All @@ -60,18 +82,13 @@ void setClock()
#ifdef LOG_LEVEL
myPrintln();
#endif
lastNTPUpdate = millis();
Log.notice(F("NTP time set." CR));
struct tm timeinfo;
time_t nowSecs = time(nullptr);
gmtime_r(&nowSecs, &timeinfo);
}

String getDTS()
{
// Returns JSON-type string = 2019-12-20T13:59:39Z
/// Also:
// sprintf(dts, "%04u-%02u-%02uT%02u:%02u:%02uZ", getYear(), getMonth(), getDate(), getHour(), getMinute(), getSecond());
// Also: sprintf(dta, "%04u-%02u-%02uT%02u:%02u:%02uZ", getYear(), getMonth(), getDate(), getHour(), getMinute(), getSecond());
time_t now;
time_t rawtime = time(&now);
struct tm ts;
Expand Down Expand Up @@ -100,7 +117,7 @@ int getMonth()
struct tm *ts;
time(&rawtime);
ts = gmtime(&rawtime);
int month = ts->tm_mon;
int month = ts->tm_mon + 1;
return month;
}

Expand All @@ -126,6 +143,16 @@ int getWday()
return wday;
}

String getDayofWeek()
{
return DAY_OF_WEEK[getWday()];
}

String getShortDayofWeek()
{
return DAY_OF_WEEK_SHORT[getWday()];
}

int getHour()
{
// tm_hour = hours since midnight (0-23)
Expand Down
Loading

0 comments on commit e0b7429

Please sign in to comment.