Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeating Error Code -3, Not Connected using v4.3.3 #468

Closed
djmick opened this issue Jan 21, 2023 · 4 comments
Closed

Repeating Error Code -3, Not Connected using v4.3.3 #468

djmick opened this issue Jan 21, 2023 · 4 comments

Comments

@djmick
Copy link

djmick commented Jan 21, 2023

After initial connection to RTDB using v4.3.3 i'm repeatedly getting "stream timed out, resuming..." followed by "error code: -3, reason: not connected" every 3 seconds. As you'll see in my example code, Firebase.ready() is being called repeatedly.

Opening port
Port open
Connecting to Wi-Fi.
Connected with IP: 10.0.0.121


Current Boot Time (EDT): 01/21/2023 04:11:37 PM

Firebase Client v4.3.3


01/21/2023 04:11:37 PM
Token info: type = id token (GITKit token), status = on request



01/21/2023 04:11:38 PM
Token info: type = id token (GITKit token), status = ready


RTDB User Path: /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
01/21/2023 04:11:38 PM


01/21/2023 04:11:39 PM
stream timed out, resuming...


sream path, /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
event path, /
data type, json
event type, put

Pretty printed JSON data:
{
"dht": {
"humitity": "19%",
"lastUpdated": 1674330519425,
"temperature": "71°F"
},
"serverTimeStamp": 1674333984382
}
Iterate JSON data:

0, Type: object, Name: dht, Value: {"humitity":"19%","lastUpdated":1674330519425,"temperature":"71°F"}
1, Type: object, Name: humitity, Value: "19%"
2, Type: object, Name: lastUpdated, Value: 1674330519425
3, Type: object, Name: temperature, Value: "71°F"
4, Type: object, Name: serverTimeStamp, Value: 1674333984382

Received stream payload size: 147 (Max. 147)


01/21/2023 04:11:43 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 04:11:46 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 04:11:50 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 04:11:53 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 04:11:56 PM
stream timed out, resuming...

error code: -3, reason: not connected


