Skip to content

Commit

Permalink
Fix RTDB data type mismatch, FireSense addon issue. Reduce memory usa…
Browse files Browse the repository at this point in the history
…ge. Remove RTDB's priority parameter in set and push of File and Blob functions.
  • Loading branch information
mobizt committed Jul 4, 2021
1 parent dc49aac commit 84a3f43
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
9 changes: 6 additions & 3 deletions src/rtdb/FB_RTDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,14 @@ bool FB_RTDB::int_pushInt(FirebaseData *fbdo, const char *path, int intValue, bo

void FB_RTDB::addJsonPriority(FirebaseData *fbdo, struct fb_esp_rtdb_request_info_t *req)
{
if (req->data.jsonPtr)
if (req->data.jsonPtr && strlen(req->priority) > 0)
{
char *tmp = nullptr;
tmp = ut->strP(fb_esp_pgm_str_157);
req->data.jsonPtr->add((const char *)tmp, req->priority);
if (ut->strposP(req->priority, fb_esp_pgm_str_4, 0) != -1)
req->data.jsonPtr->add((const char *)tmp, atof(req->priority));
else
req->data.jsonPtr->add((const char *)tmp, atoi(req->priority));
ut->delS(tmp);
}
}
Expand Down Expand Up @@ -4653,7 +4656,7 @@ bool FB_RTDB::handleResponse(FirebaseData *fbdo)
}
}

if (fbdo->_ss.rtdb.resp_data_type != d_null && fbdo->_ss.rtdb.req_data_type != d_timestamp && !response.noContent && fbdo->_ss.rtdb.req_method != m_post && fbdo->_ss.rtdb.req_method != m_get_shallow && response.httpCode < 400)
if (fbdo->_ss.rtdb.req_method != m_get_nocontent && fbdo->_ss.rtdb.req_data_type != d_timestamp && !response.noContent && fbdo->_ss.rtdb.req_method != m_post && fbdo->_ss.rtdb.req_method != m_get_shallow && response.httpCode < 400)
{
bool _reqType = fbdo->_ss.rtdb.req_data_type == d_integer || fbdo->_ss.rtdb.req_data_type == d_float || fbdo->_ss.rtdb.req_data_type == d_double;
bool _respType = fbdo->_ss.rtdb.resp_data_type == d_integer || fbdo->_ss.rtdb.resp_data_type == d_float || fbdo->_ss.rtdb.resp_data_type == d_double;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 20 additions & 8 deletions src/session/FB_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,10 @@ void FCMObject::fcm_begin(FirebaseData &fbdo)
fbdo.tcpClient.begin(host.c_str(), _port);
}

void FCMObject::fcm_prepareHeader(std::string &header, size_t payloadSize)
int FCMObject::fcm_sendHeader(FirebaseData &fbdo, size_t payloadSize)
{
int ret = -1;
std::string header;
if (!ut)
ut = new UtilsClass(nullptr);
FirebaseJsonData server_key;
Expand All @@ -1172,7 +1174,16 @@ void FCMObject::fcm_prepareHeader(std::string &header, size_t payloadSize)
ut->appendP(header, fb_esp_pgm_str_21);

ut->appendP(header, fb_esp_pgm_str_131);
header += server_key.stringValue.c_str();

ret = fbdo.tcpSend(header.c_str());
ut->clearS(header);
if (ret < 0)
return ret;

ret = fbdo.tcpSend(server_key.stringValue.c_str());
if (ret < 0)
return ret;

ut->appendP(header, fb_esp_pgm_str_21);

ut->appendP(header, fb_esp_pgm_str_32);
Expand All @@ -1188,6 +1199,10 @@ void FCMObject::fcm_prepareHeader(std::string &header, size_t payloadSize)
ut->appendP(header, fb_esp_pgm_str_21);
ut->appendP(header, fb_esp_pgm_str_36);
ut->appendP(header, fb_esp_pgm_str_21);

ret = fbdo.tcpSend(header.c_str());
ut->clearS(header);
return ret;
}

void FCMObject::fcm_preparePayload(fb_esp_fcm_msg_type messageType)
Expand Down Expand Up @@ -1534,8 +1549,6 @@ bool FCMObject::fcm_send(FirebaseData &fbdo, fb_esp_fcm_msg_type messageType)
if (!ut)
ut = new UtilsClass(nullptr);

std::string header;

FirebaseJsonData msg;

fcm_preparePayload(messageType);
Expand All @@ -1545,10 +1558,9 @@ bool FCMObject::fcm_send(FirebaseData &fbdo, fb_esp_fcm_msg_type messageType)
ut->appendP(s, fb_esp_pgm_str_575);
json.get(msg, s.c_str());

fcm_prepareHeader(header, msg.stringValue.length());

int ret = fbdo.tcpClient.send(header.c_str(), msg.stringValue.c_str());
ut->clearS(header);
int ret = fcm_sendHeader(fbdo, msg.stringValue.length());
if (ret == 0)
ret = fbdo.tcpSend(msg.stringValue.c_str());
json.remove(s.c_str());
ut->clearS(s);
ut->clearS(raw);
Expand Down
6 changes: 3 additions & 3 deletions src/session/FB_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#define FIREBASE_SESSION_H
#include <Arduino.h>
#include "Utils.h"
#include "stream/FB_Stream.h"
#include "stream/FB_MP_Stream.h"
#include "rtdb/stream/FB_Stream.h"
#include "rtdb/stream/FB_MP_Stream.h"
#include "rtdb/QueueInfo.h"
#include "rtdb/QueueManager.h"

Expand Down Expand Up @@ -180,7 +180,7 @@ class FCMObject

bool fcm_send(FirebaseData &fbdo, fb_esp_fcm_msg_type messageType);

void fcm_prepareHeader(std::string &header, size_t payloadSize);
int fcm_sendHeader(FirebaseData &fbdo, size_t payloadSize);

void fcm_preparePayload(fb_esp_fcm_msg_type messageType);

Expand Down

0 comments on commit 84a3f43

Please sign in to comment.