hello I have an application that works with esp32. When I install the application with Arduino version 2.0.8, everything works smoothly, but when I upgrade to version 2.0.10, it gives the error I see in the screenshot below. I would be very happy if someone could help me. [img][/img] Here is the code where the error parts are changing [code c++]#ifndef MTimeHPP #define MTimeHPP #include <TimeLib.h> #include <DS1307RTC.h> ///!!! порядок подключения библиотек DS1307RTC.h Wire.h не менять иначе #include <Wire.h> /// порт сыпет ошибками #include "MFunction.h" #include "MNTP.hpp" #include "MJsonLoad.hpp" #include "MJsonSave.hpp" extern "C" { #include <apps/sntp/sntp.h> } void sntp_init(); //--------------------------------------------------------------------------- class MTime { private: const int AddressPCF8563 =0x51; const int AddressDS1307 =0x68; byte isRTC; int HourLast; public: unsigned long MillisStart; public: unsigned long MillisBeginDay; private: unsigned long LastTimeNTP; int MillisResetCount = 0; /// for Uptime() int HLasSync=-100; /// for EnabledAutoSyncGadget //--------------------------------------------------------------------------- byte bcd2DEC(byte value) { return ((value / 16) * 10 + value % 16); } //--------------------------------------------------------------------------- byte DEC2bcd(byte value) { return (value / 10 * 16 + value % 10); } //--------------------------------------------------------------------------- void GetPCF8563(tmElements_t &tm) // this gets the time and date from the PCF8563 { Wire.beginTransmission(AddressPCF8563); Wire.write(0x02); Wire.endTransmission(); Wire.requestFrom(AddressPCF8563, 7); tm.Second = bcd2DEC(Wire.read() & B01111111); // remove VL error bit tm.Minute = bcd2DEC(Wire.read() & B01111111); // remove unwanted bits from MSB tm.Hour = bcd2DEC(Wire.read() & B00111111); tm.Day = bcd2DEC(Wire.read() & B00111111); tm.Wday = bcd2DEC(Wire.read() & B00000111); tm.Month = bcd2DEC(Wire.read() & B00011111); // remove century bit, 1999 is over tm.Year = bcd2DEC(Wire.read() ); } //--------------------------------------------------------------------------- void SetPCF8563(tmElements_t &tm) // this sets the time and date to the PCF8563 { Wire.beginTransmission(AddressPCF8563); Wire.write(0x02); Wire.write(DEC2bcd(tm.Second)); Wire.write(DEC2bcd(tm.Minute)); Wire.write(DEC2bcd(tm.Hour)); Wire.write(DEC2bcd(tm.Day)); Wire.write(DEC2bcd(tm.Wday)); Wire.write(DEC2bcd(tm.Month)); Wire.write(DEC2bcd(tm.Year)); Wire.endTransmission(); } //--------------------------------------------------------------------------- static void Sec2tm(unsigned long s, tmElements_t& tm) { tm.Hour = hour(s); tm.Minute = minute(s); tm.Second = second(s); tm.Day = day(s); tm.Month = month(s); tm.Year = CalendarYrToTm(year(s)); tm.Wday = weekday(s); } //--------------------------------------------------------------------------- static void AddDigits2String(int V, String &S, int length=2) { String S0 = String(V); while(S0.length()<length) S0="0"+S0; S+=S0; } //--------------------------------------------------------------------------- String tm2String(tmElements_t& tm, bool NeedAddWday=true) { String S = String(tm.Hour) + ":"; AddDigits2String(tm.Minute, S); S+=":"; AddDigits2String(tm.Second, S); S+=" "; S+= String(tmYearToCalendar(tm.Year)) + "." + String(tm.Month) + "." + String(tm.Day); if(NeedAddWday) S+= " W" + String(tm.Wday-1); return S; } //--------------------------------------------------------------------------- bool RTCCheck() { _TL isRTC = 0; Wire.beginTransmission(AddressPCF8563); if (Wire.endTransmission() == 0) { isRTC += 2; Serial.println("PCF8563 found"); } Wire.beginTransmission(AddressDS1307); if (Wire.endTransmission() == 0) { Serial.println("DS1307 found"); isRTC += 1; setSyncProvider(RTC.get); } _TFl(isRTC) if (isRTC == 0) Serial.println("RTC not found !!!"); } //--------------------------------------------------------------------------- public: bool bTimeSet; /// time was set void(*MDelay)(unsigned int); bool EnabledAutoSyncNTP; bool EnabledAutoSyncGadget; /// sync only by udp, but not http. This because http responc not regular. /// But Lic test by time, from udp and from http. int TimeZone; short AMonthDay[12]={0,31,59,90,120,151,181,212,243,273,304,334}; //--------------------------------------------------------------------------- MTime() /// here call RTCCheck(), SetTime(), SyncNTP() { _TP_ bTimeSet = false; /// after SetTimeZone(TimeZone); EnabledAutoSyncNTP = true; EnabledAutoSyncGadget = true; TimeZone=0; LastTimeNTP = 0; _TP_ SetTimeZone(TimeZone); _TP_ _TFl(bTimeSet); } //--------------------------------------------------------------------------- static String Millis2TimeStr(unsigned long ms) { int H=ms/3600000; ms-=H*3600000; int M = ms / 60000; ms -= M * 60000; int Sec = ms / 1000; ms -= Sec * 1000; String S; AddDigits2String(H, S); S += ":"; AddDigits2String(M, S); if(Sec>0 || ms>0) { S += ":"; AddDigits2String(Sec, S); if (ms>0) { S += "."; AddDigits2String(ms, S, 3); } } return S; } //--------------------------------------------------------------------------- static unsigned long TimeStr2Millis(String STime) { int ms = 0; int p = 0; int iLast = 0; for (int i = 1; i <= STime.length(); i++) { if (STime[i] == ':') { if (p == 0) ms = STime.substring(iLast, i).toInt() * 3600000; else if (p == 1) ms += +STime.substring(iLast, i).toInt() * 60000; iLast = i + 1; p++; } else if (STime[i] == '.' && p == 2) { ms += STime.substring(iLast, i).toInt() * 1000; iLast = i + 1; p++; } } if (p == 1) ms += STime.substring(iLast, STime.length()).toInt() * 60000; else if (p == 2) ms += STime.substring(iLast, STime.length()).toInt() * 1000; else if (p == 3) ms += STime.substring(iLast, STime.length()).toInt(); //_TFl(ms) return ms; } //--------------------------------------------------------------------------- void SetTime(tmElements_t &tm) { if(tm.Hour<24 && tm.Minute<60 && tm.Second<60 && tm.Day!=0 && tm.Day<32 && tm.Month!=0 && tm.Month<13) { MDelay(0); if (isRTC == 1) RTC.write(tm); else if (isRTC == 2) SetPCF8563(tm); else if (isRTC == 3) { SetPCF8563(tm); RTC.write(tm); } //else { _TFl(tm2String(tm)) setTime(tm.Hour, tm.Minute, tm.Second, tm.Day, tm.Month, tmYearToCalendar(tm.Year)); } GetTime(tm); /// tm after test MillisStart=( (tm.Hour*60 + tm.Minute)*60 + tm.Second)*1000;//=millis(); MillisBeginDay=millis(); HourLast=-1; bTimeSet=true; } } //--------------------------------------------------------------------------- void SetTimeZone(int TimeZone_) { tmElements_t tm; _TFl(LockTodo) GetTime(tm); configTime(TimeZone_ * 3600, 0, "pool.ntp.org", "time.nist.gov"); tm.Hour= tm.Hour - TimeZone + TimeZone_; bool bTimeSet_= bTimeSet; /// else at start and load from file TimeZone will be set bTimeSet=true; SetTime(tm); bTimeSet= bTimeSet_; //tm.Hour += (-TimeZone + TimeZone_); TimeZone = TimeZone_; //SetTime(tm); } //--------------------------------------------------------------------------- bool SyncNTP(bool bMust=false) { // todo: +++ here _TF_ byte i = 0; if(bMust || GetTimeDo(100)) { Serial.print("SyncNTP."); MNTP NTP(TimeZone); NTP.SendNTP(); MDelay(1000); unsigned long Sec = NTP.GetTimeSec(); for (byte i0=0; Sec == 0 && i0<5; i0++) while (Sec == 0 && i<3) { MDelay(1000); Serial.print("."); i++; Sec = NTP.GetTimeSec(); } if (Sec!= 0) { tmElements_t tm; Sec2tm(Sec, tm); SetTime(tm); _TFl(LockTodo) _TC(GetTime()+" SNTP was sync ") } else Serial.println("None"); LastTimeNTP = millis(); /// not set at only good sync, else at abset inet we will call SNTP sync very offen return bTimeSet; } return false; } //--------------------------------------------------------------------------- int GetWDay() { if (isRTC == 2) { tmElements_t tm; GetPCF8563(tm); return tm.Wday-1; } /// DS1307 or not RTC return weekday()-1;//CalcWDay(tm.Day, tm.Month, CalendarYrToTm(tm.Year)); } //--------------------------------------------------------------------------- int GetHour() /// in 24 format { if (isRTC == 2) { tmElements_t tm; GetPCF8563(tm); return tm.Hour; } /// DS1307 or not RTC return hour();//CalcWDay(tm.Day, tm.Month, CalendarYrToTm(tm.Year)); } //--------------------------------------------------------------------------- void GetTime(tmElements_t& tm) { static unsigned int _Tmsec; unsigned long ms = millis(); if (isRTC ==2) GetPCF8563(tm); else /// DS1307 or not RTC { //_TP_ tm.Hour = hour(); tm.Minute = minute(); tm.Second=second(); tm.Day = day(); tm.Month = month(); tm.Year = CalendarYrToTm(year()); tm.Wday = weekday();//CalcWDay(tm.Day, tm.Month, CalendarYrToTm(tm.Year)); //_TP_ } MDelay(0); } //--------------------------------------------------------------------------- String GetTime() { tmElements_t tm; GetTime(tm); return tm2String(tm); } //--------------------------------------------------------------------------- String GetUptime() { unsigned long ms = millis(); tmElements_t tm; unsigned long sec=millis()/1000+ MillisResetCount*4294967;//.295; String S = "D"+String(sec / (3600 * 24)) + " "; AddDigits2String((sec % (3600 * 24))/3600, S); /// hour S+=":"; AddDigits2String((sec % 3600)/60, S); /// min S += ":"; AddDigits2String(sec % 60, S); ///sec S += "; sec=" + String(sec) + "; millis()=" + String(millis()) + "; Count=" + String(MillisResetCount); // _TP_ MDelay(0); //_TP_ return S; } //--------------------------------------------------------------------------- void Setup() { //initialize_sntp(); sntp_init(); setSyncProvider(RTC.get); MillisStart = ((hour() * 60 + minute()) * 60 + second()) * 1000;//=millis(); MillisBeginDay = millis(); RTCCheck(); } //--------------------------------------------------------------------------- void LoopLowPriority() { if (EnabledAutoSyncNTP) { unsigned long T = millis() - LastTimeNTP; if (T>1000 * 3600 * 2 && T % 10000 == 0) // todo: 1->24 // _TFl(T) //if (T>10000) // todo: 1->24 //---- { _TP_ static int HLast = 0; tmElements_t tm; GetTime(tm); int H = tm.Hour; if(H != HLast) SyncNTP(); HLast=H; } } else LastTimeNTP = 0; } //--------------------------------------------------------------------------- void LoopHighPriority() { static unsigned long MillisLast = 0; if (millis() < MillisLast) MillisResetCount++; MillisLast = millis(); int H = GetHour(); if (H < HourLast) /// change day { MillisStart = 0; MillisBeginDay = MillisLast; } HourLast = H; } //--------------------------------------------------------------------------- unsigned long MillisStartDay() { return millis() - MillisBeginDay + MillisStart; } //--------------------------------------------------------------------------- void SetTimeFromJson(String sK, tmElements_t tm, bool bTimeSyncGadget) { if (sK == "SetTime") { SetTime(tm); } else if (bTimeSyncGadget) /// here from udp (time sync only by udp) { tmElements_t tmg; GetTime(tmg); if (EnabledAutoSyncGadget && abs(tmg.Hour-HLasSync)>2) /// not often then one in 3 hour { //bNeedTestLic = false; SetTime(tm); } } } //--------------------------------------------------------------------------- void SetTimeFromJsonGet(String sK_, JsonObject& JOP, bool bTimeSyncGadget) { //_TL; //_TP_ if (JOP.size() < 1) _TEr_FR(); String sK; tmElements_t tm; for (JsonObject::iterator it = JOP.begin(); it != JOP.end(); ++it) { sK = it->key; if (sK == "Y") tm.Year = CalendarYrToTm(int(it->value)); else if (sK == "Mn") tm.Month = it->value; else if (sK == "D") tm.Day = it->value; else if (sK == "WD") tm.Wday = it->value; else if (sK == "H") tm.Hour = it->value; else if (sK == "M") tm.Minute = it->value; else if (sK == "S") tm.Second = it->value; } SetTimeFromJson(sK_, tm, bTimeSyncGadget); //_TP_ } //--------------------------------------------------------------------------- void SetTimeFromJson(String sK, MJsonLoad& JL, bool bTimeSyncGadget) { tmElements_t tm; while (JL.GetNext() && JL.Key != "}") { if (JL.Value == "{") continue; String sK2(JL.Key); int V = JL.Value.toInt(); //it2->value.as<int>(); if (sK2 == "Y") tm.Year = CalendarYrToTm(V); else if (sK2 == "Mn") tm.Month = V; else if (sK2 == "D") tm.Day = V; else if (sK2 == "WD") tm.Wday = V; else if (sK2 == "H") tm.Hour = V; else if (sK2 == "M") tm.Minute = V; else if (sK2 == "S") tm.Second = V; else { _TErFl(sK2); _TErFl(JL.Value); } MDelay(0); } //_TFl(tm.Year); SetTimeFromJson(sK, tm, bTimeSyncGadget); } //--------------------------------------------------------------------------- void SetFromJSon(MJsonLoad& JL) /// set all params consisting in JO to this /// return !err { bool bNeedSetTime = false; while (JL.GetNext() && JL.Key != "}") { String sK(JL.Key); if (sK == "EnabledAutoSyncNTP") EnabledAutoSyncNTP = JL.ValueAsBool();// it->value.as<bool>(); else if (sK == "EnabledAutoSyncGadget") EnabledAutoSyncGadget = JL.ValueAsBool();// it->value.as<bool>(); else if (sK == "TimeZone") SetTimeZone(JL.Value.toInt());// it->value.as<int>()); else if (sK == "SyncNTP") { //_TP_ SyncNTP(true); } else if (sK == "SetTime")// || sK=="Time") { //_TP_ SetTimeFromJson(sK, JL, false); _TC("SetTime") } else { _TErFl(sK); _TErFl(JL.Value); } MDelay(0); } } //--------------------------------------------------------------------------- void GetToJSon(JsonObject& JOP, MJsonSave& JS, bool bAll = false, int Regime = 0) /// Regime = 0 - for save to file, 1 - save for http /// return all params consisting in JOP to JO /// return !err { //_TP_ if (!bAll && JOP.size() < 1) _TEr_FR(); String sK; int Size = 0; for (JsonObject::iterator it = JOP.begin(); bAll || it != JOP.end(); ++it) { _TP_ Size++; if (!bAll) sK = it->key; bAll = (bAll || sK == "All"); if (bAll || sK == "EnabledAutoSyncNTP") JS.Add("EnabledAutoSyncNTP", EnabledAutoSyncNTP); if (bAll || sK == "EnabledAutoSyncGadget") JS.Add("EnabledAutoSyncGadget", EnabledAutoSyncGadget); if (bAll || sK == "TimeZone") JS.Add("TimeZone", TimeZone); _TP_ if ((bAll && Regime == 1) || sK == "TimeCurrent") { JS.Add("TimeCurrent", GetTime()); } _TP_ if ((bAll && Regime == 1) || sK == "Uptime") JS.Add("Uptime", GetUptime()); if ((bAll && Regime == 1) || sK == "DS1307") { if (isRTC == 1 || isRTC == 3) JS.Add("DS1307", "Found"); else JS.Add("DS1307", "Not found"); } if ((bAll && Regime == 1) || sK == "PCF8563") { _TC("+++++++++++++++++++++++++"); _TC("+++++++++++++++++++++++++"); _TC("+++++++++++++++++++++++++"); _TC("+++++++++++++++++++++++++"); _TFl(isRTC) if (isRTC == 2 || isRTC == 3) JS.Add("PCF8563", "Found"); else JS.Add("PCF8563", "Not found"); } _TP_ if (!bAll && JS.Size == Size) { String sJOP; JOP.printTo(sJOP); _TErFl(sJOP); } MDelay(0); if (bAll) break; } _TP_ } //--------------------------------------------------------------------------- }; //MTime Time; #endif [/code]
|