`/**

*/

#include <FB_Const.h>
#include <FB_Error.h>
#include <FB_Network.h>
#include <FB_Utils.h>
#include <Firebase.h>
#include <FirebaseFS.h>
#include <HttpsOTAUpdate.h>
#include <Update.h>
#include <esp_crt_bundle.h>
#include <ssl_client.h>
#include <WiFiClientSecure.h>
#include <ETH.h>
#include <SPI.h>
#include <SD.h>
#include <sd_defines.h>
#include <sd_diskio.h>
#include <FS.h>
#include <FSImpl.h>
#include <vfs_api.h>
#include <SPIFFS.h>
#include <MB_NTP.h>
#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif

#include <Firebase_ESP_Client.h>

// Provide the token generation process info.
#include <addons/TokenHelper.h>

// Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>

/* 1. Define the WiFi credentials */
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

// For the following credentials, see examples/Authentications/SignInAsUser/EmailPassword/EmailPassword.ino

/* 2. Define the API Key */
#define API_KEY "API_KEY"

/* 3. Define the RTDB URL */
#define DATABASE_URL "URL" //.firebaseio.com or ..firebasedatabase.app

/* 4. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "USER_EMAIL"
#define USER_PASSWORD "USER_PASSWORD"

// Define Firebase Data object
FirebaseData stream;
FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

unsigned long sendDataPrevMillis = 0;

int count = 0;

volatile bool dataChanged = false;

String fbDbPath;

void streamCallback(FirebaseStream data)
{
Serial.printf("sream path, %s\nevent path, %s\ndata type, %s\nevent type, %s\n\n",
data.streamPath().c_str(),
data.dataPath().c_str(),
data.dataType().c_str(),
data.eventType().c_str());
printResult(data); // see addons/RTDBHelper.h
Serial.println();

// This is the size of stream payload received (current and max value)
// Max payload size is the payload size under the stream path since the stream connected
// and read once and will not update until stream reconnection takes place.
// This max value will be zero as no payload received in case of ESP8266 which
// BearSSL reserved Rx buffer size is less than the actual stream payload.
Serial.printf("Received stream payload size: %d (Max. %d)\n\n", data.payloadLength(), data.maxPayloadLength());

// Due to limited of stack memory, do not perform any task that used large memory here especially starting connect to server.
// Just set this flag and check it status later.
dataChanged = true;

}

void streamTimeoutCallback(bool timeout)
{
Serial.println("***************");
printCurrentTime(true);
if (timeout)
Serial.println("stream timed out, resuming...\n");

if (!stream.httpConnected())
    Serial.printf("error code: %d, reason: %s\n", stream.httpCode(), stream.errorReason().c_str());

Serial.println("***************");
Serial.println();
Serial.println();

}

void setup()
{

Serial.begin(115200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
    Serial.print(".");
    delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

ntpInit(); //get time

Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

/* Assign the api key (required) */
config.api_key = API_KEY;

/* Assign the user sign in credentials */
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;

/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;

/* Assign the callback function for the long running token generation task */
config.token_status_callback = my_tokenStatusCallback; // see addons/TokenHelper.h


config.signer.preRefreshSeconds = 3600 - 60;

Firebase.begin(&config, &auth);

Firebase.reconnectWiFi(true);


//Set the size of HTTP response buffers in the case where we want to work with large data.
fbdo.setResponseSize(1024);

String fbUid = auth.token.uid.c_str();
fbDbPath =  "/users/" + fbUid;
Serial.print("RTDB User Path: ");
Serial.println(fbDbPath);

printCurrentTime(true);

if (!Firebase.RTDB.beginStream(&stream, fbDbPath))
    Serial.printf("sream begin error, %s\n\n", stream.errorReason().c_str());

Firebase.RTDB.setStreamCallback(&stream, streamCallback, streamTimeoutCallback);

}

void loop()
{

if (Firebase.ready() && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0))
{
    sendDataPrevMillis = millis();
    //count++;
    //FirebaseJson json;
    //json.add("data", "hello");
    //json.add("num", count);
    //Serial.printf("Set json... %s\n\n", Firebase.RTDB.setJSON(&fbdo, "/test/stream/data/json", &json) ? "ok" : fbdo.errorReason().c_str());
}

if (dataChanged)
{
    dataChanged = false;
    // When stream data is available, do anything here...
}

}

void my_tokenStatusCallback(TokenInfo info)
{
/** fb_esp_auth_token_status enum
* token_status_uninitialized,
* token_status_on_initialize,
* token_status_on_signing,
* token_status_on_request,
* token_status_on_refresh,
* token_status_ready,
* token_status_error
*/

Serial.println("***************");
printCurrentTime(true);
if (info.status == token_status_error)
{
    Serial_Printf("Token info: type = %s, status = %s\n", getTokenType(info), getTokenStatus(info));
    Serial_Printf("Token error: %s\n", getTokenError(info).c_str());
}
else
{
    Serial_Printf("Token info: type = %s, status = %s\n", getTokenType(info), getTokenStatus(info));
}
Serial.println("***************");
Serial.println();
Serial.println();

}

const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 18000;
const int daylightOffset_sec = 3600;
#define TZ "EST5EDT,M3.2.0,M11.1.0"

void ntpInit() {
configTime(0, 0, ntpServer); // 0, 0 because we will use TZ in the next line
setenv("TZ", TZ, 1); // Set environment variable with your time zone
tzset();

time_t now;
struct tm timeinfo;

if (!getLocalTime(&timeinfo)) {
    Serial.println("Failed to obtain time");
}
else {

    Serial.println("--------------------");
    Serial.print("Current Boot Time (EDT): ");
    Serial.println(&timeinfo, "%m/%d/%Y %I:%M:%S %p");
    Serial.println("--------------------");
    Serial.println();
}

}

void printCurrentTime(bool newLine) {
time_t now;
struct tm timeinfo;

//Serial.println();

if (!getLocalTime(&timeinfo)) {
    Serial.println("Failed to obtain time");
    return;
}
else if (newLine) {
    Serial.println(&timeinfo, "%m/%d/%Y %I:%M:%S %p");
}
else {
    Serial.print(&timeinfo, "%m/%d/%Y %I:%M:%S %p");
}

}

`

@mobizt
Copy link
Owner

mobizt commented Jan 21, 2023

The library works normally and there is nothing updated that involved this issue.
This is not the library issue unless your network issue which you should use other AP to access the internet or reset your router or change your device or power supply.

@mobizt mobizt closed this as completed Jan 21, 2023
@mobizt mobizt reopened this Jan 21, 2023
@mobizt
Copy link
Owner

mobizt commented Jan 21, 2023

I will check again and update.

@djmick
Copy link
Author

djmick commented Jan 21, 2023

I'm seeing a clear difference between 4.3.2 & 4.3.3

here's serial log using 4.3.2
Opening port
Port open

