Skip to content

Commit

Permalink
Fix tokens generation and WiFi reconnection issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Feb 7, 2023
1 parent e9703e5 commit 1de85f1
Show file tree
Hide file tree
Showing 24 changed files with 291 additions and 137 deletions.
75 changes: 66 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ See [all examples](/examples) for complete usages.
```cpp
#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down Expand Up @@ -648,24 +648,82 @@ void refreshToken();
void reset();
```

#### Initiate SD card with SPI port configuration.

#### SD card config with GPIO pins.
param **`ss`** The SPI Chip/Slave Select pin.

param **`sck`** The SPI Clock pin.

param **`miso`** The SPI MISO pin.

param **`mosi`** The SPI MOSI pin.

aram **`frequency`** The SPI frequency.

return **`boolean`** The boolean value indicates the success of operation.

```cpp
bool sdBegin(int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, uint32_t frequency = 4000000);
```
#### Initiate SD card with SD FS configurations (ESP8266 only).
param **`ss`** SPI Chip/Slave Select pin.
param **`sck`** SPI Clock pin.
param **`sdFSConfig`** The pointer to SDFSConfig object (ESP8266 only).
param **`miso`** SPI MISO pin.
return **`boolean`** type status indicates the success of the operation.
param **`mosi`** SPI MOSI pin.
```cpp
bool sdBegin(SDFSConfig *sdFSConfig);
```

return **`Boolean`** type status indicates the success of the operation.

#### Initiate SD card with chip select and SPI configuration (ESP32 only).

param **`ss`** The SPI Chip/Slave Select pin.

param **`spiConfig`** The pointer to SPIClass object for SPI configuartion.

param **`frequency`** The SPI frequency.

return **`boolean`** The boolean value indicates the success of operation.

```cpp
bool sdBegin( int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1);
bool sdBegin(int8_t ss, SPIClass *spiConfig = nullptr, uint32_t frequency = 4000000);
```
#### Initiate SD card with SdFat SPI and pins configurations (with SdFat included only).
param **`sdFatSPIConfig`** The pointer to SdSpiConfig object for SdFat SPI configuration.
param **`ss`** The SPI Chip/Slave Select pin.
param **`sck`** The SPI Clock pin.
param **`miso`** The SPI MISO pin.
param **`mosi`** The SPI MOSI pin.
return **`boolean`** The boolean value indicates the success of operation.
```cpp
bool sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1);
```


#### Initiate SD card with SdFat SDIO configuration (with SdFat included only).

param **`sdFatSDIOConfig`** The pointer to SdioConfig object for SdFat SDIO configuration.

return **`boolean`** The boolean value indicates the success of operation.

```cpp
bool sdBegin(SdioConfig *sdFatSDIOConfig);
```
#### Initialize the SD_MMC card (ESP32 only).
Expand All @@ -678,10 +736,9 @@ param **`format_if_mount_failed`** Format SD_MMC card if mount failed.
return **`Boolean`** type status indicates the success of the operation.
```cpp
bool sdMMCBegin(<string> mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false);
bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false);
```


#### Applies one or more updates to the spreadsheet.

param **`response`** (FirebaseJson or String) The returned response.
Expand Down
67 changes: 31 additions & 36 deletions examples/Ethernet/ESP8266/ESP8266.ino
Original file line number Diff line number Diff line change
@@ -1,68 +1,64 @@

/**
* Created by K. Suwatchai (Mobizt)
*
*
* Email: [email protected]
*
*
* Github: https://github.com/mobizt
*
*
* Copyright (c) 2023 mobizt
*
*/
*/

//This example shows how to connect to Google API via ethernet.
// This example shows how to connect to Google API via ethernet.

//This example is for ESP8266 and ENC28J60 Ethernet module.
// This example is for ESP8266 and ENC28J60 Ethernet module.

/**
*
*
* The ENC28J60 Ethernet module and ESP8266 board, SPI port wiring connection.
*
* ESP8266 (Wemos D1 Mini or NodeMCU) ENC28J60
*
*
* ESP8266 (Wemos D1 Mini or NodeMCU) ENC28J60
*
* GPIO12 (D6) - MISO SO
* GPIO13 (D7) - MOSI SI
* GPIO14 (D5) - SCK SCK
* GPIO16 (D0) - CS CS
* GND GND
* 3V3 VCC
*
*/
*
*/

/**
* Do not forget to defines the following macros in ESP_Google_Sheet_Client_FS_Config.h
*
* #define ESP_GOOGLE_SHEET_CLIENT_ENABLE_EXTERNAL_CLIENT
*
*
* For ESP8266 ENC28J60 Ethernet module
* #define ENABLE_ESP8266_ENC28J60_ETH
*
*
* For ESP8266 W5100 Ethernet module
* #define ENABLE_ESP8266_W5100_ETH
*
*
* For ESP8266 W5500 Ethernet module
* #define ENABLE_ESP8266_W5500_ETH
*
*
*/


#include <Arduino.h>
#if defined(ESP8266)
#include <ENC28J60lwIP.h>
//#include <W5100lwIP.h>
//#include <W5500lwIP.h>
// #include <W5100lwIP.h>
// #include <W5500lwIP.h>
#endif
#include <ESP_Google_Sheet_Client.h>
#include <Ethernet.h>

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

#define PROJECT_ID "PROJECT_ID"

//Service Account's client email
// Service Account's client email
#define CLIENT_EMAIL "CLIENT_EMAIL"

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

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

void tokenStatusCallback(TokenInfo info);

#define ETH_CS_PIN 16 //D0
#define ETH_CS_PIN 16 // D0

ENC28J60lwIP eth(ETH_CS_PIN);
//Wiznet5100lwIP eth(ETH_CS_PIN);
//Wiznet5500lwIP eth(ETH_CS_PIN);


// UDP Client for NTP Time synching
EthernetUDP udpClient;

// Wiznet5100lwIP eth(ETH_CS_PIN);
// Wiznet5500lwIP eth(ETH_CS_PIN);

void setup()
{
Expand Down Expand Up @@ -134,7 +125,7 @@ void loop()
if (ready && !taskComplete)
{

//Google sheet code here
// Google sheet code here

taskComplete = true;
}
Expand All @@ -143,14 +134,18 @@ void loop()

void setupGsheet()
{
//Set the callback for Google API access token generation status (for debug only)
// Set the callback for Google API access token generation status (for debug only)
GSheet.setTokenCallback(tokenStatusCallback);

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

//Begin the access token generation for Google API authentication
// Begin the access token generation for Google API authentication
#if defined(ENABLE_ESP8266_ENC28J60_ETH) || defined(ENABLE_ESP8266_W5100_ETH) || defined(ENABLE_ESP8266_W5500_ETH)
GSheet.begin(CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY, &eth);
#else
GSheet.begin(CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY);
#endif

gsheetSetupReady = true;
}
Expand Down
3 changes: 0 additions & 3 deletions examples/Ethernet/Pico/Pico.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
// This example shows how to connect to Google API via ethernet using external SSL client
// This example is for Raspberri Pi Pico and W5500 Ethernet module.

// Plese don't forget to assign macro ESP_GOOGLE_SHEET_CLIENT_ENABLE_EXTERNAL_CLIENT
// in ESP_Google_Sheet_Client_FS_Config.h

/**
*
* The W5500 Ethernet module and RPI2040 Pico board, SPI 0 port wiring connection.
Expand Down
2 changes: 1 addition & 1 deletion examples/ServiceAccountFile/ServiceAccountFile.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/** This example will show how to authenticate using the Service Account file. */

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Sheets/CopyTo/CopyTo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to copy sheet of spreadsheet to another spreadsheet.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Spreadsheets/Create/Create.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to create the spreadsheet.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Spreadsheets/Delete/Delete.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to delete spreadsheet from Google Drive.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Spreadsheets/Get/Get.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to get the spreadsheet.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Spreadsheets/List/List.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to list spreadsheet in Google Drive.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Values/Append/Append.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to append new values to spreadsheet.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Values/Clear/Clear.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to clear the spreadsheet's values.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Values/Create_Update_Read/Create_Update_Read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to create the spreadsheet, update and read the values.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Values/Read/Read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to read the spreadsheet's values from ranges.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/Values/Update/Update.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This example shows how to update the spreadsheet's values.

#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP-Google-Sheet-Client",
"version": "1.3.2",
"version": "1.3.3",
"keywords": "communication, REST, esp32, esp8266, raspberrypi, arduino",
"description": "Arduino Google Sheet REST client library for ESP8266, ESP32 and Raspberry Pi Pico (RP2040). This library allows devices to communicate with Google Sheet API to read, edit and delete the spreadsheets",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP-Google-Sheet-Client

version=1.3.2
version=1.3.3

author=Mobizt

Expand All @@ -14,4 +14,4 @@ category=Communication

url=https://github.com/mobizt/ESP-Google-Sheet-Client

architectures=esp8266,esp32,mbed_rp2040
architectures=esp8266,esp32,mbed_rp2040,rp2040
Loading

0 comments on commit 1de85f1

Please sign in to comment.