Skip to content

Commit

Permalink
Get rid of uneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Feb 20, 2021
1 parent a995d51 commit 7b95da9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 48 deletions.
14 changes: 7 additions & 7 deletions src/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,31 @@ 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"

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)
{
configTime(THISTZ, TIMESERVER);
if (time(nullptr) - startSecs > 9)
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
Expand All @@ -60,11 +64,7 @@ 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()
Expand Down
36 changes: 1 addition & 35 deletions src/ntp.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SOFTWARE. */
#include <Ticker.h>
#include <ArduinoLog.h>


void setClock();
String getDTS();
int getYear(); // tm_year
Expand All @@ -48,41 +49,6 @@ int getSecond(); // tm_sec
int getYDay(); // tm_yday
void ntpBlinker();

static uint32_t __attribute__((unused)) lastNTPUpdate = 0;

static const float __attribute__((unused)) GMT = 0;
static const float __attribute__((unused)) UTC = 0;
static const float __attribute__((unused)) ECT = 1.00;
static const float __attribute__((unused)) EET = 2.00;
static const float __attribute__((unused)) ART = 2.00;
static const float __attribute__((unused)) EAT = 3.00;
static const float __attribute__((unused)) MET = 3.30;
static const float __attribute__((unused)) NET = 4.00;
static const float __attribute__((unused)) PLT = 5.00;
static const float __attribute__((unused)) IST = 5.30;
static const float __attribute__((unused)) BST = 6.00;
static const float __attribute__((unused)) VST = 7.00;
static const float __attribute__((unused)) CTT = 8.00;
static const float __attribute__((unused)) JST = 9.00;
static const float __attribute__((unused)) ACT = 9.30;
static const float __attribute__((unused)) AET = 10.00;
static const float __attribute__((unused)) SST = 11.00;
static const float __attribute__((unused)) NST = 12.00;
static const float __attribute__((unused)) MIT = -11.00;
static const float __attribute__((unused)) HST = -10.00;
static const float __attribute__((unused)) AST = -9.00;
static const float __attribute__((unused)) PST = -8.00;
static const float __attribute__((unused)) PNT = -7.00;
static const float __attribute__((unused)) MST = -7.00;
static const float __attribute__((unused)) CST = -6.00;
static const float __attribute__((unused)) EST = -5.00;
static const float __attribute__((unused)) IET = -5.00;
static const float __attribute__((unused)) PRT = -4.00;
static const float __attribute__((unused)) CNT = -3.30;
static const float __attribute__((unused)) AGT = -3.00;
static const float __attribute__((unused)) BET = -3.00;
static const float __attribute__((unused)) CAT = -1.00;

static const int __attribute__((unused)) EPOCH_1_1_2019 = 1546300800; //1546300800 = 01/01/2019 @ 12:00am (UTC)
static const char __attribute__((unused)) * DAYS_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
static const char __attribute__((unused)) * DAYS_OF_WEEK_3[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
Expand Down
6 changes: 0 additions & 6 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ void maintenanceLoop()
_delay(100);
ESP.restart();
}
if (lastNTPUpdate > NTPRESET)
{
// Reset NTP (blocking) every measured 24 hours
Log.notice(F("Maintenance: Setting time"));
setClock();
}
if (blip)
{
// Bubble display in debug for Chris Thomas :)
Expand Down

0 comments on commit 7b95da9

Please sign in to comment.