Compare commits
No commits in common. "b62ef700edd3fb1ee6bac13b22c9a8264670f89c" and "64d6c4fab3e2e8fefded0898ecc07421dcf64dd7" have entirely different histories.
b62ef700ed
...
64d6c4fab3
|
@ -1,3 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#define SDK_VESRION "2.9.0"
|
||||
#define SDK_VESRION "2.8.0"
|
|
@ -1,5 +1,4 @@
|
|||
#include <ESPMegaProOS.hpp>
|
||||
#include "esp_sntp.h"
|
||||
|
||||
// Reserve FRAM address 0 - 1000 for ESPMegaPRO Internal Use
|
||||
// (34 Bytes) Address 0-33 for Built-in Digital Output Card
|
||||
|
@ -12,7 +11,6 @@
|
|||
*/
|
||||
ESPMegaPRO::ESPMegaPRO()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,13 +102,6 @@ void ESPMegaPRO::loop()
|
|||
if (iotEnabled)
|
||||
{
|
||||
iot->loop();
|
||||
static int64_t lastNTPUpdate = (esp_timer_get_time() / 1000) - NTP_UPDATE_INTERVAL_MS + NTP_INITIAL_SYNC_DELAY_MS;
|
||||
if ((esp_timer_get_time() / 1000) - lastNTPUpdate > NTP_UPDATE_INTERVAL_MS)
|
||||
{
|
||||
ESP_LOGV("ESPMegaPRO", "Updating time from NTP");
|
||||
lastNTPUpdate = esp_timer_get_time() / 1000;
|
||||
this->updateTimeFromNTP();
|
||||
}
|
||||
}
|
||||
if (internalDisplayEnabled)
|
||||
{
|
||||
|
@ -162,35 +153,19 @@ bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard *card)
|
|||
bool ESPMegaPRO::updateTimeFromNTP()
|
||||
{
|
||||
struct tm timeinfo;
|
||||
uint32_t start = esp_timer_get_time() / 1000;
|
||||
time_t now;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
if (!(timeinfo.tm_year > (2016 - 1900)))
|
||||
if (getLocalTime(&timeinfo))
|
||||
{
|
||||
ESP_LOGI("ESPMegaPRO", "NTP is not ready yet!");
|
||||
return false;
|
||||
rtctime_t rtctime = this->getTime();
|
||||
if (rtctime.hours != timeinfo.tm_hour || rtctime.minutes != timeinfo.tm_min ||
|
||||
rtctime.seconds != timeinfo.tm_sec || rtctime.day != timeinfo.tm_mday ||
|
||||
rtctime.month != timeinfo.tm_mon + 1 || rtctime.year != timeinfo.tm_year + 1900)
|
||||
{
|
||||
this->setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec,
|
||||
timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
rtctime_t rtctime = this->getTime();
|
||||
if (rtctime.hours != timeinfo.tm_hour || rtctime.minutes != timeinfo.tm_min ||
|
||||
rtctime.seconds != timeinfo.tm_sec || rtctime.day != timeinfo.tm_mday ||
|
||||
rtctime.month != timeinfo.tm_mon + 1 || rtctime.year != timeinfo.tm_year + 1900)
|
||||
{
|
||||
this->setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec,
|
||||
timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900);
|
||||
}
|
||||
ESP_LOGV("ESPMegaPRO", "Time updated from NTP: %s", asctime(&timeinfo));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the timezone for the internal RTC.
|
||||
*
|
||||
* @note This function takes POSIX timezone strings (e.g. "EST5EDT,M3.2.0,M11.1.0").
|
||||
*/
|
||||
void ESPMegaPRO::setTimezone(const char* offset)
|
||||
{
|
||||
setenv("TZ", offset, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -247,10 +222,6 @@ void ESPMegaPRO::enableIotModule()
|
|||
this->iot->bindFRAM(&fram);
|
||||
this->iot->intr_begin(cards);
|
||||
iotEnabled = true;
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, this->iot->getMqttConfig()->mqtt_server);
|
||||
sntp_setservername(1, "pool.ntp.org");
|
||||
sntp_init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,11 +24,6 @@
|
|||
#define PWM_BANK_ADDRESS 0x5F
|
||||
#define RTC_ADDRESS 0x68
|
||||
|
||||
// Constants
|
||||
#define NTP_TIMEOUT_MS 5000
|
||||
#define NTP_UPDATE_INTERVAL_MS 60000
|
||||
#define NTP_INITIAL_SYNC_DELAY_MS 15000
|
||||
|
||||
/**
|
||||
* @brief The ESPMegaPRO class is the main class for the ESPMegaPRO library.
|
||||
*
|
||||
|
@ -52,7 +47,6 @@ class ESPMegaPRO {
|
|||
void enableIotModule();
|
||||
void enableInternalDisplay(HardwareSerial *serial);
|
||||
void enableWebServer(uint16_t port);
|
||||
void setTimezone(const char* offset);
|
||||
rtctime_t getTime();
|
||||
void dumpFRAMtoSerial(uint16_t start, uint16_t end);
|
||||
void dumpFRAMtoSerialASCII(uint16_t start, uint16_t end);
|
||||
|
|
|
@ -14,16 +14,15 @@
|
|||
|
||||
// #define FRAM_DEBUG
|
||||
// #define MQTT_DEBUG
|
||||
// #define RTC_DEBUG
|
||||
#define WRITE_DEFAULT_NETCONF
|
||||
#define CLIMATE_CARD_ENABLE
|
||||
#define MQTT_CARD_REGISTER
|
||||
// #define DISPLAY_ENABLE
|
||||
#define DISPLAY_ENABLE
|
||||
#define WEB_SERVER_ENABLE
|
||||
#define LCD_OTA_ENABLE
|
||||
// #define REMOTE_VARIABLE_ENABLE
|
||||
// #define CT_ENABLE
|
||||
// #define SMART_VARIABLE_ENABLE
|
||||
#define SMART_VARIABLE_ENABLE
|
||||
|
||||
// Demo PLC firmware using the ESPMegaPRO OOP library
|
||||
|
||||
|
@ -163,7 +162,6 @@ void setup()
|
|||
{
|
||||
ESP_LOGI("Initializer", "Starting ESPMegaPRO OOP demo");
|
||||
espmega.begin();
|
||||
espmega.setTimezone("UTC-7");
|
||||
ESP_LOGI("Initializer", "Enabling IOT module");
|
||||
espmega.enableIotModule();
|
||||
ESP_LOGI("Initializer", "Enabling Ethernet");
|
||||
|
@ -328,13 +326,4 @@ void loop()
|
|||
smartVar.setValue(last_smartvar_state ? "true" : "false");
|
||||
}
|
||||
#endif
|
||||
#ifdef RTC_DEBUG
|
||||
static uint32_t last_time_print = 0;
|
||||
if (millis() - last_time_print >= 1000)
|
||||
{
|
||||
last_time_print = millis();
|
||||
rtctime_t time = espmega.getTime();
|
||||
Serial.printf("Time: %02d:%02d:%02d %02d/%02d/%04d\n", time.hours, time.minutes, time.seconds, time.day, time.month, time.year);
|
||||
}
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue