Skip to content

Commit 89d8166

Browse files
committed
Fixed NTP time synching issue.
1 parent f495568 commit 89d8166

File tree

10 files changed

+158
-240
lines changed

10 files changed

+158
-240
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Arduino Google Sheet Client Library for ESP8266 and ESP32
22

33

4-
Arduino Google Sheet Client Library for ESP8266 and ESP32 v1.0.3.
4+
Arduino Google Sheet Client Library for ESP8266 and ESP32 v1.0.4.
55

66
This library allows devices to authenticate and communicate with Google Sheet APIs using the Service Account.
77

@@ -17,13 +17,6 @@ You can create, edit and deploy the Apps Script code via extension of spreadshee
1717
Spreadsheet created or owned by you, needed to share the access with Service Account's client email then library can read, and edit except for delete the user's spreadsheet due to permission denied.
1818

1919

20-
## Important Note
21-
22-
The connection to Google Sheet API endpoint takes time and the time from sending request to the complete response received can be as much as 3 seconds.
23-
24-
The speed is not the library or device issue unless the server issue.
25-
26-
2720
## Dependencies
2821

2922

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP-Google-Sheet-Client",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"keywords": "communication, REST, esp32, esp8266, arduino",
55
"description": "Arduino Google Sheet REST client library for ESP8266 and ESP32. This library allows devices to communicate with Google Sheet API to read, edit and delete the spreadsheets",
66
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name=ESP-Google-Sheet-Client
22

3-
version=1.0.3
3+
version=1.0.4
44

55
author=Mobizt
66

src/ESP_Google_Sheet_Client.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Google Sheet Client, ESP_Google_Sheet_Client.cpp v1.0.1
2+
* Google Sheet Client, ESP_Google_Sheet_Client.cpp v1.0.4
33
*
44
* This library supports Espressif ESP8266 and ESP32 MCUs
55
*
6-
* Created April 18, 2022
6+
* Created April 23, 2022
77
*
88
* The MIT License (MIT)
99
* Copyright (c) 2022 K. Suwatchai (Mobizt)
@@ -57,7 +57,7 @@ void GSheetClass::auth(const char *client_email, const char *project_id, const c
5757
config.service_account.data.private_key = private_key;
5858
config.signer.expiredSeconds = 3600;
5959
config.signer.preRefreshSeconds = 60;
60-
config._int.esp_signer_reconnect_wifi = WiFi.getAutoReconnect();
60+
config.internal.esp_signer_reconnect_wifi = WiFi.getAutoReconnect();
6161
config.signer.tokens.scope = (const char *)FPSTR("https://www.googleapis.com/auth/drive.metadata,https://www.googleapis.com/auth/drive.appdata,https://www.googleapis.com/auth/spreadsheets,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/drive.file");
6262
this->begin(&config);
6363
}
@@ -69,25 +69,20 @@ void GSheetClass::setTokenCallback(TokenStatusCallback callback)
6969

7070
bool GSheetClass::checkToken()
7171
{
72-
if (setClock(0))
73-
{
74-
return this->tokenReady();
75-
}
76-
77-
return false;
72+
return this->tokenReady();
7873
}
7974

8075
bool GSheetClass::setClock(float gmtOffset)
8176
{
8277

83-
if (time(nullptr) > ESP_DEFAULT_TS && gmtOffset == config._int.esp_signer_gmt_offset)
78+
if (time(nullptr) > ESP_DEFAULT_TS && gmtOffset == config.internal.esp_signer_gmt_offset)
8479
return true;
8580

8681
time_t now = time(nullptr);
8782

88-
config._int.esp_signer_clock_rdy = now > ESP_DEFAULT_TS;
83+
config.internal.esp_signer_clock_rdy = now > ESP_DEFAULT_TS;
8984

90-
if (!config._int.esp_signer_clock_rdy || gmtOffset != config._int.esp_signer_gmt_offset)
85+
if (!config.internal.esp_signer_clock_rdy || gmtOffset != config.internal.esp_signer_gmt_offset)
9186
{
9287
configTime(gmtOffset * 3600, 0, "pool.ntp.org", "time.nist.gov");
9388

@@ -102,11 +97,11 @@ bool GSheetClass::setClock(float gmtOffset)
10297
}
10398
}
10499

105-
config._int.esp_signer_clock_rdy = now > ESP_DEFAULT_TS;
106-
if (config._int.esp_signer_clock_rdy)
107-
config._int.esp_signer_gmt_offset = gmtOffset;
100+
config.internal.esp_signer_clock_rdy = now > ESP_DEFAULT_TS;
101+
if (config.internal.esp_signer_clock_rdy)
102+
config.internal.esp_signer_gmt_offset = gmtOffset;
108103

109-
return config._int.esp_signer_clock_rdy;
104+
return config.internal.esp_signer_clock_rdy;
110105
}
111106

112107
void GSheetClass::beginRequest(FirebaseJson *response, MB_String &req, host_type_t host_type)
@@ -189,30 +184,25 @@ void GSheetClass::setSecure()
189184
if (config.signer.wcs->_certType == -1 || cert_updated)
190185
{
191186

192-
if (!config._int.esp_signer_clock_rdy && (cert_addr > 0))
187+
if (!config.internal.esp_signer_clock_rdy && (cert_addr > 0))
193188
{
194189

195190
#if defined(ESP8266)
196-
int retry = 0;
197-
while (!config._int.esp_signer_clock_rdy && retry < 5)
198-
{
199191
setClock(0);
200-
retry++;
201-
}
202192
#endif
203193
}
204194

205-
config.signer.wcs->_clockReady = config._int.esp_signer_clock_rdy;
195+
config.signer.wcs->_clockReady = config.internal.esp_signer_clock_rdy;
206196

207197
if (certFile.length() > 0)
208198
{
209199

210200
#if defined(ESP8266)
211-
if (config._int.sd_config.ss == -1)
212-
config._int.sd_config.ss = SD_CS_PIN;
201+
if (config.internal.sd_config.ss == -1)
202+
config.internal.sd_config.ss = SD_CS_PIN;
213203
#endif
214204
int type = certFileStorageType == esP_google_sheet_file_storage_type_flash ? 1 : 2;
215-
config.signer.wcs->setCACertFile(certFile.c_str(), type, config._int.sd_config);
205+
config.signer.wcs->setCACertFile(certFile.c_str(), type, config.internal.sd_config);
216206
}else
217207
{
218208
if (cert_addr > 0)

src/ESP_Google_Sheet_Client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#ifndef ESP_GOOGLE_SHEET_CLIENT_VERSION
2-
#define ESP_GOOGLE_SHEET_CLIENT_VERSION "1.0.3"
2+
#define ESP_GOOGLE_SHEET_CLIENT_VERSION "1.0.4"
33
#endif
44

55
/**
6-
* Google Sheet Client, ESP_Google_Sheet_Client.h v1.0.3
6+
* Google Sheet Client, ESP_Google_Sheet_Client.h v1.0.4
77
*
88
* This library supports Espressif ESP8266 and ESP32 MCUs
99
*
10-
* Created April 20, 2022
10+
* Created April 23, 2022
1111
*
1212
* The MIT License (MIT)
1313
* Copyright (c) 2022 K. Suwatchai (Mobizt)

0 commit comments

Comments
 (0)