Skip to content

Commit df72117

Browse files
committed
update codes, upgrade BLINKER PRO ESP & RT codes.
1 parent ebbc82a commit df72117

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/Adapters/BlinkerPROESP.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,11 @@ int BlinkerPROESP::print(char * data, bool needCheck)
928928
// // payload += BLINKER_F("\",\"deviceType\":\"OwnApp\"}");
929929
// }
930930

931+
if (isMQTTinit == false) {
932+
BLINKER_ERR_LOG("print fail, mqtt not init...");
933+
return false;
934+
}
935+
931936
uint16_t num = strlen(data);
932937

933938
for(uint16_t c_num = num; c_num > 0; c_num--)

src/Blinker/BlinkerApi.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,15 @@ class BlinkerApi : public BlinkerProtocol
502502
#if defined(BLINKER_WIFI) || defined(BLINKER_MQTT) || \
503503
defined(BLINKER_PRO) || defined(BLINKER_PRO_ESP)
504504

505-
void attachRTData(blinker_callback_t newFunction)
505+
void attachRTData(blinker_callback_t newFunction, uint8_t rt_sec = 1)
506506
{
507507
// strcpy(_RTDataKey, _name);
508508
_RTDataFunc = newFunction;
509+
510+
if (rt_sec > 0 && rt_sec < 9)
511+
{
512+
_RTTime = rt_sec;
513+
}
509514
}
510515

511516
#endif
@@ -1087,6 +1092,7 @@ class BlinkerApi : public BlinkerProtocol
10871092
blinker_callback_t _RTDataFunc = NULL;
10881093
uint8_t _RTTimesCount = 0;
10891094
Ticker _RTTicker;
1095+
uint8_t _RTTime = 1;
10901096
#endif
10911097

10921098
#if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || defined(BLINKER_AT_MQTT) ||\
@@ -4698,22 +4704,31 @@ void BlinkerApi::rtParse(const JsonObject& data)
46984704

46994705
data_rtKeyCount = 0;
47004706

4701-
for (size_t i = 0; i < BLINKER_MAX_RTDATA_SIZE; i++)
4702-
{
4703-
String get_key = data["rt"][i];
4707+
if (data.containsKey("rt")) {
4708+
4709+
BLINKER_LOG_ALL(BLINKER_F("containsKey rt"));
47044710

4705-
if (get_key != "null")
4711+
for (size_t i = 0; i < BLINKER_MAX_RTDATA_SIZE; i++)
47064712
{
4707-
BLINKER_LOG_ALL(BLINKER_F("===>rt get_key: "), get_key);
4713+
String get_key = data["rt"][i];
47084714

4709-
// for (size_t num = 0; num < data_rtDataCount; num++)
4710-
// {
4711-
// if (_RTData[num]->checkName(get_key.c_str()))
4712-
// {
4713-
// strcpy(_RTDataKey[data_rtKeyCount], get_key.c_str());
4714-
data_rtKeyCount++;
4715-
// }
4716-
// }
4715+
if (get_key != "null")
4716+
{
4717+
BLINKER_LOG_ALL(BLINKER_F("===>rt get_key: "), get_key);
4718+
4719+
// for (size_t num = 0; num < data_rtDataCount; num++)
4720+
// {
4721+
// if (_RTData[num]->checkName(get_key.c_str()))
4722+
// {
4723+
// strcpy(_RTDataKey[data_rtKeyCount], get_key.c_str());
4724+
data_rtKeyCount++;
4725+
// }
4726+
// }
4727+
}
4728+
else
4729+
{
4730+
break;
4731+
}
47174732
}
47184733
}
47194734

@@ -4774,7 +4789,7 @@ void BlinkerApi::rtParse(const JsonObject& data)
47744789
// if (_RTDataFunc && data_rtRun == false)
47754790
// {
47764791
// data_rtRun = true;
4777-
_RTTicker.once(1, _RTDataFunc);
4792+
_RTTicker.once(_RTTime, _RTDataFunc);
47784793

47794794
data_rtTimes = 0;
47804795

@@ -7103,7 +7118,7 @@ float BlinkerApi::gps(b_gps_t axis)
71037118

71047119
// printObject(_RTDataKey, data);
71057120

7106-
_RTTicker.once(1, _RTDataFunc);
7121+
_RTTicker.once(_RTTime, _RTDataFunc);
71077122

71087123
data_rtTimes++;
71097124

0 commit comments

Comments
 (0)