Switched from NTPClient to lwIPs internal SNTP client.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This has the advantage of being able to set DST automatically.
This commit is contained in:
parent
e2a56d7c29
commit
47812de405
@ -10,7 +10,7 @@ private:
|
|||||||
CRGB _color_seconds_moving_light = CRGB(0x666600);
|
CRGB _color_seconds_moving_light = CRGB(0x666600);
|
||||||
CRGB _color_seconds_moving_dark = CRGB(0x660000);
|
CRGB _color_seconds_moving_dark = CRGB(0x660000);
|
||||||
|
|
||||||
void _draw_seconds();
|
void _draw_seconds(uint8_t seconds);
|
||||||
void _draw_border_pixel(accum88 pos, CRGB* color);
|
void _draw_border_pixel(accum88 pos, CRGB* color);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <NTPClient.h>
|
|
||||||
#include "my_wifi.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
void time_changed();
|
||||||
extern NTPClient ntpClient;
|
|
||||||
void updateCallback(NTPClient* c);
|
|
||||||
void ntp_setup();
|
void ntp_setup();
|
||||||
|
@ -16,7 +16,6 @@ env_default = ota
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
PubSubClient
|
PubSubClient
|
||||||
https://github.com/fabianonline/FastLED.git
|
https://github.com/fabianonline/FastLED.git
|
||||||
https://github.com/fabianonline/NTPClient.git
|
|
||||||
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||||
|
|
||||||
[env:ota]
|
[env:ota]
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "effect_analogclock.h"
|
#include "effect_analogclock.h"
|
||||||
#include "my_fastled.h"
|
#include "my_fastled.h"
|
||||||
#include "ntp.h"
|
#include "ntp.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
void AnalogClockEffect::loop(uint16_t ms) {
|
void AnalogClockEffect::loop(uint16_t ms) {
|
||||||
window->clear();
|
window->clear();
|
||||||
@ -8,10 +9,18 @@ void AnalogClockEffect::loop(uint16_t ms) {
|
|||||||
CRGB red(0xFF0000);
|
CRGB red(0xFF0000);
|
||||||
window->circle(8, 8, 7, &white);
|
window->circle(8, 8, 7, &white);
|
||||||
|
|
||||||
uint8_t seconds = ntpClient.getSeconds();
|
time_t now;
|
||||||
uint8_t angle = seconds * 256 / 60;
|
tm timeinfo;
|
||||||
window->lineWithAngle(8, 8, angle, 10, &red);
|
time(&now);
|
||||||
window->line(1<<8, 1<<8, 12<<8, 4<<8, &white);
|
localtime_r(&now, &timeinfo);
|
||||||
|
uint16_t seconds = timeinfo.tm_sec * 1000 + (millis()%1000);
|
||||||
|
uint16_t angle = seconds * 0x10000 / 60000;
|
||||||
|
window->lineWithAngle(8, 8, angle, 12, &red);
|
||||||
|
//window->line(0<<8, 0<<8, 7<<8, 7<<8, &white);
|
||||||
|
//window->line(15<<8, 0<<8, 8<<8, 7<<8, &red);
|
||||||
|
//window->line(0<<8, 15<<8, 7<<8, 8<<8, &blue);
|
||||||
|
//window->line(15<<8, 15<<8, 8<<8, 8<<8, &green);
|
||||||
|
|
||||||
/*for (uint8_t i=0; i<=12; i++) {
|
/*for (uint8_t i=0; i<=12; i++) {
|
||||||
window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white);
|
window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white);
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
#include "Effect.h"
|
#include "Effect.h"
|
||||||
#include "effect_big_clock.h"
|
#include "effect_big_clock.h"
|
||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
#include "ntp.h"
|
#include <time.h>
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
void BigClockEffect::loop(uint16_t ms) {
|
void BigClockEffect::loop(uint16_t ms) {
|
||||||
window->clear();
|
window->clear();
|
||||||
uint8_t h = ntpClient.getHours();
|
time_t now;
|
||||||
|
tm timeinfo;
|
||||||
|
time(&now);
|
||||||
|
localtime_r(&now, &timeinfo);
|
||||||
|
uint8_t h = timeinfo.tm_hour;
|
||||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
|
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
|
||||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font);
|
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font);
|
||||||
|
|
||||||
uint8_t m = ntpClient.getMinutes();
|
uint8_t m = timeinfo.tm_min;
|
||||||
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
|
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
|
||||||
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font);
|
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font);
|
||||||
|
|
||||||
uint8_t s = ntpClient.getSeconds();
|
uint8_t s = timeinfo.tm_sec;
|
||||||
if (s & 1) {
|
if (s & 1) {
|
||||||
window->setPixel(3, 10, &_color_font);
|
window->setPixel(3, 10, &_color_font);
|
||||||
window->setPixel(3, 12, &_color_font);
|
window->setPixel(3, 12, &_color_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
_draw_seconds();
|
_draw_seconds(timeinfo.tm_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BigClockEffect::_draw_seconds() {
|
void BigClockEffect::_draw_seconds(uint8_t seconds) {
|
||||||
uint8_t seconds = ntpClient.getSeconds();
|
|
||||||
for (int i=1; i<=seconds; i++) {
|
for (int i=1; i<=seconds; i++) {
|
||||||
_draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
|
_draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
uint16_t mil = millis() % 1000;
|
||||||
accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - millis) / 1000 + (1<<8);
|
accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - mil) / 1000 + (1<<8);
|
||||||
uint8_t sec = seconds + 1;
|
uint8_t sec = seconds + 1;
|
||||||
while (pos < (60<<8)) {
|
while (pos < (60<<8)) {
|
||||||
_draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);
|
_draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);
|
||||||
|
@ -42,18 +42,22 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo
|
|||||||
}
|
}
|
||||||
fg_color = bg_color;
|
fg_color = bg_color;
|
||||||
}
|
}
|
||||||
if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
|
/*if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
|
||||||
window->clear(&bg_color);
|
window->clear(&bg_color);
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
int h = ntpClient.getHours();
|
time_t now;
|
||||||
|
tm timeinfo;
|
||||||
|
time(&now);
|
||||||
|
localtime_r(&now, &timeinfo);
|
||||||
|
int h = timeinfo.tm_hour;
|
||||||
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
||||||
window->drawChar(&font_numbers3x5, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert);
|
window->drawChar(&font_numbers3x5, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert);
|
||||||
window->drawChar(&font_numbers3x5, 4<<8, yPos<<8, '0' + (h % 10), &fg_color, invert);
|
window->drawChar(&font_numbers3x5, 4<<8, yPos<<8, '0' + (h % 10), &fg_color, invert);
|
||||||
int m = ntpClient.getMinutes();
|
int m = timeinfo.tm_min;
|
||||||
window->drawChar(&font_numbers3x5, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert);
|
window->drawChar(&font_numbers3x5, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert);
|
||||||
window->drawChar(&font_numbers3x5, 13<<8, yPos<<8, '0' + (m % 10), &fg_color, invert);
|
window->drawChar(&font_numbers3x5, 13<<8, yPos<<8, '0' + (m % 10), &fg_color, invert);
|
||||||
if (ntpClient.getSeconds() & 1) {
|
if (timeinfo.tm_sec & 1) {
|
||||||
window->setPixel(7, yPos+1, &fg_color);
|
window->setPixel(7, yPos+1, &fg_color);
|
||||||
window->setPixel(7, yPos+3, &fg_color);
|
window->setPixel(7, yPos+3, &fg_color);
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,20 @@ PixelClockEffect::~PixelClockEffect() {
|
|||||||
void PixelClockEffect::loop(uint16_t ms) {
|
void PixelClockEffect::loop(uint16_t ms) {
|
||||||
uint8_t x, y; // Temporary variables for calculating positions
|
uint8_t x, y; // Temporary variables for calculating positions
|
||||||
window->clear();
|
window->clear();
|
||||||
|
time_t now;
|
||||||
|
tm timeinfo;
|
||||||
|
time(&now);
|
||||||
|
localtime_r(&now, &timeinfo);
|
||||||
|
|
||||||
// Seconds
|
// Seconds
|
||||||
uint8_t seconds = ntpClient.getSeconds();
|
uint8_t seconds = timeinfo.tm_sec;
|
||||||
for (uint8_t s=0; s<60; s++) {
|
for (uint8_t s=0; s<60; s++) {
|
||||||
x = window->width - 1 - s/10;
|
x = window->width - 1 - s/10;
|
||||||
y = window->height - 1 - (s % 10);
|
y = window->height - 1 - (s % 10);
|
||||||
if (s<seconds) window->setPixel(x, y, _color_seconds);
|
if (s<seconds) window->setPixel(x, y, _color_seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t minutes = ntpClient.getMinutes();
|
uint8_t minutes = timeinfo.tm_min;
|
||||||
for (uint8_t m=0; m<60; m++) {
|
for (uint8_t m=0; m<60; m++) {
|
||||||
x = 6 - m/10;
|
x = 6 - m/10;
|
||||||
y = window->height - 1 - (m % 10);
|
y = window->height - 1 - (m % 10);
|
||||||
|
@ -9,7 +9,8 @@ void TimerEffect::loop(uint16_t ms) {
|
|||||||
|
|
||||||
CRGB bg_color(0x000000);
|
CRGB bg_color(0x000000);
|
||||||
CRGB fg_color(0xCCCCCC);
|
CRGB fg_color(0xCCCCCC);
|
||||||
unsigned long now = ntpClient.getEpochTime() - NTP_OFFSET;
|
time_t now;
|
||||||
|
time(&now);
|
||||||
long diff = timer - now;
|
long diff = timer - now;
|
||||||
window->clear(&bg_color);
|
window->clear(&bg_color);
|
||||||
if (diff < 0 && (now & 1)==0) return;
|
if (diff < 0 && (now & 1)==0) return;
|
||||||
|
25
src/ntp.cpp
25
src/ntp.cpp
@ -1,13 +1,26 @@
|
|||||||
#include <ntp.h>
|
#include <sntp.h>
|
||||||
|
#include <coredecls.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <TZ.h>
|
||||||
#include "my_fastled.h"
|
#include "my_fastled.h"
|
||||||
|
|
||||||
void updateCallback(NTPClient* c) {
|
/*void updateCallback(NTPClient* c) {
|
||||||
random16_add_entropy(c->getEpochMillis() & 0xFFFF);
|
random16_add_entropy(c->getEpochMillis() & 0xFFFF);
|
||||||
}
|
LOGln("Received current time. Epoch is %lu.", ntpClient.getEpochTime());
|
||||||
|
}*/
|
||||||
|
|
||||||
WiFiUDP ntpUDP;
|
void time_changed() {
|
||||||
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL);
|
random16_add_entropy(millis() & 0xFFFF);
|
||||||
|
time_t now;
|
||||||
|
tm timeinfo;
|
||||||
|
time(&now);
|
||||||
|
localtime_r(&now, &timeinfo);
|
||||||
|
char time_s[30];
|
||||||
|
strftime(time_s, 30, "%a %d.%m.%Y %T", &timeinfo);
|
||||||
|
LOGln("NTP * Received time: %s", time_s);
|
||||||
|
}
|
||||||
|
|
||||||
void ntp_setup() {
|
void ntp_setup() {
|
||||||
ntpClient.setUpdateCallback(updateCallback);
|
settimeofday_cb(time_changed);
|
||||||
|
configTime(TZ_Europe_Berlin, "de.pool.ntp.org");
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ void setup() {
|
|||||||
ntp_setup();
|
ntp_setup();
|
||||||
ota_setup();
|
ota_setup();
|
||||||
fastled_setup();
|
fastled_setup();
|
||||||
ntpClient.begin();
|
|
||||||
#ifdef HTTP_SERVER_ENABLE
|
#ifdef HTTP_SERVER_ENABLE
|
||||||
http_server_setup();
|
http_server_setup();
|
||||||
#endif
|
#endif
|
||||||
@ -76,7 +75,6 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ntpClient.update();
|
|
||||||
#ifdef MQTT_ENABLE
|
#ifdef MQTT_ENABLE
|
||||||
mqtt_loop();
|
mqtt_loop();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user