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
6662const char PRIVATE_KEY[] PROGMEM = " -----BEGIN PRIVATE KEY-----XXXXXXXXXXXX-----END PRIVATE KEY-----\n " ;
6763
6864bool gsheetSetupReady = false ;
@@ -73,16 +69,11 @@ void setupGsheet();
7369
7470void tokenStatusCallback (TokenInfo info);
7571
76- #define ETH_CS_PIN 16 // D0
72+ #define ETH_CS_PIN 16 // D0
7773
7874ENC28J60lwIP 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
8778void 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
144135void 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, ð);
146+ #else
147+ GSheet.begin (CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY);
148+ #endif
154149
155150 gsheetSetupReady = true ;
156151}
0 commit comments