测试ok
This commit is contained in:
@ -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()
|
||||
|
@ -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();
|
||||
|
97
src/main.cpp
97
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user