Skip to content

Commit

Permalink
Add supports all Arduino devices except for AVR.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Aug 13, 2023
1 parent 7a88996 commit 03108c3
Show file tree
Hide file tree
Showing 366 changed files with 83,252 additions and 1,986 deletions.
73 changes: 64 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Arduino Google Sheet Client Library for ESP32, ESP8266 and Raspberry Pi Pico (RP2040)
# Arduino Google Sheet Client Library for Arduino devices


Arduino Google Sheet Client Library for ESP32, ESP8266 and Raspberry Pi Pico (RP2040).
Arduino Google Sheet Client Library for Arduino devices.


This library works with Google Sheet APIs directly using the Service Account which is safe and reliable as it does not require Google AppScrips and other dirty HTTP hacks to work.
Expand All @@ -25,11 +25,11 @@ Note: There is the way of hacking to post the data to Google Forms’s linked sp
## Dependencies


This library required **ESP8266, ESP32 and Raspberry Pi Pico Arduino Core SDK** to be installed.
This library required the Arduino platforms SDK (for ESP32, ESP8266, Pico, SAMD stm32 and Teensy) to be installed.

To install device SDK, in Arduino IDE, ESP8266, ESP32 and Pico Core SDK can be installed through **Boards Manager**.
To install device SDK, in Arduino IDE, the platform SDK can be installed through **Boards Manager**.

In PlatfoemIO IDE, ESP32 and ESP8266 devices's Core SDK can be installed through **PIO Home** > **Platforms** > **Espressif 8266 or Espressif 32**.
In PlatfoemIO IDE, the platform SDK can be installed through **PIO Home** > **Platforms** > **Espressif 8266 or Espressif 32**.


### RP2040 Arduino SDK installation
Expand Down Expand Up @@ -208,6 +208,12 @@ See [all examples](/examples) for complete usages.
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif __has_include(<WiFiNINA.h>)
#include <WiFiNINA.h>
#elif __has_include(<WiFi101.h>)
#include <WiFi101.h>
#elif __has_include(<WiFiS3.h>)
#include <WiFiS3.h>
#endif
#include <ESP_Google_Sheet_Client.h>
Expand Down Expand Up @@ -524,16 +530,27 @@ void setExternalClient(Client *client, GS_NetworkConnectionRequestCallback netwo
GS_NetworkStatusRequestCallback networkStatusCB);
```
#### Assign UDP client and gmt offset for NTP time synching when using external SSL client
param **`client`** The pointer to UDP client based on the network type.
#### Assign TinyGsm Clients.
param **`gmtOffset`** The GMT time offset.
param **`client`** The pointer to TinyGsmClient.
param **`modem`** The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data.
param **`pin`** The SIM pin.
param **`apn`** The GPRS APN (Access Point Name).
param **`user`** The GPRS user.
param **`password`** The GPRS password.
```cpp
void setUDPClient(UDP *client, float gmtOffset = 0);
void setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password);
```



#### Set the network status acknowledgement.

param **`status`** The network status.
Expand Down Expand Up @@ -640,6 +657,29 @@ retuen **`unsigned long`** of timestamp.
unsigned long getExpiredTimestamp();
```



#### Get the current timestamp.

return **`timestamp`**

```cpp
uint64_t getCurrentTimestamp();
```



#### Set system time with timestamp.

param **`ts`** timestamp in seconds from midnight Jan 1, 1970.

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

```cpp
bool setSystemTime(time_t ts);
```
#### Force the token to expire immediately and refresh.
```cpp
Expand Down Expand Up @@ -744,6 +784,21 @@ return **`Boolean`** type status indicates the success of the operation.
bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false);
```

#### Formatted printing on Serial.

```cpp
void printf(const char *format, ...);
```
#### Get free Heap memory.
return **`Free memory amount in byte`**
```cpp
int getFreeHeap();
```

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

param **`response`** (FirebaseJson or String) The returned response.
Expand Down
10 changes: 5 additions & 5 deletions examples/Ethernet/ESP32/ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void setup()
Serial.println();
Serial.println();

Serial.printf("ESP Google Sheet Client v%s\n\n", ESP_GOOGLE_SHEET_CLIENT_VERSION);
GSheet.printf("ESP Google Sheet Client v%s\n\n", ESP_GOOGLE_SHEET_CLIENT_VERSION);

#if defined(ESP32)
WiFi.onEvent(WiFiEvent);
Expand Down Expand Up @@ -228,13 +228,13 @@ void setupGsheet()

void tokenStatusCallback(TokenInfo info)
{
if (info.status == esp_signer_token_status_error)
if (info.status == token_status_error)
{
Serial.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
Serial.printf("Token error: %s\n", GSheet.getTokenError(info).c_str());
GSheet.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
GSheet.printf("Token error: %s\n", GSheet.getTokenError(info).c_str());
}
else
{
Serial.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
GSheet.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
}
}
10 changes: 5 additions & 5 deletions examples/Ethernet/ESP8266/ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void setup()
Serial.println();
Serial.println();

Serial.printf("ESP Google Sheet Client v%s\n\n", ESP_GOOGLE_SHEET_CLIENT_VERSION);
GSheet.printf("ESP Google Sheet Client v%s\n\n", ESP_GOOGLE_SHEET_CLIENT_VERSION);

#if defined(ESP8266)
SPI.begin();
Expand Down Expand Up @@ -152,13 +152,13 @@ void setupGsheet()

void tokenStatusCallback(TokenInfo info)
{
if (info.status == esp_signer_token_status_error)
if (info.status == token_status_error)
{
Serial.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
Serial.printf("Token error: %s\n", GSheet.getTokenError(info).c_str());
GSheet.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
GSheet.printf("Token error: %s\n", GSheet.getTokenError(info).c_str());
}
else
{
Serial.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
GSheet.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
}
}
36 changes: 8 additions & 28 deletions examples/Ethernet/Pico/Pico.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
*
*/

// 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.
// This example shows how to connect to Google API via ethernet using Raspberri Pi Pico and W5500 Ethernet module.

/**
*
Expand Down Expand Up @@ -39,9 +38,6 @@
#include <Arduino.h>
#include <ESP_Google_Sheet_Client.h>

// https://github.com/mobizt/ESP_SSLClient
#include <ESP_SSLClient.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
Expand Down Expand Up @@ -72,17 +68,7 @@ void tokenStatusCallback(TokenInfo info);
// The network interface devices that can be used to handle SSL data should
// have large memory buffer up to 1k - 2k or more, otherwise the SSL/TLS handshake
// will fail.
EthernetClient basic_client;

// This is the wrapper client that utilized the basic client for io and
// provides the mean for the data encryption and decryption before sending to or after read from the io.
// The most probable failures are related to the basic client itself that may not provide the buffer
// that large enough for SSL data.
// The SSL client can do nothing for this case, you should increase the basic client buffer memory.
ESP_SSLClient ssl_client;

// UDP Client for NTP Time synching
EthernetUDP udpClient;
EthernetClient eth;

void ResetEthernet()
{
Expand Down Expand Up @@ -137,12 +123,9 @@ void setup()

delay(5000);

Serial.printf("ESP Google Sheet Client v%s\n\n", ESP_GOOGLE_SHEET_CLIENT_VERSION);
GSheet.printf("ESP Google Sheet Client v%s\n\n", ESP_GOOGLE_SHEET_CLIENT_VERSION);

networkConnection();

ssl_client.setClient(&basic_client);
ssl_client.setInsecure();
}

void loop()
Expand All @@ -168,10 +151,7 @@ void setupGsheet()
GSheet.setTokenCallback(tokenStatusCallback);

/* Assign the pointer to global defined external SSL Client object and required callback functions */
GSheet.setExternalClient(&ssl_client, networkConnection, networkStatusRequestCallback);

/* Assign UDP client and gmt offset for NTP time synching when using external SSL client */
GSheet.setUDPClient(&udpClient, 3);
GSheet.setExternalClient(&eth, networkConnection, networkStatusRequestCallback);

// Set the seconds to refresh the auth token before expire (60 to 3540, default is 300 seconds)
GSheet.setPrerefreshSeconds(10 * 60);
Expand All @@ -184,13 +164,13 @@ void setupGsheet()

void tokenStatusCallback(TokenInfo info)
{
if (info.status == esp_signer_token_status_error)
if (info.status == token_status_error)
{
Serial.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
Serial.printf("Token error: %s\n", GSheet.getTokenError(info).c_str());
GSheet.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
GSheet.printf("Token error: %s\n", GSheet.getTokenError(info).c_str());
}
else
{
Serial.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
GSheet.printf("Token info: type = %s, status = %s\n", GSheet.getTokenType(info).c_str(), GSheet.getTokenStatus(info).c_str());
}
}
Loading

0 comments on commit 03108c3

Please sign in to comment.