mirror of https://github.com/arendst/Tasmota.git
Merge pull request #14318 from pkkrusty/patch-1
Add NTP server capability to DS3231 driver
This commit is contained in:
commit
26219eaebd
|
@ -787,7 +787,6 @@ void ResponseAppendFeatures(void)
|
||||||
#ifdef USE_SHIFT595
|
#ifdef USE_SHIFT595
|
||||||
feature8 |= 0x00080000; // xdrv_60_shift595.ino
|
feature8 |= 0x00080000; // xdrv_60_shift595.ino
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// feature8 |= 0x00100000;
|
// feature8 |= 0x00100000;
|
||||||
// feature8 |= 0x00200000;
|
// feature8 |= 0x00200000;
|
||||||
// feature8 |= 0x00400000;
|
// feature8 |= 0x00400000;
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
#define XSNS_33 33
|
#define XSNS_33 33
|
||||||
#define XI2C_26 26 // See I2CDEVICES.md
|
#define XI2C_26 26 // See I2CDEVICES.md
|
||||||
|
|
||||||
|
#include "NTPServer.h"
|
||||||
|
#include "NTPPacket.h"
|
||||||
|
|
||||||
//DS3232 I2C Address
|
//DS3232 I2C Address
|
||||||
#ifndef USE_RTC_ADDR
|
#ifndef USE_RTC_ADDR
|
||||||
#define USE_RTC_ADDR 0x68
|
#define USE_RTC_ADDR 0x68
|
||||||
|
@ -67,6 +70,23 @@ bool ds3231ReadStatus = false;
|
||||||
bool ds3231WriteStatus = false; //flag, we want to read/write to DS3231 only once
|
bool ds3231WriteStatus = false; //flag, we want to read/write to DS3231 only once
|
||||||
bool DS3231chipDetected = false;
|
bool DS3231chipDetected = false;
|
||||||
|
|
||||||
|
#define D_CMND_NTP "NTP"
|
||||||
|
|
||||||
|
const char S_JSON_NTP_COMMAND_NVALUE[] PROGMEM = "{\"" D_CMND_NTP "%s\":%d}";
|
||||||
|
|
||||||
|
const char kRTCTypes[] PROGMEM = "NTP";
|
||||||
|
|
||||||
|
#define NTP_MILLIS_OFFSET 50
|
||||||
|
|
||||||
|
NtpServer timeServer(PortUdp);
|
||||||
|
|
||||||
|
struct NTP_t {
|
||||||
|
struct {
|
||||||
|
uint32_t init:1;
|
||||||
|
uint32_t runningNTP:1;
|
||||||
|
} mode;
|
||||||
|
} NTP;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------*
|
/*----------------------------------------------------------------------*
|
||||||
Detect the DS3231 Chip
|
Detect the DS3231 Chip
|
||||||
----------------------------------------------------------------------*/
|
----------------------------------------------------------------------*/
|
||||||
|
@ -156,6 +176,39 @@ void DS3231EverySecond(void)
|
||||||
SetDS3231Time (Rtc.utc_time); //update the DS3231 time
|
SetDS3231Time (Rtc.utc_time); //update the DS3231 time
|
||||||
ds3231WriteStatus = true;
|
ds3231WriteStatus = true;
|
||||||
}
|
}
|
||||||
|
if (NTP.mode.runningNTP) {
|
||||||
|
timeServer.processOneRequest(Rtc.utc_time, NTP_MILLIS_OFFSET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************************************************************\
|
||||||
|
NTP functions
|
||||||
|
\*********************************************************************************************/
|
||||||
|
|
||||||
|
void NTPSelectMode(uint16_t mode)
|
||||||
|
{
|
||||||
|
DEBUG_SENSOR_LOG(PSTR("RTC: NTP status %u"),mode);
|
||||||
|
switch(mode){
|
||||||
|
case 0:
|
||||||
|
NTP.mode.runningNTP = false;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (timeServer.beginListening()) {
|
||||||
|
NTP.mode.runningNTP = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NTPCmd(void)
|
||||||
|
{
|
||||||
|
bool serviced = true;
|
||||||
|
if (XdrvMailbox.data_len > 0) {
|
||||||
|
NTPSelectMode(XdrvMailbox.payload);
|
||||||
|
Response_P(S_JSON_NTP_COMMAND_NVALUE, XdrvMailbox.command, XdrvMailbox.payload);
|
||||||
|
}
|
||||||
|
return serviced;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
|
@ -173,6 +226,11 @@ bool Xsns33(uint8_t function)
|
||||||
}
|
}
|
||||||
else if (DS3231chipDetected) {
|
else if (DS3231chipDetected) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
|
case FUNC_COMMAND_SENSOR:
|
||||||
|
if (XSNS_33 == XdrvMailbox.index) {
|
||||||
|
result = NTPCmd();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
DS3231EverySecond();
|
DS3231EverySecond();
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue