Skip to content

Commit

Permalink
Merge pull request letscontrolit#4347 from TD-er/build/swap_alt_wifi
Browse files Browse the repository at this point in the history
[WiFi] Switch default and alt.WiFi builds for ESP8266
  • Loading branch information
TD-er authored Nov 9, 2022
2 parents 6439616 + 1f017b6 commit b6c0356
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ platform = [email protected]
platform_packages =
framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#2.7.4
build_flags = ${esp82xx_2_6_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190313
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190703
-Wno-deprecated-declarations
lib_ignore = ${esp82xx_defaults.lib_ignore}
IRremoteESP8266
Expand All @@ -153,7 +153,7 @@ platform = [email protected]
platform_packages =
framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#2.7.4
build_flags = ${esp82xx_2_6_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_191122
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190313
-Wno-deprecated-declarations
lib_ignore = ${esp82xx_defaults.lib_ignore}
IRremoteESP8266
Expand Down
2 changes: 1 addition & 1 deletion src/src/DataStructs/Web_StreamingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Web_StreamingBuffer& Web_StreamingBuffer::addFlashString(PGM_P str, int length)
*/
{
// Copy to internal buffer and send in chunks
unsigned int pos = 0;
int pos = 0;
while (pos < length) {
if (flush_step == 0) {
flush();
Expand Down
8 changes: 7 additions & 1 deletion src/src/ESPEasyCore/ESPEasyNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../ESPEasyCore/ESPEasy_Log.h"
#include "../ESPEasyCore/ESPEasyEth.h"
#include "../ESPEasyCore/ESPEasyWifi.h"
#include "../Globals/ESPEasy_time.h"
#include "../Globals/ESPEasyWiFiEvent.h"
#include "../Globals/NetworkState.h"
#include "../Globals/Settings.h"
Expand Down Expand Up @@ -224,13 +225,18 @@ MAC_address WifiSTAmacAddress() {
}

void CheckRunningServices() {
set_mDNS();
// First try to get the time, since that may be used in logs
if (Settings.UseNTP() && node_time.timeSource > timeSource_t::NTP_time_source) {
node_time.lastNTPSyncTime_ms = 0;
node_time.initTime();
}
#ifdef ESP8266
if (active_network_medium == NetworkMedium_t::WIFI)
{
SetWiFiTXpower();
}
#endif
set_mDNS();
}

#if FEATURE_ETHERNET
Expand Down
4 changes: 0 additions & 4 deletions src/src/ESPEasyCore/ESPEasyWifi_ProcessEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ void handle_unprocessedNetworkEvents()
}
WiFiEventData.setWiFiServicesInitialized();
CheckRunningServices();
// First try to get the time, since that may be used in logs
if (Settings.UseNTP()) {
node_time.initTime();
}
}
}
}
Expand Down
34 changes: 12 additions & 22 deletions src/src/Helpers/ESPEasy_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ struct tm ESPEasy_time::addSeconds(const struct tm& ts, int seconds, bool toLoca
void ESPEasy_time::restoreFromRTC()
{
static bool firstCall = true;
uint32_t unixtime = 0;

#if FEATURE_EXT_RTC
uint32_t unixtime = 0;
if (ExtRTC_get(unixtime)) {
setExternalTimeSource(unixtime, timeSource_t::External_RTC_time_source);
firstCall = false;
return;
}
#endif

if (firstCall && (RTC.lastSysTime != 0) && (RTC.deepSleepState != 1)) {
firstCall = false;
Expand Down Expand Up @@ -179,7 +181,6 @@ unsigned long ESPEasy_time::now() {
if (getNtpTime(unixTime_d)) {
updatedTime = true;
} else {
uint32_t tmp_unixtime = 0;
#if FEATURE_ESPEASY_P2P
double tmp_unixtime_d;

Expand All @@ -191,6 +192,8 @@ unsigned long ESPEasy_time::now() {
}
#endif // if FEATURE_ESPEASY_P2P

#if FEATURE_EXT_RTC
uint32_t tmp_unixtime = 0;
if (!updatedTime &&
(timeSource > timeSource_t::External_RTC_time_source) && // No need to set from ext RTC more than once.
ExtRTC_get(tmp_unixtime)) {
Expand All @@ -199,6 +202,7 @@ unsigned long ESPEasy_time::now() {
updatedTime = true;
syncInterval = 120; // Allow sync in 2 minutes to see if we get some better options from p2p nodes.
}
#endif
}
}

Expand All @@ -224,9 +228,11 @@ unsigned long ESPEasy_time::now() {

sysTime = unixTime_d;

#if FEATURE_EXT_RTC
// External RTC only stores with second resolution.
// Thus to limit the error to +/- 500 ms, round the sysTime instead of just casting it.
ExtRTC_set(round(sysTime));
#endif
{
const unsigned long abs_time_offset_ms = std::abs(time_offset) * 1000;

Expand Down Expand Up @@ -735,6 +741,7 @@ struct tm ESPEasy_time::getSunSet(int secOffset) const {
return addSeconds(tsSet, secOffset, true);
}

#if FEATURE_EXT_RTC
bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
{
unixtime = 0;
Expand All @@ -744,7 +751,6 @@ bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
return false;
case ExtTimeSource_e::DS1307:
{
#if FEATURE_EXT_RTC
I2CSelect_Max100kHz_ClockSpeed(); // Only supports upto 100 kHz
RTC_DS1307 rtc;

Expand All @@ -758,12 +764,10 @@ bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
break;
}
unixtime = rtc.now().unixtime();
#endif // if FEATURE_EXT_RTC
break;
}
case ExtTimeSource_e::DS3231:
{
#if FEATURE_EXT_RTC
RTC_DS3231 rtc;

if (!rtc.begin()) {
Expand All @@ -776,13 +780,11 @@ bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
break;
}
unixtime = rtc.now().unixtime();
#endif // if FEATURE_EXT_RTC
break;
}

case ExtTimeSource_e::PCF8523:
{
#if FEATURE_EXT_RTC
RTC_PCF8523 rtc;

if (!rtc.begin()) {
Expand All @@ -795,12 +797,10 @@ bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
break;
}
unixtime = rtc.now().unixtime();
#endif // if FEATURE_EXT_RTC
break;
}
case ExtTimeSource_e::PCF8563:
{
#if FEATURE_EXT_RTC
RTC_PCF8563 rtc;

if (!rtc.begin()) {
Expand All @@ -813,7 +813,6 @@ bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
break;
}
unixtime = rtc.now().unixtime();
#endif // if FEATURE_EXT_RTC
break;
}
}
Expand All @@ -827,83 +826,74 @@ bool ESPEasy_time::ExtRTC_get(uint32_t& unixtime)
addLog(LOG_LEVEL_ERROR, F("ExtRTC: Cannot get time from external time source"));
return false;
}
#endif

#if FEATURE_EXT_RTC
bool ESPEasy_time::ExtRTC_set(uint32_t unixtime)
{
if (timeSource >= timeSource_t::External_RTC_time_source) {
// Do not adjust the external RTC time if we already used it as a time source.
// or the new time source is worse than the external RTC time souce.
return true;
}
#if FEATURE_EXT_RTC
bool timeAdjusted = false;
#endif // if FEATURE_EXT_RTC

switch (Settings.ExtTimeSource()) {
case ExtTimeSource_e::None:
return false;
case ExtTimeSource_e::DS1307:
{
#if FEATURE_EXT_RTC
I2CSelect_Max100kHz_ClockSpeed(); // Only supports upto 100 kHz
RTC_DS1307 rtc;

if (rtc.begin()) {
rtc.adjust(DateTime(unixtime));
timeAdjusted = true;
}
#endif // if FEATURE_EXT_RTC
break;
}
case ExtTimeSource_e::DS3231:
{
#if FEATURE_EXT_RTC
RTC_DS3231 rtc;

if (rtc.begin()) {
rtc.adjust(DateTime(unixtime));
timeAdjusted = true;
}
#endif // if FEATURE_EXT_RTC
break;
}

case ExtTimeSource_e::PCF8523:
{
#if FEATURE_EXT_RTC
RTC_PCF8523 rtc;

if (rtc.begin()) {
rtc.adjust(DateTime(unixtime));
rtc.start();
timeAdjusted = true;
}
#endif // if FEATURE_EXT_RTC
break;
}
case ExtTimeSource_e::PCF8563:
{
#if FEATURE_EXT_RTC
RTC_PCF8563 rtc;

if (rtc.begin()) {
rtc.adjust(DateTime(unixtime));
rtc.start();
timeAdjusted = true;
}
#endif // if FEATURE_EXT_RTC
break;
}
}
#if FEATURE_EXT_RTC

if (timeAdjusted) {
addLogMove(LOG_LEVEL_INFO, concat(
F("ExtRTC: External time source set to: "),
unixtime));
return true;
}
#endif // if FEATURE_EXT_RTC
addLog(LOG_LEVEL_ERROR, F("ExtRTC: Cannot set time to external time source"));
return false;
}
#endif
2 changes: 2 additions & 0 deletions src/src/Helpers/ESPEasy_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@ class ESPEasy_time {
struct tm getSunRise(int secOffset) const;
struct tm getSunSet(int secOffset) const;

#if FEATURE_EXT_RTC
public:

bool ExtRTC_get(uint32_t& unixtime);

private:

bool ExtRTC_set(uint32_t unixtime);
#endif

public:

Expand Down
6 changes: 5 additions & 1 deletion src/src/Helpers/StringProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const __FlashStringHelper * getLabel(LabelType::Enum label) {
case LabelType::LOCAL_TIME: return F("Local Time");
case LabelType::TIME_SOURCE: return F("Time Source");
case LabelType::TIME_WANDER: return F("Time Wander");
case LabelType::EXT_RTC_UTC_TIME: return F("UTC time stored in RTC");
#if FEATURE_EXT_RTC
case LabelType::EXT_RTC_UTC_TIME: return F("UTC time stored in RTC chip");
#endif
case LabelType::UPTIME: return F("Uptime");
case LabelType::LOAD_PCT: return F("Load");
case LabelType::LOOP_COUNT: return F("Load LC");
Expand Down Expand Up @@ -264,6 +266,7 @@ String getValue(LabelType::Enum label) {
return toString(node_time.timeSource);
}
case LabelType::TIME_WANDER: return String(node_time.timeWander, 1);
#if FEATURE_EXT_RTC
case LabelType::EXT_RTC_UTC_TIME:
{
if (Settings.ExtTimeSource() != ExtTimeSource_e::None) {
Expand All @@ -279,6 +282,7 @@ String getValue(LabelType::Enum label) {
}
return String('-');
}
#endif
case LabelType::UPTIME: return String(getUptimeMinutes());
case LabelType::LOAD_PCT: return toString(getCPUload(), 2);
case LabelType::LOOP_COUNT: return String(getLoopCountPerSec());
Expand Down
2 changes: 2 additions & 0 deletions src/src/Helpers/StringProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ struct LabelType {
LOCAL_TIME,
TIME_SOURCE,
TIME_WANDER,
#if FEATURE_EXT_RTC
EXT_RTC_UTC_TIME,
#endif
UPTIME,
LOAD_PCT, // 15.10
LOOP_COUNT, // 400
Expand Down
2 changes: 2 additions & 0 deletions src/src/WebServer/AdvancedConfigPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ void handle_advanced() {

addFormCheckBox(F("Use NTP"), F("usentp"), Settings.UseNTP());
addFormTextBox(F("NTP Hostname"), F("ntphost"), Settings.NTPHost, 63);
#if FEATURE_EXT_RTC
addFormExtTimeSourceSelect(F("External Time Source"), F("exttimesource"), Settings.ExtTimeSource());
if (Settings.ExtTimeSource() != ExtTimeSource_e::None) {
addFormNote(concat(getLabel(LabelType::EXT_RTC_UTC_TIME), F(": ")) + getValue(LabelType::EXT_RTC_UTC_TIME));
}
#endif

addFormSubHeader(F("DST Settings"));
addFormDstSelect(true, Settings.DST_Start);
Expand Down
2 changes: 2 additions & 0 deletions src/src/WebServer/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ void handle_json()
LabelType::BUILD_TIME,
LabelType::BINARY_FILENAME,
LabelType::LOCAL_TIME,
#if FEATURE_EXT_RTC
LabelType::EXT_RTC_UTC_TIME,
#endif
LabelType::TIME_SOURCE,
LabelType::TIME_WANDER,
LabelType::ISNTP,
Expand Down
2 changes: 2 additions & 0 deletions src/src/WebServer/SysInfoPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@ void handle_sysinfo_basicInfo() {
if (node_time.systemTimePresent())
{
addRowLabelValue(LabelType::LOCAL_TIME);
#if FEATURE_EXT_RTC
if (Settings.ExtTimeSource() != ExtTimeSource_e::None) {
addRowLabelValue(LabelType::EXT_RTC_UTC_TIME);
}
#endif
addRowLabelValue(LabelType::TIME_SOURCE);
addRowLabelValue(LabelType::TIME_WANDER);
addUnit(F("ppm"));
Expand Down

0 comments on commit b6c0356

Please sign in to comment.