Skip to content

Commit

Permalink
Fix NTP with lwIP 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Feb 21, 2021
2 parents a6dec58 + e0b7429 commit e6ef7c2
Show file tree
Hide file tree
Showing 60 changed files with 155 additions and 148 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"}
17 changes: 10 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html

[common_env_data]
upload_speed = 921600
upload_speed = 460800 ; 921600 // MacBook can't handle the heat!
monitor_speed = 74880
monitor_filters =
; esp8266_exception_decoder
Expand All @@ -18,8 +18,8 @@ framework = arduino
platform = espressif8266
build_unflags =
build_flags =
!python tools\git_rev.py
-D PIO_SRC_TAG=2.2.2
!python tools/git_rev.py
-D PIO_SRC_TAG=2.2.3Beta
-D BAUD=${common_env_data.monitor_speed}
; -D DEBUG_ESP_PORT=Serial
; -D DEBUG_ESP_WIFI
Expand All @@ -36,23 +36,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
build_type = release
monitor_filters =
; esp8266_exception_decoder
; log2file
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 e6ef7c2

Please sign in to comment.