Skip to content

Commit

Permalink
Fix ESP32 SPIFFS open file read issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Mar 5, 2023
1 parent fe57533 commit f570b6e
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 65 deletions.
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP-Google-Sheet-Client",
"version": "1.3.3",
"version": "1.3.4",
"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 All @@ -12,5 +12,5 @@
"email": "[email protected]"
}],
"frameworks": "arduino",
"platforms": "espressif32, espressif8266, raspberrypi"
"platforms": "espressif32, espressif8266, rp2040"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP-Google-Sheet-Client

version=1.3.3
version=1.3.4

author=Mobizt

Expand Down
12 changes: 6 additions & 6 deletions src/ESP_Google_Sheet_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google Sheet Client, GS_Google_Sheet_Client.cpp v1.3.3
* Google Sheet Client, GS_Google_Sheet_Client.cpp v1.3.4
*
* This library supports Espressif ESP8266 and ESP32 MCUs
*
* Created February 6, 2023
* Created March 5, 2023
*
* The MIT License (MIT)
* Copyright (c) 2022 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -137,7 +137,7 @@ bool GSheetClass::beginRequest(MB_String &req, host_type_t host_type)
if (client && !client->connected())
{

#if defined(ESP8266) || defined(PICO_RP2040)
#if defined(ESP8266) || defined(MB_ARDUINO_PICO)
if (host_type == host_type_sheet)
client->ethDNSWorkAround(&config.spi_ethernet_module, (const char *)FPSTR("sheets.googleapis.com"), 443);
else if (host_type == host_type_drive)
Expand Down Expand Up @@ -195,7 +195,7 @@ void GSheetClass::setCert(const char *ca)
{
cert_updated = true;
cert_addr = addr;
#if defined(ESP8266) || defined(PICO_RP2040)
#if defined(ESP8266) || defined(MB_ARDUINO_PICO)
waitClockReady();
#endif
}
Expand All @@ -210,7 +210,7 @@ void GSheetClass::setCertFile(const char *filename, esp_google_sheet_file_storag
{
cert_updated = true;

#if defined(ESP8266) || defined(PICO_RP2040)
#if defined(ESP8266) || defined(MB_ARDUINO_PICO)
waitClockReady();
#endif
}
Expand Down Expand Up @@ -244,7 +244,7 @@ bool GSheetClass::setSecure()
if (!authMan.reconnect(client))
return false;

#if (defined(ESP8266) || defined(PICO_RP2040))
#if (defined(ESP8266) || defined(MB_ARDUINO_PICO))
if (TimeHelper::getTime(&mb_ts, &mb_ts_offset) > GS_DEFAULT_TS)
{
config.internal.clock_rdy = true;
Expand Down
9 changes: 5 additions & 4 deletions src/ESP_Google_Sheet_Client.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef ESP_GOOGLE_SHEET_CLIENT_VERSION
#define ESP_GOOGLE_SHEET_CLIENT_VERSION "1.3.3"
#define ESP_GOOGLE_SHEET_CLIENT_VERSION "1.3.4"
#endif

/**
* Google Sheet Client, ESP_Google_Sheet_Client.h v1.3.3
* Google Sheet Client, ESP_Google_Sheet_Client.h v1.3.4
*
* This library supports Espressif ESP8266 and ESP32 MCUs
*
* Created February 6, 2023
* Created March 5, 2023
*
* The MIT License (MIT)
* Copyright (c) 2022 K. Suwatchai (Mobizt)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
*
*
* Permission is hereby granted, free of charge, to any person returning a copy of
Expand All @@ -32,6 +32,7 @@
*/

#include <Arduino.h>
#include "mbfs/MB_MCU.h"

#ifndef ESP_Google_Sheet_Client_H
#define ESP_Google_Sheet_Client_H
Expand Down
5 changes: 3 additions & 2 deletions src/ESP_Google_Sheet_Client_FS_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ESP_GOOGLE_SHEET_CLIENT_FS_CONFIG_H_

#include <Arduino.h>
#include "mbfs/MB_MCU.h"

/**
* To use other flash file systems
Expand All @@ -24,7 +25,7 @@
#endif
#if defined(ESP32) || defined(ESP8266)
#define DEFAULT_FLASH_FS SPIFFS
#elif defined(PICO_RP2040)
#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_NANO_RP2040_CONNECT)
#include <LittleFS.h>
#define DEFAULT_FLASH_FS LittleFS
#endif
Expand All @@ -42,7 +43,7 @@
#include <SD.h>
#define DEFAULT_SD_FS SD
#define CARD_TYPE_SD 1
#elif defined(PICO_RP2040)
#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_NANO_RP2040_CONNECT)
// Use SDFS (ESP8266SdFat) instead of SD
#include <SDFS.h>
#define DEFAULT_SD_FS SDFS
Expand Down
5 changes: 4 additions & 1 deletion src/GS_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#define GS_MIN_WIFI_RECONNECT_TIMEOUT 10 * 1000
#define GS_MAX_WIFI_RECONNECT_TIMEOUT 5 * 60 * 1000

#include <Arduino.h>
#include "mbfs/MB_MCU.h"

#if defined(ESP32) && !defined(ESP_ARDUINO_VERSION) /* ESP32 core < v2.0.x */
#include <sys/time.h>
#else
Expand Down Expand Up @@ -258,7 +261,7 @@ struct gauth_token_signer_resources_t
size_t signatureSize = 256;
#if defined(ESP32)
uint8_t *hash = nullptr;
#elif defined(ESP8266) || defined(PICO_RP2040)
#elif defined(ESP8266) || defined(MB_ARDUINO_PICO)
char *hash = nullptr;
#endif
unsigned char *signature = nullptr;
Expand Down
14 changes: 7 additions & 7 deletions src/GS_Helper.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef GS_HELPER_H
#define GS_HELPER_H

#include "ESP_Google_Sheet_Client_FS_Config.h"

#include <Arduino.h>
#include "mbfs/MB_MCU.h"
#include "ESP_Google_Sheet_Client_FS_Config.h"
#include <time.h>

#if !defined(__AVR__)
Expand All @@ -14,7 +14,7 @@
#include "GS_Const.h"
#if defined(ESP8266)
#include <Schedule.h>
#elif defined(PICO_RP2040)
#elif defined(MB_ARDUINO_PICO)
#include <WiFi.h>
#include <WiFiNTP.h>
#endif
Expand Down Expand Up @@ -69,10 +69,10 @@ namespace TimeHelper
inline time_t getTime(uint32_t *mb_ts, uint32_t *mb_ts_offset)
{
uint32_t &tm = *mb_ts;
#if defined(ENABLE_EXTERNAL_CLIENT) || defined(PICO_RP2040)
#if defined(ENABLE_EXTERNAL_CLIENT) || defined(MB_ARDUINO_PICO)
tm = *mb_ts_offset + millis() / 1000;

#if defined(PICO_RP2040)
#if defined(MB_ARDUINO_PICO)
if (tm < time(nullptr))
tm = time(nullptr);
#endif
Expand Down Expand Up @@ -157,9 +157,9 @@ namespace TimeHelper

#else

#if defined(ESP32) || defined(ESP8266) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ESP8266) || defined(MB_ARDUINO_PICO)

#if defined(PICO_RP2040)
#if defined(MB_ARDUINO_PICO)
NTP.begin("pool.ntp.org", "time.nist.gov");
NTP.waitSet();

Expand Down
7 changes: 4 additions & 3 deletions src/GS_SDHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define GS_SD_HELPER_H_

#include <Arduino.h>
#include "mbfs/MB_MCU.h"
#include "ESP_Google_Sheet_Client.h"

// If SD Card used for storage, assign SD card type and FS used in src/ESP_Google_Sheet_Client_FS_Config.h and
Expand All @@ -18,7 +19,7 @@
#define SPI_CLOCK_IN_MHz 16
#elif defined(ESP8266)
#define SPI_CS_PIN 15
#elif defined(PICO_RP2040)
#elif defined(MB_ARDUINO_PICO)
// Use SPI 1's SS (GPIO 13) port as CS for SPI
#define SPI_CS_PIN PIN_SPI1_SS
#endif
Expand All @@ -37,7 +38,7 @@ SPIClass spi;

SDFSConfig sdFSConfig(SPI_CS_PIN, SPI_HALF_SPEED);

#elif defined(PICO_RP2040)
#elif defined(MB_ARDUINO_PICO)

/** Use Pico SPI 1 for SPI
* MISO GPIO 12
Expand Down Expand Up @@ -102,7 +103,7 @@ bool SD_Card_Mounting()
return true;
}

#elif defined(PICO_RP2040)
#elif defined(MB_ARDUINO_PICO)

Serial.print("\nMounting SD Card... ");

Expand Down
14 changes: 8 additions & 6 deletions src/auth/GAuthManager.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google Sheet Client, GAuthManager v1.0.1
* Google Sheet Client, GAuthManager v1.0.2
*
* This library supports Espressif ESP8266, ESP32 and Raspberry Pi Pico MCUs.
*
* Created February 6, 2023
* Created March 5, 2023
*
* The MIT License (MIT)
* Copyright (c) 2022 K. Suwatchai (Mobizt)
Expand All @@ -30,6 +30,8 @@
#ifndef GAUTH_MANAGER_CPP
#define GAUTH_MANAGER_CPP

#include <Arduino.h>
#include "mbfs/MB_MCU.h"
#include "GAuthManager.h"

GAuthManager::GAuthManager()
Expand Down Expand Up @@ -185,7 +187,7 @@ time_t GAuthManager::getTime()
bool GAuthManager::setTime(time_t ts)
{

#if !defined(ESP_GOOGLE_SHEET_CLIENT_ENABLE_EXTERNAL_CLIENT) && (defined(ESP8266) || defined(ESP32) || defined(PICO_RP2040))
#if !defined(ESP_GOOGLE_SHEET_CLIENT_ENABLE_EXTERNAL_CLIENT) && (defined(ESP8266) || defined(ESP32) || defined(MB_ARDUINO_PICO))

if (TimeHelper::setTimestamp(ts) == 0)
{
Expand Down Expand Up @@ -428,7 +430,7 @@ void GAuthManager::tokenProcessingTask()
// flag set for valid time required
bool sslValidTime = false;

#if defined(ESP8266) || defined(PICO_RP2040)
#if defined(ESP8266) || defined(MB_ARDUINO_PICO)
// valid time required for SSL handshake using server certificate in ESP8266
if (config->cert.data != NULL || config->cert.file.length() > 0)
sslValidTime = true;
Expand Down Expand Up @@ -872,7 +874,7 @@ bool GAuthManager::createJWT()
MemoryHelper::freeBuffer(mbfs, config->signer.hash);
return false;
}
#elif defined(ESP8266) || defined(PICO_RP2040)
#elif defined(ESP8266) || defined(MB_ARDUINO_PICO)
config->signer.hash = MemoryHelper::createBuffer<char *>(mbfs, config->signer.hashSize);
br_sha256_context mc;
br_sha256_init(&mc);
Expand Down Expand Up @@ -973,7 +975,7 @@ bool GAuthManager::createJWT()

if (ret != 0)
return false;
#elif defined(ESP8266) || defined(PICO_RP2040)
#elif defined(ESP8266) || defined(MB_ARDUINO_PICO)
// RSA private key
BearSSL::PrivateKey *pk = nullptr;
Utils::idle();
Expand Down
9 changes: 5 additions & 4 deletions src/auth/GAuthManager.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google Sheet Client, GAuthManager v1.0.1
* Google Sheet Client, GAuthManager v1.0.2
*
* This library supports Espressif ESP8266, ESP32 and Raspberry Pi Pico MCUs.
*
* Created February 6, 2023
* Created March 5, 2023
*
* The MIT License (MIT)
* Copyright (c) 2022 K. Suwatchai (Mobizt)
Expand All @@ -28,7 +28,8 @@
*/
#ifndef GAUTH_MANAGER_H
#define GAUTH_MANAGER_H

#include <Arduino.h>
#include "mbfs/MB_MCU.h"
#include "client/GS_TCP_Client.h"
#include <FS.h>
#include "mbfs/MB_FS.h"
Expand Down Expand Up @@ -157,7 +158,7 @@ class GAuthManager
}
#endif

#if defined(PICO_RP2040)
#if defined(MB_ARDUINO_PICO)
#if __has_include(<WiFiMulti.h>)
#define HAS_WIFIMULTI
WiFiMulti *multi = nullptr;
Expand Down
Loading

0 comments on commit f570b6e

Please sign in to comment.