Connected with IP: 10.0.0.121


Current Boot Time (EDT): 01/21/2023 05:37:03 PM

Firebase Client v4.3.2


01/21/2023 05:37:03 PM
Token info: type = id token (GITKit token), status = on request



01/21/2023 05:37:08 PM
Token info: type = id token (GITKit token), status = ready


RTDB User Path: /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
01/21/2023 05:37:08 PM


01/21/2023 05:37:09 PM
stream timed out, resuming...


sream path, /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
event path, /
data type, json
event type, put

Pretty printed JSON data:
{
"dht": {
"humitity": "19%",
"lastUpdated": 1674330519425,
"temperature": "71°F"
},
"serverTimeStamp": 1674333984382
}
Iterate JSON data:

0, Type: object, Name: dht, Value: {"humitity":"19%","lastUpdated":1674330519425,"temperature":"71°F"}
1, Type: object, Name: humitity, Value: "19%"
2, Type: object, Name: lastUpdated, Value: 1674330519425
3, Type: object, Name: temperature, Value: "71°F"
4, Type: object, Name: serverTimeStamp, Value: 1674333984382

Received stream payload size: 147 (Max. 147)


01/21/2023 05:37:39 PM



01/21/2023 05:38:09 PM
Token info: type = id token (GITKit token), status = on refreshing



01/21/2023 05:38:14 PM
Token info: type = id token (GITKit token), status = ready



01/21/2023 05:38:14 PM



01/21/2023 05:38:39 PM



01/21/2023 05:39:09 PM



01/21/2023 05:39:15 PM
Token info: type = id token (GITKit token), status = on refreshing



01/21/2023 05:39:20 PM
Token info: type = id token (GITKit token), status = ready


same code after clean install of 4.3.3
Opening port
Port open

Connected with IP: 10.0.0.121


Current Boot Time (EDT): 01/21/2023 05:42:07 PM

Firebase Client v4.3.3


01/21/2023 05:42:07 PM
Token info: type = id token (GITKit token), status = on request



01/21/2023 05:42:08 PM
Token info: type = id token (GITKit token), status = ready


RTDB User Path: /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
01/21/2023 05:42:08 PM


01/21/2023 05:42:09 PM
stream timed out, resuming...


sream path, /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
event path, /
data type, json
event type, put

Pretty printed JSON data:
{
"dht": {
"humitity": "19%",
"lastUpdated": 1674330519425,
"temperature": "71°F"
},
"serverTimeStamp": 1674333984382
}
Iterate JSON data:

0, Type: object, Name: dht, Value: {"humitity":"19%","lastUpdated":1674330519425,"temperature":"71°F"}
1, Type: object, Name: humitity, Value: "19%"
2, Type: object, Name: lastUpdated, Value: 1674330519425
3, Type: object, Name: temperature, Value: "71°F"
4, Type: object, Name: serverTimeStamp, Value: 1674333984382

Received stream payload size: 147 (Max. 147)


01/21/2023 05:42:13 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:19 PM
stream timed out, resuming...

error code: -3, reason: not connected


Port open


01/21/2023 05:42:30 PM
Token info: type = id token (GITKit token), status = ready


RTDB User Path: /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
01/21/2023 05:42:30 PM
sream path, /users/xxxxxxxxxxxxxxxxxxxxxxxxxxxx
event path, /
data type, json
event type, put

Pretty printed JSON data:
{
"dht": {
"humitity": "19%",
"lastUpdated": 1674330519425,
"temperature": "71°F"
},
"serverTimeStamp": 1674333984382
}
Iterate JSON data:

0, Type: object, Name: dht, Value: {"humitity":"19%","lastUpdated":1674330519425,"temperature":"71°F"}
1, Type: object, Name: humitity, Value: "19%"
2, Type: object, Name: lastUpdated, Value: 1674330519425
3, Type: object, Name: temperature, Value: "71°F"
4, Type: object, Name: serverTimeStamp, Value: 1674333984382

Received stream payload size: 147 (Max. 147)


01/21/2023 05:42:31 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:31 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:36 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:39 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:45 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:49 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:53 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:42:58 PM
stream timed out, resuming...

error code: -3, reason: not connected



01/21/2023 05:43:01 PM
stream timed out, resuming...

error code: -3, reason: not connected


@mobizt
Copy link
Owner

mobizt commented Jan 22, 2023

The library update is available, please update.

@mobizt mobizt closed this as completed Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants