Skip to content

Commit 1de85f1

Browse files
committed
Fix tokens generation and WiFi reconnection issues.
1 parent e9703e5 commit 1de85f1

File tree

24 files changed

+291
-137
lines changed

24 files changed

+291
-137
lines changed

README.md

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ See [all examples](/examples) for complete usages.
199199
```cpp
200200
201201
#include <Arduino.h>
202-
#if defined(ESP32) || defined(PICO_RP2040)
202+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
203203
#include <WiFi.h>
204204
#elif defined(ESP8266)
205205
#include <ESP8266WiFi.h>
@@ -648,24 +648,82 @@ void refreshToken();
648648
void reset();
649649
```
650650

651+
#### Initiate SD card with SPI port configuration.
651652

652-
#### SD card config with GPIO pins.
653+
param **`ss`** The SPI Chip/Slave Select pin.
654+
655+
param **`sck`** The SPI Clock pin.
656+
657+
param **`miso`** The SPI MISO pin.
658+
659+
param **`mosi`** The SPI MOSI pin.
660+
661+
aram **`frequency`** The SPI frequency.
662+
663+
return **`boolean`** The boolean value indicates the success of operation.
664+
665+
```cpp
666+
bool sdBegin(int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, uint32_t frequency = 4000000);
667+
```
668+
669+
670+
#### Initiate SD card with SD FS configurations (ESP8266 only).
653671
654672
param **`ss`** SPI Chip/Slave Select pin.
655673
656-
param **`sck`** SPI Clock pin.
674+
param **`sdFSConfig`** The pointer to SDFSConfig object (ESP8266 only).
657675
658-
param **`miso`** SPI MISO pin.
676+
return **`boolean`** type status indicates the success of the operation.
659677
660-
param **`mosi`** SPI MOSI pin.
678+
```cpp
679+
bool sdBegin(SDFSConfig *sdFSConfig);
680+
```
661681

662-
return **`Boolean`** type status indicates the success of the operation.
682+
683+
#### Initiate SD card with chip select and SPI configuration (ESP32 only).
684+
685+
param **`ss`** The SPI Chip/Slave Select pin.
686+
687+
param **`spiConfig`** The pointer to SPIClass object for SPI configuartion.
688+
689+
param **`frequency`** The SPI frequency.
690+
691+
return **`boolean`** The boolean value indicates the success of operation.
663692

664693
```cpp
665-
bool sdBegin( int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1);
694+
bool sdBegin(int8_t ss, SPIClass *spiConfig = nullptr, uint32_t frequency = 4000000);
666695
```
667696
668697
698+
#### Initiate SD card with SdFat SPI and pins configurations (with SdFat included only).
699+
700+
param **`sdFatSPIConfig`** The pointer to SdSpiConfig object for SdFat SPI configuration.
701+
702+
param **`ss`** The SPI Chip/Slave Select pin.
703+
704+
param **`sck`** The SPI Clock pin.
705+
706+
param **`miso`** The SPI MISO pin.
707+
708+
param **`mosi`** The SPI MOSI pin.
709+
710+
return **`boolean`** The boolean value indicates the success of operation.
711+
712+
```cpp
713+
bool sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1);
714+
```
715+
716+
717+
#### Initiate SD card with SdFat SDIO configuration (with SdFat included only).
718+
719+
param **`sdFatSDIOConfig`** The pointer to SdioConfig object for SdFat SDIO configuration.
720+
721+
return **`boolean`** The boolean value indicates the success of operation.
722+
723+
```cpp
724+
bool sdBegin(SdioConfig *sdFatSDIOConfig);
725+
```
726+
669727
670728
#### Initialize the SD_MMC card (ESP32 only).
671729
@@ -678,10 +736,9 @@ param **`format_if_mount_failed`** Format SD_MMC card if mount failed.
678736
return **`Boolean`** type status indicates the success of the operation.
679737
680738
```cpp
681-
bool sdMMCBegin(<string> mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false);
739+
bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false);
682740
```
683741

684-
685742
#### Applies one or more updates to the spreadsheet.
686743

687744
param **`response`** (FirebaseJson or String) The returned response.

examples/Ethernet/ESP8266/ESP8266.ino

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,64 @@
11

22
/**
33
* Created by K. Suwatchai (Mobizt)
4-
*
4+
*
55
* Email: k_suwatchai@hotmail.com
6-
*
6+
*
77
* Github: https://github.com/mobizt
8-
*
8+
*
99
* Copyright (c) 2023 mobizt
1010
*
11-
*/
11+
*/
1212

13-
//This example shows how to connect to Google API via ethernet.
13+
// This example shows how to connect to Google API via ethernet.
1414

15-
//This example is for ESP8266 and ENC28J60 Ethernet module.
15+
// This example is for ESP8266 and ENC28J60 Ethernet module.
1616

1717
/**
18-
*
18+
*
1919
* The ENC28J60 Ethernet module and ESP8266 board, SPI port wiring connection.
20-
*
21-
* ESP8266 (Wemos D1 Mini or NodeMCU) ENC28J60
22-
*
20+
*
21+
* ESP8266 (Wemos D1 Mini or NodeMCU) ENC28J60
22+
*
2323
* GPIO12 (D6) - MISO SO
2424
* GPIO13 (D7) - MOSI SI
2525
* GPIO14 (D5) - SCK SCK
2626
* GPIO16 (D0) - CS CS
2727
* GND GND
2828
* 3V3 VCC
29-
*
30-
*/
29+
*
30+
*/
3131

