Skip to content

Commit

Permalink
Fix last error initialization (issue #103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jun 25, 2024
1 parent 5651387 commit 89f11b1
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mobizt/FirebaseClient/.github%2Fworkflows%2Fcompile_library.yml?logo=github&label=compile) [![Github Stars](https://img.shields.io/github/stars/mobizt/FirebaseClient?logo=github)](https://github.com/mobizt/FirebaseClient/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/FirebaseClient?logo=github)

![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.2.14-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient)
![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.2.15-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient)

[![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt)

Revision `2024-06-22T08:24:11Z`
Revision `2024-06-25T01:54:21Z`

## Table of Contents

Expand Down Expand Up @@ -507,7 +507,7 @@ In case using ESP8266 without `PSRAM` and you want to reduce the memory usage, y
Note that, because the receive buffer size was set to minimum safe value, 1024, the large server response may not be able to handle.

> [!WARNING]
> When using `WiFiClient` with `ESP_SSLClient` classes in ESP32, the `TCP receive time out` error can be occurred as found in the old Firebase library because of ESP32's `WiFiClient` issue. Then using `WiFiClient` with `ESP_SSLClient` in ESP32 is your own risk.
> In ESP32, `WiFiClient` and `WiFiClientSecure` classes are unable to detect the server disconnection in case server session time out and the TCP session was kept alive for reuse in most tasks this library. The server session timed out will not happen if data was sent or received within the server time out period. User have to close the session manually by calling `WiFiClient::stop()` or `WiFiClientSecure::stop()` when no data was sent/received within 2-3 minutes before starting the new HTTP request.

- ### Async Client
Expand Down
1 change: 1 addition & 0 deletions examples/RealtimeDatabase/Async/Callback/Stream/Stream.ino
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void printResult(AsyncResult &aResult)
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();

}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void loop()

Database.set<object_t>(aClient3, "/test/stream/path1/number", json, asyncCB, "setTask1");

Database.set<object_t>(aClient3, "/test/stream/path2/number", random(100000, 200000), asyncCB, "setTask2");
Database.set<int>(aClient3, "/test/stream/path2/number", random(100000, 200000), asyncCB, "setTask2");
}
}

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": "FirebaseClient",
"version": "1.2.14",
"version": "1.2.15",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "Async Firebase Client library for Arduino.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=FirebaseClient

version=1.2.14
version=1.2.15

author=Mobizt

Expand Down
8 changes: 6 additions & 2 deletions src/cloud_storage/CloudStorage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -62,6 +62,7 @@ class CloudStorage
this->app_addr = 0;
this->app_token = nullptr;
this->avec_addr = 0; // AsyncClient vector (list) address
this->app_ota_status_addr = 0;
}

/**
Expand Down Expand Up @@ -400,6 +401,7 @@ class CloudStorage
String uid;
// FirebaseApp address and FirebaseApp vector address
uint32_t app_addr = 0, avec_addr = 0;
uint32_t app_ota_status_addr = 0;
app_token_t *app_token = nullptr;
Memory mem;

Expand All @@ -408,11 +410,12 @@ class CloudStorage
this->service_url = url;
}

void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr)
void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr, uint32_t app_ota_status_addr)
{
this->app_addr = app_addr;
this->app_token = app_token;
this->avec_addr = avec_addr; // AsyncClient vector (list) address
this->app_ota_status_addr = app_ota_status_addr;
}

app_token_t *appToken()
Expand Down Expand Up @@ -543,6 +546,7 @@ class CloudStorage
sData->request.ota = true;
sData->request.base64 = false;
sData->aResult.download_data.ota = true;
sData->request.app_ota_status_addr = app_ota_status_addr;
}

if (request.file && sData->upload)
Expand Down
4 changes: 2 additions & 2 deletions src/core/AppBase.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -95,7 +95,7 @@ class AppBase
}

template <typename T>
void setAppBase(T &app, uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr) { app.setApp(app_addr, app_token, avec_addr); }
void setAppBase(T &app, uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr, uint32_t app_ota_status_addr) { app.setApp(app_addr, app_token, avec_addr, app_ota_status_addr); }
};

#endif
21 changes: 20 additions & 1 deletion src/core/AsyncClient/AsyncClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* For MCU build target (CORE_ARDUINO_XXXX), see Options.h.
*
Expand Down Expand Up @@ -605,6 +605,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
if (ret != function_return_type_complete)
return ret;

// HTTP error is allowed in case non-auth task to get its response.
if (!readResponse(sData))
{
// In case HTTP or TCP read error.
Expand Down Expand Up @@ -788,7 +789,10 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

// Required for sync task.
if (!sData->async)
{
sData->aResult.lastError.isError();
lastErr.isError();
}
}
else if (sData && sData->response.httpCode > 0 && sData->response.httpCode >= FIREBASE_ERROR_HTTP_CODE_BAD_REQUEST)
{
Expand All @@ -798,7 +802,10 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

// Required for sync task.
if (!sData->async)
{
sData->aResult.lastError.isError();
lastErr.isError();
}
}
}

Expand Down Expand Up @@ -2120,6 +2127,12 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
if (sData->sse && !sse)
return;

if (!sData->auth_used && sData->request.ota && sData->request.app_ota_status_addr > 0)
{
bool *ota_task_running = reinterpret_cast<bool *>(sData->request.app_ota_status_addr);
*ota_task_running = false;
}

#if defined(ENABLE_DATABASE)
clearSSE(&sData->aResult.rtdbResult);
#endif
Expand Down Expand Up @@ -2159,6 +2172,12 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
updateEvent(app_event);
sData->aResult.updateData();

if (!sData->auth_used && sData->request.ota && sData->request.app_ota_status_addr > 0)
{
bool *ota_task_running = reinterpret_cast<bool *>(sData->request.app_ota_status_addr);
*ota_task_running = true;
}

if (networkConnect(sData) == function_return_type_failure)
{
// In case TCP (network) disconnected error.
Expand Down
3 changes: 2 additions & 1 deletion src/core/AsyncClient/RequestHandler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -96,6 +96,7 @@ struct async_request_handler_t
file_config_data file_data;
bool base64 = false;
bool ota = false;
uint32_t app_ota_status_addr = 0;
uint32_t payloadLen = 0;
uint32_t dataLen = 0;
uint32_t payloadIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#undef FIREBASE_CLIENT_VERSION
#endif

#define FIREBASE_CLIENT_VERSION "1.2.14"
#define FIREBASE_CLIENT_VERSION "1.2.15"

static void sys_idle()
{
Expand Down
9 changes: 7 additions & 2 deletions src/core/FirebaseApp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -68,6 +68,7 @@ namespace firebase
Timer req_timer, auth_timer, err_timer, app_ready_timer;
bool deinit = false;
bool processing = false;
bool ota_task_running = false;
uint32_t expire = FIREBASE_DEFAULT_TOKEN_TTL;
JSONUtil json;
String extras, subdomain, host;
Expand Down Expand Up @@ -367,6 +368,10 @@ namespace firebase
if (!getClient())
return false;

// Prevent authentication task from running when OTA update is running.
if (ota_task_running)
return true;

// Deinitialize
if (deinit && auth_data.user_auth.status._event == auth_event_uninitialized)
{
Expand Down Expand Up @@ -733,7 +738,7 @@ namespace firebase
* @param app The Firebase services calss object e.g. RealtimeDatabase, Storage, Messaging, CloudStorage and CloudFunctions.
*/
template <typename T>
void getApp(T &app) { setAppBase(app, app_addr, &auth_data.app_token, reinterpret_cast<uint32_t>(&aVec)); }
void getApp(T &app) { setAppBase(app, app_addr, &auth_data.app_token, reinterpret_cast<uint32_t>(&aVec), reinterpret_cast<uint32_t>(&ota_task_running)); }

/**
* Get the auth token.
Expand Down
8 changes: 6 additions & 2 deletions src/database/RealtimeDatabase.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -81,6 +81,7 @@ class RealtimeDatabase : public RTDBResultBase
this->app_addr = 0;
this->app_token = nullptr;
this->avec_addr = 0; // AsyncClient vector (list) address
this->app_ota_status_addr = 0;
}

/**
Expand Down Expand Up @@ -903,6 +904,7 @@ class RealtimeDatabase : public RTDBResultBase

// FirebaseApp address and FirebaseApp vector address
uint32_t app_addr = 0, avec_addr = 0;
uint32_t app_ota_status_addr = 0;
app_token_t *app_token = nullptr;

struct async_request_data_t
Expand Down Expand Up @@ -932,11 +934,12 @@ class RealtimeDatabase : public RTDBResultBase
}
};

void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr)
void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr, uint32_t app_ota_status_addr)
{
this->app_addr = app_addr;
this->app_token = app_token;
this->avec_addr = avec_addr; // AsyncClient vector (list) address
this->app_ota_status_addr = app_ota_status_addr;
}

app_token_t *appToken()
Expand Down Expand Up @@ -996,6 +999,7 @@ class RealtimeDatabase : public RTDBResultBase
sData->request.ota = true;
sData->request.base64 = true;
sData->aResult.download_data.ota = true;
sData->request.app_ota_status_addr = app_ota_status_addr;
}

if (request.file && sData->upload)
Expand Down
7 changes: 5 additions & 2 deletions src/firestore/FirestoreBase.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -64,6 +64,7 @@ class FirestoreBase : public AppBase
this->app_addr = 0;
this->app_token = nullptr;
this->avec_addr = 0; // AsyncClient vector (list) address
this->app_ota_status_addr = 0;
}

/**
Expand All @@ -89,6 +90,7 @@ class FirestoreBase : public AppBase
String uid;
// FirebaseApp address and FirebaseApp vector address
uint32_t app_addr = 0, avec_addr = 0;
uint32_t app_ota_status_addr = 0;
app_token_t *app_token = nullptr;

struct async_request_data_t
Expand Down Expand Up @@ -121,11 +123,12 @@ class FirestoreBase : public AppBase
this->service_url = url;
}

void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr)
void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr, uint32_t app_ota_status_addr)
{
this->app_addr = app_addr;
this->app_token = app_token;
this->avec_addr = avec_addr; // AsyncClient vector (list) address
this->app_ota_status_addr = app_ota_status_addr;
}

app_token_t *appToken()
Expand Down
8 changes: 6 additions & 2 deletions src/functions/Functions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -62,6 +62,7 @@ class CloudFunctions
this->app_addr = 0;
this->app_token = nullptr;
this->avec_addr = 0; // AsyncClient vector (list) address
this->app_ota_status_addr = 0;
}

/**
Expand Down Expand Up @@ -781,18 +782,21 @@ class CloudFunctions
String uid;
// FirebaseApp address and FirebaseApp vector address
uint32_t app_addr = 0, avec_addr = 0;
// Not used but required.
uint32_t app_ota_status_addr = 0;
app_token_t *app_token = nullptr;

void url(const String &url)
{
this->service_url = url;
}

void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr)
void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr, uint32_t app_ota_status_addr)
{
this->app_addr = app_addr;
this->app_token = app_token;
this->avec_addr = avec_addr; // AsyncClient vector (list) address
this->app_ota_status_addr = app_ota_status_addr;
}

app_token_t *appToken()
Expand Down
8 changes: 6 additions & 2 deletions src/messaging/Messaging.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created June 12, 2024
* Created June 25, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -63,6 +63,7 @@ class Messaging
this->app_addr = 0;
this->app_token = nullptr;
this->avec_addr = 0; // AsyncClient vector (list) address
this->app_ota_status_addr = 0;
}

/**
Expand Down Expand Up @@ -141,18 +142,21 @@ class Messaging
String uid;
// FirebaseApp address and FirebaseApp vector address
uint32_t app_addr = 0, avec_addr = 0;
// Not used but required.
uint32_t app_ota_status_addr = 0;
app_token_t *app_token = nullptr;

void url(const String &url)
{
this->service_url = url;
}

void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr)
void setApp(uint32_t app_addr, app_token_t *app_token, uint32_t avec_addr, uint32_t app_ota_status_addr)
{
this->app_addr = app_addr;
this->app_token = app_token;
this->avec_addr = avec_addr; // AsyncClient vector (list) address
this->app_ota_status_addr = app_ota_status_addr;
}

app_token_t *appToken()
Expand Down
Loading

0 comments on commit 89f11b1

Please sign in to comment.