测试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);
|
String date=String(year)+"-"+I2toS(month)+"-"+I2toS(day)+" "+I2toS(hour)+":"+I2toS(minute)+":"+I2toS(second);
|
||||||
return date;}
|
return date;}
|
||||||
return "2000-01-01 00:00:00";
|
return "-1";
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMMannger::loop()
|
void GSMMannger::loop()
|
||||||
|
@ -39,7 +39,7 @@ void write_log(String path,unsigned char level,String write_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
File file;
|
File file;
|
||||||
file = SD_MMC.open(path,"a+");
|
file = SD_MMC.open(path,"ab+");
|
||||||
file.println(write_data);
|
file.println(write_data);
|
||||||
file.flush();
|
file.flush();
|
||||||
file.close();
|
file.close();
|
||||||
|
97
src/main.cpp
97
src/main.cpp
@ -300,13 +300,15 @@ String get_GPS(void)
|
|||||||
gsmmanger->modem->waitResponse(5000,gpsbac);
|
gsmmanger->modem->waitResponse(5000,gpsbac);
|
||||||
// Serial.println(gps);
|
// Serial.println(gps);
|
||||||
|
|
||||||
|
write_log(log_path,10,"gpsbac is " + gpsbac);
|
||||||
String Date = gpsbac.substring(14,28);
|
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);
|
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;
|
Date = temp;
|
||||||
|
|
||||||
if(Date[0] = ',')
|
write_log(log_path,10,"gps time is" + Date);
|
||||||
|
|
||||||
|
if(Date.indexOf(",") != -1)
|
||||||
{
|
{
|
||||||
return "-1";
|
return "-1";
|
||||||
}
|
}
|
||||||
@ -315,9 +317,10 @@ String get_GPS(void)
|
|||||||
write_log(log_path,10,"gpsdate:"+Date);
|
write_log(log_path,10,"gpsdate:"+Date);
|
||||||
return Date;
|
return Date;
|
||||||
}
|
}
|
||||||
|
// String get_ti()
|
||||||
|
// {
|
||||||
|
// return gsmmanger->modem->getNetworkTime;
|
||||||
|
// }
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial2.begin(115200);
|
Serial2.begin(115200);
|
||||||
@ -349,7 +352,7 @@ void setup()
|
|||||||
String Date = getnetData();
|
String Date = getnetData();
|
||||||
Serial.println("date is :"+Date);
|
Serial.println("date is :"+Date);
|
||||||
String tem = fenge(Date," ",0);
|
String tem = fenge(Date," ",0);
|
||||||
log_path = "/log/"+tem+".txt";
|
log_path = "/log/"+tem+".log";
|
||||||
log_data = Date+"\r\nSystem starts working.";
|
log_data = Date+"\r\nSystem starts working.";
|
||||||
write_log(log_path,10,"");
|
write_log(log_path,10,"");
|
||||||
write_log(log_path,10,log_data);
|
write_log(log_path,10,log_data);
|
||||||
@ -360,6 +363,12 @@ void setup()
|
|||||||
gsmmanger->modem->sendAT(GF("+CGPIO=1,11,1")); //点灯
|
gsmmanger->modem->sendAT(GF("+CGPIO=1,11,1")); //点灯
|
||||||
gsmmanger->modem->waitResponse("OK");
|
gsmmanger->modem->waitResponse("OK");
|
||||||
|
|
||||||
|
// while (1)
|
||||||
|
// {
|
||||||
|
// Serial.println(gsmmanger->GetDataAndTime());
|
||||||
|
// delay(1000);
|
||||||
|
// }
|
||||||
|
|
||||||
write_log(log_path,10,"GPS Init ....");
|
write_log(log_path,10,"GPS Init ....");
|
||||||
for(int a = 0 ; a<100 ;a++)
|
for(int a = 0 ; a<100 ;a++)
|
||||||
{
|
{
|
||||||
@ -470,49 +479,48 @@ void loop()
|
|||||||
String gpsbac;
|
String gpsbac;
|
||||||
for(int i = 0 ;i < 201 ; i++)
|
for(int i = 0 ;i < 201 ; i++)
|
||||||
{
|
{
|
||||||
write_log(log_path,10,"start get_GPS()");
|
write_log(log_path,10,"start getnetData()");
|
||||||
Date = get_GPS();
|
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
|
else
|
||||||
{
|
{
|
||||||
if (hassend == 0)
|
break;
|
||||||
{
|
|
||||||
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") break;
|
|
||||||
|
|
||||||
|
|
||||||
if (i==200)
|
if (i==200)
|
||||||
{
|
{
|
||||||
write_log(log_path,10," get_GPS and getnetData failed,esp_restart");
|
write_log(log_path,10," get_GPS and getnetData failed,esp_restart");
|
||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelay(500);
|
vTaskDelay(500);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -521,7 +529,7 @@ void loop()
|
|||||||
if (fenge(Date, " ", 0)!=lastdate)
|
if (fenge(Date, " ", 0)!=lastdate)
|
||||||
{
|
{
|
||||||
lastdate=fenge(Date, " ", 0);
|
lastdate=fenge(Date, " ", 0);
|
||||||
log_path = "/log/"+lastdate+".txt";
|
log_path = "/log/"+lastdate+".log";
|
||||||
myslave.claeryuliang();
|
myslave.claeryuliang();
|
||||||
ProgrameUper->CheckAndUpdate();
|
ProgrameUper->CheckAndUpdate();
|
||||||
|
|
||||||
@ -626,3 +634,8 @@ void loop()
|
|||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user