Removal of ntp_client_plus files, refactoring to use time C lib instead.

This commit is contained in:
2024-04-01 03:32:54 +02:00
parent 52c7794d59
commit 73aa168152
5 changed files with 139 additions and 885 deletions

View File

@@ -1,90 +0,0 @@
#ifndef NTPCLIENTPLUS_H
#define NTPCLIENTPLUS_H
#include <Arduino.h>
#include <WiFiUdp.h>
#define UNIX_TIMESTAMP_1900 2208988800UL // careful: positive value
#define NTP_PACKET_SIZE 48
#define NTP_DEFAULT_LOCAL_PORT 1337
#define MAX_NTP_CONN_TRIES 50 // 50 * NTP_RECEIVE_WAIT_TIME_MS => 500ms
#define NTP_RECEIVE_WAIT_TIME_MS 10 // 10ms
typedef enum
{
NTP_UPDATE_TIMEOUT = -1,
NTP_UPDATE_SUCCESS = 0,
NTP_UPDATE_DIFFTOOHIGH = 1,
NTP_UPDATE_TIME_INVALID = 2
} NtpReturnValue;
/**
* @brief Own NTP Client library for Arduino with code from:
* - https://github.com/arduino-libraries/NTPClient
* - SPS&Technik - Projekt WordClock v1.02
*
*/
class NTPClientPlus
{
public:
NTPClientPlus(UDP &udp, const char *pool_server_name, int utcx, bool sw_change);
bool is_leap_year(unsigned int year);
bool check_daylight_saving_time();
int get_hours_12() const;
int get_hours_24() const;
int get_minutes() const;
int get_month(int dayOfYear);
int get_seconds() const;
int update_ntp();
long get_time_offset();
String get_formatted_date();
String get_formatted_time() const;
unsigned int get_day_of_week();
unsigned int get_year();
unsigned long get_epoch_time() const;
unsigned long get_secs_since_1900() const;
void calc_date();
void end();
void set_pool_server_name(const char *pool_server_name);
void set_time_offset(int time_offset);
void setup_ntp_client();
private:
UDP *_udp;
bool _udp_setup = false;
bool _sw_change = 1;
const char *_pool_server_name = "pool.ntp.org"; // Default time server
int _utcx = 0;
IPAddress _pool_server_ip;
long _time_offset = 0;
unsigned int _port = NTP_DEFAULT_LOCAL_PORT;
unsigned long _update_interval = 60000; // In ms
unsigned int _date_day = 0;
unsigned int _date_month = 0;
unsigned int _date_year = 0;
unsigned int _day_of_week = 0;
unsigned long _current_epoc = 0; // In s
unsigned long _last_secs_since_1900 = 0;
unsigned long _last_update = 0; // In ms
unsigned long _secs_since_1900 = 0; // seconds since 1. Januar 1900, 00:00:00
unsigned char _packet_buffer[NTP_PACKET_SIZE] = {0};
void send_ntp_packet();
void set_summertime(bool summertime);
static const unsigned long milliseconds_per_second = 1000;
static const unsigned long minutes_per_hour = 60;
static const unsigned long seconds_per_day = 86400;
static const unsigned long seconds_per_hour = 3600;
static const unsigned long seconds_per_minute = 60;
// number of days in months
unsigned int _days_per_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
};
void wait(unsigned long time_ms);
#endif /* NTPCLIENTPLUS_H */

View File

@@ -6,8 +6,10 @@
// ----------------------------------------------------------------------------------
// CONSTANTS
// ----------------------------------------------------------------------------------
#define AP_SSID "WordclockAP" // SSID name of Access Point
#define NTP_SERVER_URL "de.pool.ntp.org" // NTP server address
#define AP_SSID "WordclockAP" // SSID name of Access Point
#define NTP_SERVER_URL "de.pool.ntp.org" // NTP server address
#define MY_TZ "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" // Timezone
#define HOSTNAME (String("wordclock")) // Local hostname
#define LOGGER_MULTICAST_IP (IPAddress(230, 120, 10, 2)) // IP for UDP server
#define LOGGER_MULTICAST_PORT (8123) // Port for UDP server

View File

@@ -66,6 +66,8 @@ void handle_current_state(void);
void handle_data_request(void);
void handle_led_direct(void);
void limit_value_ranges(void);
void log_time(tm local_time);
void ntp_time_update(uint32 *last_ntp_update_us);
void ntp_time_update(uint32 *last_ntp_update_us);
void on_state_entry(uint8_t state);
void read_settings_from_EEPROM(void);