minor cleaning

This commit is contained in:
Sara Damiano
2019-07-02 11:29:42 -04:00
parent f006268969
commit 1d0e7791b0
5 changed files with 51 additions and 64 deletions

View File

@@ -708,22 +708,18 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
/* /*
* NTP server functions * NTP server functions
*/ */
boolean isValidNumber(String str) boolean isValidNumber(String str) {
{
boolean isNum = false; boolean isNum = false;
if(!(str.charAt(0) == '+' || str.charAt(0) == '-' || isDigit(str.charAt(0)))) return false; if(!(str.charAt(0) == '+' || str.charAt(0) == '-' || isDigit(str.charAt(0)))) return false;
for(byte i=1;i < str.length(); i++) for(byte i=1;i < str.length(); i++) {
{
if(!(isDigit(str.charAt(i)) || str.charAt(i) == '.')) return false; if(!(isDigit(str.charAt(i)) || str.charAt(i) == '.')) return false;
} }
return true; return true;
} }
String ShowNTPError(byte error) String ShowNTPError(byte error) {
{ switch (error) {
switch (error)
{
case 1: case 1:
return "Network time synchronization is successful"; return "Network time synchronization is successful";
case 61: case 61:
@@ -739,29 +735,22 @@ String ShowNTPError(byte error)
default: default:
return "Unknown error: " + String(error); return "Unknown error: " + String(error);
} }
} }
byte NTPServerSync(String server = "pool.ntp.org", byte TimeZone = 3) byte NTPServerSync(String server = "pool.ntp.org", byte TimeZone = 3) {
{
//Serial.println("Sync time with NTP server."); //Serial.println("Sync time with NTP server.");
sendAT(GF("+CNTPCID=1")); sendAT(GF("+CNTPCID=1"));
if (waitResponse(10000L) != 1) if (waitResponse(10000L) != 1) {
{
//Serial.println("AT command \"AT+CNTPCID=1\" executing fault.");
return -1; return -1;
} }
String CNTP = "+CNTP=" + server + "," + String(TimeZone); sendAT(GF("+CNTP="), server, ',', String(TimeZone));
sendAT(GF(CNTP)); if (waitResponse(10000L) != 1) {
if (waitResponse(10000L) != 1)
{
//Serial.println("AT command \"" + CNTP + "\" executing fault.");
return -1; return -1;
} }
sendAT(GF("+CNTP")); sendAT(GF("+CNTP"));
if (waitResponse(10000L, GF(GSM_NL "+CNTP:"))) if (waitResponse(10000L, GF(GSM_NL "+CNTP:"))) {
{
String result = stream.readStringUntil('\n'); String result = stream.readStringUntil('\n');
result.trim(); result.trim();
if (isValidNumber(result)) if (isValidNumber(result))
@@ -769,13 +758,11 @@ byte NTPServerSync(String server = "pool.ntp.org", byte TimeZone = 3)
return result.toInt(); return result.toInt();
} }
} }
else else {
{
//Serial.println("AT command \"+CNTP\" executing fault.");
return -1; return -1;
} }
return -1; return -1;
} }
float getTemperature() TINY_GSM_ATTR_NOT_AVAILABLE; float getTemperature() TINY_GSM_ATTR_NOT_AVAILABLE;