From 58e75077d646bfb240854512fc935b5372856e53 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 9 Apr 2024 10:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GSMMannager.cpp | 2 +- src/log.cpp | 2 +- src/main.cpp | 97 +++++++++++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 44 deletions(-) diff --git a/src/GSMMannager.cpp b/src/GSMMannager.cpp index cd3bd51..fc7d17f 100644 --- a/src/GSMMannager.cpp +++ b/src/GSMMannager.cpp @@ -90,7 +90,7 @@ String GSMMannger::GetDataAndTime() { { String date=String(year)+"-"+I2toS(month)+"-"+I2toS(day)+" "+I2toS(hour)+":"+I2toS(minute)+":"+I2toS(second); return date;} - return "2000-01-01 00:00:00"; + return "-1"; } void GSMMannger::loop() diff --git a/src/log.cpp b/src/log.cpp index ee1c385..8b46bcf 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -39,7 +39,7 @@ void write_log(String path,unsigned char level,String write_data) } File file; - file = SD_MMC.open(path,"a+"); + file = SD_MMC.open(path,"ab+"); file.println(write_data); file.flush(); file.close(); diff --git a/src/main.cpp b/src/main.cpp index 9aaa7d2..0bc7c3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -300,13 +300,15 @@ String get_GPS(void) gsmmanger->modem->waitResponse(5000,gpsbac); // Serial.println(gps); - - String Date = gpsbac.substring(14,28); - + write_log(log_path,10,"gpsbac is " + gpsbac); + String Date = gpsbac.substring(18,32); + write_log(log_path,10,"get gps data is " + Date); String temp = Date.substring(0,4) + "-" + Date.substring(4,6) + "-" +Date.substring(6,8) + " " + Date.substring(8,10) + ":" +Date.substring(10,12) + ":" +Date.substring(12,-1); Date = temp; - if(Date[0] = ',') + write_log(log_path,10,"gps time is" + Date); + + if(Date.indexOf(",") != -1) { return "-1"; } @@ -315,9 +317,10 @@ String get_GPS(void) write_log(log_path,10,"gpsdate:"+Date); return Date; } - - - +// String get_ti() +// { +// return gsmmanger->modem->getNetworkTime; +// } void setup() { Serial2.begin(115200); @@ -349,7 +352,7 @@ void setup() String Date = getnetData(); Serial.println("date is :"+Date); String tem = fenge(Date," ",0); - log_path = "/log/"+tem+".txt"; + log_path = "/log/"+tem+".log"; log_data = Date+"\r\nSystem starts working."; write_log(log_path,10,""); write_log(log_path,10,log_data); @@ -360,6 +363,12 @@ void setup() gsmmanger->modem->sendAT(GF("+CGPIO=1,11,1")); //点灯 gsmmanger->modem->waitResponse("OK"); + // while (1) + // { + // Serial.println(gsmmanger->GetDataAndTime()); + // delay(1000); + // } + write_log(log_path,10,"GPS Init ...."); for(int a = 0 ; a<100 ;a++) { @@ -470,49 +479,48 @@ void loop() String gpsbac; for(int i = 0 ;i < 201 ; i++) { - write_log(log_path,10,"start get_GPS()"); - Date = get_GPS(); + write_log(log_path,10,"start getnetData()"); + Date = getnetData(); + if(Date == "-1") + { + write_log(log_path,10,"start get_GPS()"); + Date = get_GPS(); + if(Date != "-1") + { + if(hassend == 0) + { + gpsbac = StationID+"#"+Date; + int lennn = gpsbac.length(); + char *temp = new char[lennn]; + memcpy(temp, gpsbac.c_str(), gpsbac.length()); + bool flagsucc = UpdateData("/weather/php/StationGPSinfo.php", temp, lennn); + + if (!flagsucc) + { + // sdcard::WriteStringToFile(nameoffile, temp, lennn); + } + else{ + Serial.println("Finish Put StationGPSinfo Data"); + } + delete[] temp; + + } + if(hassend >= 0) + { + hassend--; + } + } - if(Date == "-1") { - write_log(log_path,10,"start getnetData()"); - Date = getnetData(); } else { - if (hassend == 0) - { - gpsbac = StationID+"#"+Date; - int lennn = gpsbac.length(); - char *temp = new char[lennn]; - memcpy(temp, gpsbac.c_str(), gpsbac.length()); - bool flagsucc = UpdateData("/weather/php/StationGPSinfo.php", temp, lennn); - - if (!flagsucc) - { - // sdcard::WriteStringToFile(nameoffile, temp, lennn); - } - else{ - Serial.println("Finish Put StationGPSinfo Data"); - } - delete[] temp; - - } - if (hassend >= 0) - { - hassend--; - } - + break; } - - if(Date != "-1") break; - - if (i==200) { write_log(log_path,10," get_GPS and getnetData failed,esp_restart"); esp_restart(); } - vTaskDelay(500); } @@ -521,7 +529,7 @@ void loop() if (fenge(Date, " ", 0)!=lastdate) { lastdate=fenge(Date, " ", 0); - log_path = "/log/"+lastdate+".txt"; + log_path = "/log/"+lastdate+".log"; myslave.claeryuliang(); ProgrameUper->CheckAndUpdate(); @@ -626,3 +634,8 @@ void loop() #endif return; } + + + + +