3232
/**
3333
* Do not forget to defines the following macros in ESP_Google_Sheet_Client_FS_Config.h
34-
*
35-
* #define ESP_GOOGLE_SHEET_CLIENT_ENABLE_EXTERNAL_CLIENT
36-
*
34+
*
3735
* For ESP8266 ENC28J60 Ethernet module
3836
* #define ENABLE_ESP8266_ENC28J60_ETH
39-
*
37+
*
4038
* For ESP8266 W5100 Ethernet module
4139
* #define ENABLE_ESP8266_W5100_ETH
42-
*
40+
*
4341
* For ESP8266 W5500 Ethernet module
4442
* #define ENABLE_ESP8266_W5500_ETH
45-
*
43+
*
4644
*/
4745

48-
4946
#include <Arduino.h>
5047
#if defined(ESP8266)
5148
#include <ENC28J60lwIP.h>
52-
//#include <W5100lwIP.h>
53-
//#include <W5500lwIP.h>
49+
// #include <W5100lwIP.h>
50+
// #include <W5500lwIP.h>
5451
#endif
5552
#include <ESP_Google_Sheet_Client.h>
56-
#include <Ethernet.h>
5753

58-
//For how to create Service Account and how to use the library, go to https://github.com/mobizt/ESP-Google-Sheet-Client
54+
// For how to create Service Account and how to use the library, go to https://github.com/mobizt/ESP-Google-Sheet-Client
5955

6056
#define PROJECT_ID "PROJECT_ID"
6157

62-
//Service Account's client email
58+
// Service Account's client email
6359
#define CLIENT_EMAIL "CLIENT_EMAIL"
6460

65-
//Service Account's private key
61+
// Service Account's private key
6662
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----XXXXXXXXXXXX-----END PRIVATE KEY-----\n";
6763

6864
bool gsheetSetupReady = false;
@@ -73,16 +69,11 @@ void setupGsheet();
7369

7470
void tokenStatusCallback(TokenInfo info);
7571

76-
#define ETH_CS_PIN 16 //D0
72+
#define ETH_CS_PIN 16 // D0
7773

7874
ENC28J60lwIP eth(ETH_CS_PIN);
79-
//Wiznet5100lwIP eth(ETH_CS_PIN);
80-
//Wiznet5500lwIP eth(ETH_CS_PIN);
81-
82-
83-
// UDP Client for NTP Time synching
84-
EthernetUDP udpClient;
85-
75+
// Wiznet5100lwIP eth(ETH_CS_PIN);
76+
// Wiznet5500lwIP eth(ETH_CS_PIN);
8677

8778
void setup()
8879
{
@@ -134,7 +125,7 @@ void loop()
134125
if (ready && !taskComplete)
135126
{
136127

137-
//Google sheet code here
128+
// Google sheet code here
138129

139130
taskComplete = true;
140131
}
@@ -143,14 +134,18 @@ void loop()
143134

144135
void setupGsheet()
145136
{
146-
//Set the callback for Google API access token generation status (for debug only)
137+
// Set the callback for Google API access token generation status (for debug only)
147138
GSheet.setTokenCallback(tokenStatusCallback);
148139

149140
// Set the seconds to refresh the auth token before expire (60 to 3540, default is 300 seconds)
150141
GSheet.setPrerefreshSeconds(10 * 60);
151142

152-
//Begin the access token generation for Google API authentication
143+
// Begin the access token generation for Google API authentication
144+
#if defined(ENABLE_ESP8266_ENC28J60_ETH) || defined(ENABLE_ESP8266_W5100_ETH) || defined(ENABLE_ESP8266_W5500_ETH)
153145
GSheet.begin(CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY, &eth);
146+
#else
147+
GSheet.begin(CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY);
148+
#endif
154149

155150
gsheetSetupReady = true;
156151
}

examples/Ethernet/Pico/Pico.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
// This example shows how to connect to Google API via ethernet using external SSL client
1414
// This example is for Raspberri Pi Pico and W5500 Ethernet module.
1515

16-
// Plese don't forget to assign macro ESP_GOOGLE_SHEET_CLIENT_ENABLE_EXTERNAL_CLIENT
17-
// in ESP_Google_Sheet_Client_FS_Config.h
18-
1916
/**
2017
*
2118
* The W5500 Ethernet module and RPI2040 Pico board, SPI 0 port wiring connection.

examples/ServiceAccountFile/ServiceAccountFile.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/** This example will show how to authenticate using the Service Account file. */
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

examples/Sheets/CopyTo/CopyTo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// This example shows how to copy sheet of spreadsheet to another spreadsheet.
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

examples/Spreadsheets/Create/Create.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// This example shows how to create the spreadsheet.
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

examples/Spreadsheets/Delete/Delete.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// This example shows how to delete spreadsheet from Google Drive.
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

examples/Spreadsheets/Get/Get.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// This example shows how to get the spreadsheet.
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

examples/Spreadsheets/List/List.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// This example shows how to list spreadsheet in Google Drive.
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

examples/Values/Append/Append.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// This example shows how to append new values to spreadsheet.
1414

1515
#include <Arduino.h>
16-
#if defined(ESP32) || defined(PICO_RP2040)
16+
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
1717
#include <WiFi.h>
1818
#elif defined(ESP8266)
1919
#include <ESP8266WiFi.h>

0 commit comments

Comments
 (0)