Terminating the server connection... #187
Unanswered
Nikitanagar
asked this question in
Q&A
Replies: 1 comment
-
I'm already replied here. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
we discussed #185
getting authenticating error:
`
#include <Arduino.h>
#define TINY_GSM_MODEM_SIM7600 // SIMA7670 Compatible with SIM7600 AT instructions
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
HardwareSerial SerialAT(PA3, PA2);
// See all AT commands, if wanted
// #define DUMP_AT_COMMANDS
// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
// set GSM PIN, if any
#define GSM_PIN ""
// Your GPRS credentials, if any
const char apn[] = "";
const char gprsUser[] = "";
const char gprsPass[] = "";
#define UART_BAUD 115200
// Include TinyGsmClient.h first and followed by FirebaseClient.h
#include <TinyGsmClient.h>
#include <FirebaseClient.h>
// The API key can be obtained from Firebase console > Project Overview > Project settings.
#define API_KEY ""
#define USER_EMAIL ""
#define USER_PASSWORD ""
#define DATABASE_URL "****"
TinyGsm modem(SerialAT);
TinyGsmClient gsm_client1(modem, 0);
TinyGsmClient gsm_client2(modem, 1);
// This is the library internal SSL clients.
// You can use any SSL Client that works with Ethernet library.
// The ESP_SSLClient uses PSRAM by default (if it is available), for PSRAM usage, see https://github.com/mobizt/FirebaseClient#memory-options
// For ESP_SSLClient documentation, see https://github.com/mobizt/ESP_SSLClient
ESP_SSLClient ssl_client1, ssl_client2;
GSMNetwork gsm_network(&modem, GSM_PIN, apn, gprsUser, gprsPass);
UserAuth user_auth(API_KEY, USER_EMAIL, USER_PASSWORD);
FirebaseApp app;
using AsyncClient = AsyncClientClass;
AsyncClient aClient1(ssl_client1, getNetwork(gsm_network)), aClient2(ssl_client2, getNetwork(gsm_network));
void asyncCB(AsyncResult &aResult);
void printResult(AsyncResult &aResult);
RealtimeDatabase Database;
unsigned long ms = 0;
void setup()
{
Serial.begin(115200);
delay(10);
DBG("Wait...");
delay(3000);
SerialAT.begin(UART_BAUD);
// Restart takes quite some time
// To skip it, call init() instead of restart()
DBG("Initializing modem...");
if (!modem.init())
{
DBG("Failed to restart modem, delaying 10s and retrying");
return;
}
/*
2 Automatic
13 GSM Only
14 WCDMA Only
38 LTE Only
*/
Serial.println(modem.getNetworkMode());
modem.setNetworkMode(38);
if (modem.waitResponse(10000L) != 1)
{
DBG(" setNetworkMode faill");
}
String name = modem.getModemName();
DBG("Modem Name:", name);
String modemInfo = modem.getModemInfo();
DBG("Modem Info:", modemInfo);
Firebase.printf("Firebase Client v%s\n", FIREBASE_CLIENT_VERSION);
ssl_client1.setInsecure();
ssl_client1.setDebugLevel(1);
ssl_client1.setBufferSizes(2048 /* rx /, 1024 / tx */);
ssl_client1.setClient(&gsm_client1);
ssl_client2.setInsecure();
ssl_client2.setDebugLevel(1);
ssl_client2.setBufferSizes(2048 /* rx /, 1024 / tx */);
ssl_client2.setClient(&gsm_client2);
Serial.println("Initializing app...");
initializeApp(aClient1, app, getAuth(user_auth), asyncCB, "authTask");
// Binding the FirebaseApp for authentication handler.
// To unbind, use Database.resetApp();
app.getApp(Database);
Database.url(DATABASE_URL);
Database.setSSEFilters("get,put,patch,keep-alive,cancel,auth_revoked");
// The "unauthenticate" error can be occurred in this case because we don't wait
// the app to be authenticated before connecting the stream.
// This is ok as stream task will be reconnected automatically when the app is authenticated.
Database.get(aClient1, "/Device/AD_001/contact_1", asyncCB, true /* SSE mode */, "streamTask");
}
void loop()
{
// The async task handler should run inside the main loop
// without blocking delay or bypassing with millis code blocks.
app.loop();
Database.loop();
if (millis() - ms > 20000 && app.ready())
{
ms = millis();
}
}
void asyncCB(AsyncResult &aResult)
{
// WARNING!
// Do not put your codes inside the callback and printResult.
printResult(aResult);
}
void printResult(AsyncResult &aResult)
{
if (aResult.isEvent())
{
Firebase.printf("Event task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.appEvent().message().c_str(), aResult.appEvent().code());
}
if (aResult.isDebug())
{
Firebase.printf("Debug task: %s, msg: %s\n", aResult.uid().c_str(), aResult.debug().c_str());
}
if (aResult.isError())
{
Firebase.printf("Error task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.error().message().c_str(), aResult.error().code());
}
if (aResult.available())
{
RealtimeDatabaseResult &RTDB = aResult.to();
if (RTDB.isStream())
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());
}
}`
Output:
OK
[17408] ### Unhandled: +NETOPEN: 0
OK
Debug task: streamTask, msg: Network connected
Error task: streamTask, msg: unauthenticate, code: -106
Event task: authTask, msg: authenticating, code: 7
Debug task: authTask, msg: Connecting to
Event task: authTask, msg: auth request sent, code: 8
Debug task: streamTask, msg: GPRS/EPS connected
Debug task: streamTask, msg: Terminating the server connection...
Debug task: streamTask, msg: Connecting to server...
Debug task: streamTask, msg: Terminating the server connection...
Debug task: streamTask, msg: Terminating the server connection...
Event task: authTask, msg: error, code: -1
Event task: authTask, msg: authenticating, code: 7
Event task: authTask, msg: auth request sent, code: 8
Debug task: streamTask, msg: Connecting to server...
Debug task: streamTask, msg: Terminating the server connection...
I have read the document, May I know the solution?
Beta Was this translation helpful? Give feedback.
All reactions