Skip to content

Commit 56e5ff7

Browse files
committed
Bugs fix and improvements.
1 parent 55a1326 commit 56e5ff7

31 files changed

+1014
-694
lines changed

examples/ExternalClient/Ethernet/Basic/Basic.ino

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,6 @@ void networkStatusRequestCallback()
127127
fbdo.setNetworkStatus(Ethernet.linkStatus() == LinkON);
128128
}
129129

130-
// Define the callback function to handle server connection
131-
void tcpConnectionRequestCallback(const char *host, int port)
132-
{
133-
134-
// You may need to set the system timestamp to use for
135-
// auth token expiration checking.
136-
137-
if (timestamp == 0)
138-
{
139-
timestamp = ntpClient.getTime(2000 /* wait 2000 ms */);
140-
141-
if (timestamp > 0)
142-
Firebase.setSystemTime(timestamp);
143-
}
144-
145-
Serial.print("Connecting to server via external Client... ");
146-
if (!ssl_client.connect(host, port))
147-
{
148-
Serial.println("failed.");
149-
return;
150-
}
151-
Serial.println("success.");
152-
}
153-
154130
void setup()
155131
{
156132

@@ -185,7 +161,7 @@ void setup()
185161
fbdo.setExternalClient(&ssl_client);
186162

187163
/* Assign the required callback functions */
188-
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback, networkConnection, networkStatusRequestCallback);
164+
fbdo.setExternalClientCallbacks(networkConnection, networkStatusRequestCallback);
189165

190166
// Comment or pass false value when WiFi reconnection will control by your code or third party library
191167
Firebase.reconnectWiFi(true);

examples/ExternalClient/Ethernet/StreamCallback/StreamCallback.ino

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -135,54 +135,6 @@ void networkStatusRequestCallback()
135135
stream.setNetworkStatus(Ethernet.linkStatus() == LinkON);
136136
}
137137

138-
// Define the callback function to handle server connection
139-
void tcpConnectionRequestCallback1(const char *host, int port)
140-
{
141-
142-
// You may need to set the system timestamp to use for
143-
// auth token expiration checking.
144-
145-
if (timestamp == 0)
146-
{
147-
timestamp = ntpClient.getTime(2000 /* wait 2000 ms */);
148-
149-
if (timestamp > 0)
150-
Firebase.setSystemTime(timestamp);
151-
}
152-
153-
Serial.print("Connecting to server via external Client... ");
154-
if (!ssl_client1.connect(host, port))
155-
{
156-
Serial.println("failed.");
157-
return;
158-
}
159-
Serial.println("success.");
160-
}
161-
162-
// Define the callback function to handle server connection
163-
void tcpConnectionRequestCallback2(const char *host, int port)
164-
{
165-
166-
// You may need to set the system timestamp to use for
167-
// auth token expiration checking.
168-
169-
if (timestamp == 0)
170-
{
171-
timestamp = ntpClient.getTime(2000 /* wait 2000 ms */);
172-
173-
if (timestamp > 0)
174-
Firebase.setSystemTime(timestamp);
175-
}
176-
177-
Serial.print("Connecting to server via external Client2... ");
178-
if (!ssl_client2.connect(host, port))
179-
{
180-
Serial.println("failed.");
181-
return;
182-
}
183-
Serial.println("success.");
184-
}
185-
186138
void streamCallback(StreamData data)
187139
{
188140
Serial_Printf("sream path, %s\nevent path, %s\ndata type, %s\nevent type, %s\n\n",
@@ -254,13 +206,13 @@ void setup()
254206
fbdo.setExternalClient(&ssl_client1);
255207

256208
/* Assign the required callback functions */
257-
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback1, networkConnection, networkStatusRequestCallback);
209+
fbdo.setExternalClientCallbacks(networkConnection, networkStatusRequestCallback);
258210

259211
/* Assign the pointer to global defined external SSL Client object */
260212
stream.setExternalClient(&ssl_client2);
261213

262214
/* Assign the required callback functions */
263-
stream.setExternalClientCallbacks(tcpConnectionRequestCallback2, networkConnection, networkStatusRequestCallback);
215+
stream.setExternalClientCallbacks(networkConnection, networkStatusRequestCallback);
264216

265217
// Comment or pass false value when WiFi reconnection will control by your code or third party library
266218
Firebase.reconnectWiFi(true);

examples/ExternalClient/WiFi/Basic/Basic.ino

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,6 @@ void networkStatusRequestCallback()
7676
fbdo.setNetworkStatus(WiFi.status() == WL_CONNECTED);
7777
}
7878

79-
// Define the callback function to handle server connection
80-
void tcpConnectionRequestCallback(const char *host, int port)
81-
{
82-
83-
// You may need to set the system timestamp to use for
84-
// auth token expiration checking.
85-
86-
Serial.print("Connecting to server via external Client... ");
87-
if (!ssl_client.connect(host, port))
88-
{
89-
Serial.println("failed.");
90-
return;
91-
}
92-
Serial.println("success.");
93-
}
94-
9579
void setup()
9680
{
9781

@@ -122,7 +106,7 @@ void setup()
122106
fbdo.setExternalClient(&ssl_client);
123107

124108
/* Assign the required callback functions */
125-
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback, networkConnection, networkStatusRequestCallback);
109+
fbdo.setExternalClientCallbacks(networkConnection, networkStatusRequestCallback);
126110

127111
// Comment or pass false value when WiFi reconnection will control by your code or third party library
128112
Firebase.reconnectWiFi(true);

examples/ExternalClient/WiFi/StreamCallback/StreamCallback.ino

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,6 @@ void networkStatusRequestCallback()
8181
stream.setNetworkStatus(WiFi.status() == WL_CONNECTED);
8282
}
8383

84-
// Define the callback function to handle server connection
85-
void tcpConnectionRequestCallback1(const char *host, int port)
86-
{
87-
88-
// You may need to set the system timestamp to use for
89-
// auth token expiration checking.
90-
91-
Serial.print("Connecting to server via external Client... ");
92-
if (!ssl_client1.connect(host, port))
93-
{
94-
Serial.println("failed.");
95-
return;
96-
}
97-
Serial.println("success.");
98-
}
99-
100-
// Define the callback function to handle server connection
101-
void tcpConnectionRequestCallback2(const char *host, int port)
102-
{
103-
104-
// You may need to set the system timestamp to use for
105-
// auth token expiration checking.
106-
107-
Serial.print("Connecting to server via external Client... ");
108-
if (!ssl_client2.connect(host, port))
109-
{
110-
Serial.println("failed.");
111-
return;
112-
}
113-
Serial.println("success.");
114-
}
115-
11684
void streamCallback(StreamData data)
11785
{
11886
Serial_Printf("sream path, %s\nevent path, %s\ndata type, %s\nevent type, %s\n\n",
@@ -181,13 +149,13 @@ void setup()
181149
fbdo.setExternalClient(&ssl_client1);
182150

183151
/* Assign the required callback functions */
184-
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback1, networkConnection, networkStatusRequestCallback);
152+
fbdo.setExternalClientCallbacks(networkConnection, networkStatusRequestCallback);
185153

186154
/* Assign the pointer to global defined external SSL Client object */
187155
stream.setExternalClient(&ssl_client2);
188156

189157
/* Assign the required callback functions */
190-
stream.setExternalClientCallbacks(tcpConnectionRequestCallback2, networkConnection, networkStatusRequestCallback);
158+
stream.setExternalClientCallbacks(networkConnection, networkStatusRequestCallback);
191159

192160
Firebase.reconnectWiFi(true);
193161

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ setExternalClientCallbacks KEYWORD2
7373
setNetworkStatus KEYWORD2
7474
getFreeHeap KEYWORD2
7575
getCurrentTime KEYWORD2
76+
setUDPClient KEYWORD2
7677

7778
set KEYWORD2
7879
push KEYWORD2

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Firebase ESP32 Client",
3-
"version": "4.3.2",
3+
"version": "4.3.3",
44
"keywords": "communication, REST, esp32, arduino",
55
"description": "The secure, fast and reliable Firebase Realtime database library to read, store, update, delete, listen, backup, and restore data. You can also read and modify the database security rules with this library.",
66
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name=Firebase ESP32 Client
22

3-
version=4.3.2
3+
version=4.3.3
44

55
author=Mobizt
66

src/FB_Const.h

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#ifndef FB_CONST_H_
3131
#define FB_CONST_H_
3232

33-
#pragma once
34-
3533
#include <Arduino.h>
3634
#include <time.h>
3735

@@ -48,6 +46,7 @@
4846
#define FIREBASEJSON_USE_PSRAM
4947
#endif
5048
#include "json/FirebaseJson.h"
49+
#include "MB_NTP.h"
5150

5251
#if defined(ENABLE_OTA_FIRMWARE_UPDATE) && (defined(ENABLE_RTDB) || defined(ENABLE_FB_STORAGE) || defined(ENABLE_GC_STORAGE))
5352
#if defined(ESP32)
@@ -67,11 +66,21 @@
6766
#endif
6867

6968
#if defined(FIREBASE_ESP_CLIENT)
69+
7070
#define FIREBASE_STREAM_CLASS FirebaseStream
7171
#define FIREBASE_MP_STREAM_CLASS MultiPathStream
72+
#define FIREBASE_CLASS Firebase_ESP_Client
73+
7274
#elif defined(FIREBASE_ESP32_CLIENT) || defined(FIREBASE_ESP8266_CLIENT)
75+
7376
#define FIREBASE_STREAM_CLASS StreamData
7477
#define FIREBASE_MP_STREAM_CLASS MultiPathStreamData
78+
#if defined(ESP32)
79+
#define FIREBASE_CLASS FirebaseESP32
80+
#elif defined(ES8266) || defined(PICO_RP2040)
81+
#define FIREBASE_CLASS FirebaseESP8266
82+
#endif
83+
7584
#endif
7685

7786
class FirebaseData;
@@ -560,6 +569,52 @@ enum fb_esp_functions_operation_status
560569

561570
#endif
562571

572+
struct fb_esp_wifi_credential_t
573+
{
574+
MB_String ssid;
575+
MB_String password;
576+
};
577+
578+
struct fb_esp_wifi_credentials_t
579+
{
580+
friend class Firebase_Signer;
581+
582+
public:
583+
fb_esp_wifi_credentials_t(){};
584+
~fb_esp_wifi_credentials_t() { clearAP(); };
585+
void addAP(const String &ssid, const String &password)
586+
{
587+
fb_esp_wifi_credential_t cred;
588+
cred.ssid = ssid;
589+
cred.password = password;
590+
credentials.push_back(cred);
591+
}
592+
void clearAP()
593+
{
594+
credentials.clear();
595+
}
596+
597+
private:
598+
MB_List<fb_esp_wifi_credential_t> credentials;
599+
};
600+
601+
static fb_esp_wifi_credentials_t WiFiCreds;
602+
603+
class fb_esp_wifi
604+
{
605+
public:
606+
fb_esp_wifi(){};
607+
~fb_esp_wifi() { WiFiCreds.clearAP(); };
608+
void addAP(const String &ssid, const String &password)
609+
{
610+
WiFiCreds.addAP(ssid, password);
611+
}
612+
void clearAP()
613+
{
614+
WiFiCreds.clearAP();
615+
}
616+
};
617+
563618
template <typename T>
564619
struct fb_esp_base64_io_t
565620
{
@@ -767,15 +822,19 @@ typedef struct fb_esp_spi_ethernet_module_t
767822
{
768823
#if defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X)
769824
#ifdef INC_ENC28J60_LWIP
770-
ENC28J60lwIP *enc28j60;
825+
ENC28J60lwIP *enc28j60 = nullptr;
771826
#endif
772827
#ifdef INC_W5100_LWIP
773-
Wiznet5100lwIP *w5100;
828+
Wiznet5100lwIP *w5100 = nullptr;
774829
#endif
775830
#ifdef INC_W5500_LWIP
776-
Wiznet5500lwIP *w5500;
831+
Wiznet5500lwIP *w5500 = nullptr;
777832
#endif
833+
834+
#elif defined(PICO_RP2040)
835+
778836
#endif
837+
779838
} SPI_ETH_Module;
780839

781840
struct fb_esp_auth_token_info_t
@@ -922,6 +981,7 @@ struct fb_esp_cfg_int_t
922981

923982
bool fb_reconnect_wifi = false;
924983
unsigned long fb_last_reconnect_millis = 0;
984+
bool net_once_connected = false;
925985
unsigned long fb_last_jwt_begin_step_millis = 0;
926986
unsigned long fb_last_jwt_generation_error_cb_millis = 0;
927987
unsigned long fb_last_request_token_cb_millis = 0;
@@ -1077,7 +1137,7 @@ struct fb_esp_functions_config_t
10771137
#if defined(ENABLE_FB_STORAGE)
10781138
struct fb_esp_fcs_config_t
10791139
{
1080-
size_t upload_buffer_size = 512;
1140+
size_t upload_buffer_size = 2048;
10811141
size_t download_buffer_size = 2048;
10821142
};
10831143

@@ -1177,6 +1237,7 @@ struct fb_esp_cfg_t
11771237
TokenStatusCallback token_status_callback = NULL;
11781238
// deprecated
11791239
int8_t max_token_generation_retry = 0;
1240+
fb_esp_wifi wifi;
11801241
struct fb_esp_rtdb_config_t rtdb;
11811242
#if defined(ENABLE_GC_STORAGE)
11821243
struct fb_esp_gcs_config_t gcs;
@@ -1194,6 +1255,10 @@ struct fb_esp_cfg_t
11941255

11951256
SPI_ETH_Module spi_ethernet_module;
11961257
struct fb_esp_client_timeout_t timeout;
1258+
1259+
public:
1260+
fb_esp_cfg_t(){};
1261+
~fb_esp_cfg_t() { wifi.clearAP(); };
11971262
};
11981263

11991264
#ifdef ENABLE_RTDB
@@ -1935,7 +2000,7 @@ static const char fb_esp_pgm_str_65[] PROGMEM = "gateway timeout";
19352000
static const char fb_esp_pgm_str_66[] PROGMEM = "http version not support";
19362001
static const char fb_esp_pgm_str_67[] PROGMEM = "network authentication required";
19372002
static const char fb_esp_pgm_str_68[] PROGMEM = "data buffer overflow";
1938-
static const char fb_esp_pgm_str_69[] PROGMEM = "response payload read timed out due to network issue or too large data size";
2003+
static const char fb_esp_pgm_str_69[] PROGMEM = "response payload read timed out";
19392004
static const char fb_esp_pgm_str_70[] PROGMEM = "data type mismatch";
19402005
static const char fb_esp_pgm_str_71[] PROGMEM = "path not exist";
19412006
static const char fb_esp_pgm_str_72[] PROGMEM = "task";
@@ -2036,7 +2101,7 @@ static const char fb_esp_pgm_str_166[] PROGMEM = "\".sv\"";
20362101
static const char fb_esp_pgm_str_167[] PROGMEM = "Transfer-Encoding: ";
20372102
static const char fb_esp_pgm_str_168[] PROGMEM = "chunked";
20382103
static const char fb_esp_pgm_str_169[] PROGMEM = "Maximum Redirection reached";
2039-
// static const char fb_esp_pgm_str_170[] PROGMEM = "";
2104+
static const char fb_esp_pgm_str_170[] PROGMEM = "UDP client is required for NTP server time synching based on your network type \ne.g. WiFiUDP or EthernetUDP. Please call Firebase.setUDPClient(&udpClient, gmtOffset); to assign the UDP client.";
20402105
// static const char fb_esp_pgm_str_171[] PROGMEM = "";
20412106
static const char fb_esp_pgm_str_172[] PROGMEM = "&";
20422107
static const char fb_esp_pgm_str_173[] PROGMEM = "?";

0 commit comments

Comments
 (0)