Skip to content

Commit 7db2473

Browse files
authored
Merge pull request #573 from blinker-iot/dev_3.0
update codes, upgrade LIB version
2 parents af4cb40 + f063eb0 commit 7db2473

File tree

5 files changed

+100
-90
lines changed

5 files changed

+100
-90
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "git",
1414
"url": "https://github.com/blinker-iot/blinker-library.git"
1515
},
16-
"version": "0.3.7.210421",
16+
"version": "0.3.70210426",
1717
"homepage": "https://blinker.app/",
1818
"export": {
1919
"exclude": [

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Blinker
2-
version=0.3.7.210421
2+
version=0.3.70210426
33
author=i3water
44
maintainer=i3wawter
55
sentence=Build a easy way for your IoT project.

src/Blinker/BlinkerApi.h

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,16 @@ class BlinkerApi : public BlinkerProtocol
363363
time_t startTime();
364364
time_t runTime();
365365

366+
// template<typename T>
367+
// bool sms(const T& msg);
366368
template<typename T>
367-
bool sms(const T& msg);
368-
template<typename T>
369-
bool sms(const T& msg, const char* cel);
369+
bool sms(const T& msg, const String & cel = "");
370370
template<typename T>
371-
bool push(const T& msg);
371+
bool push(const T& msg, const String & users = "");
372372
template<typename T>
373373
bool wechat(const T& msg);
374374
template<typename T>
375-
bool wechat(const String & title, const String & state, const T& msg);
375+
bool wechat(const String & title, const String & state, const T& msg, const String & users = "");
376376
#if !defined(BLINKER_AT_MQTT)
377377
void weather(uint32_t _city = 0);
378378
void weatherForecast(uint32_t _city = 0);
@@ -5967,54 +5967,54 @@ float BlinkerApi::gps(b_gps_t axis)
59675967
}
59685968
}
59695969

5970-
template<typename T>
5971-
bool BlinkerApi::sms(const T& msg)
5972-
{
5973-
String _msg = STRING_format(msg);
5974-
5975-
#if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \
5976-
defined(BLINKER_AT_MQTT) || defined(BLINKER_WIFI_GATEWAY) || \
5977-
defined(BLINKER_NBIOT_SIM7020) || defined(BLINKER_GPRS_AIR202) || \
5978-
defined(BLINKER_PRO_SIM7020) || defined(BLINKER_PRO_AIR202) || \
5979-
defined(BLINKER_MQTT_AUTO) || defined(BLINKER_PRO_ESP) || \
5980-
defined(BLINKER_LOWPOWER_AIR202) || defined(BLINKER_QRCODE_NBIOT_SIM7020) || \
5981-
defined(BLINKER_NBIOT_SIM7000) || defined(BLINKER_QRCODE_NBIOT_SIM7000) || \
5982-
defined(BLINKE_HTTP)
5983-
String data = BLINKER_F("{\"deviceName\":\"");
5984-
data += BProto::deviceName();
5985-
data += BLINKER_F("\",\"key\":\"");
5986-
data += BProto::authKey();
5987-
data += BLINKER_F("\",\"msg\":\"");
5988-
data += _msg;
5989-
data += BLINKER_F("\"}");
5990-
#elif defined(BLINKER_WIFI)
5991-
String data = BLINKER_F("{\"deviceName\":\"");
5992-
data += macDeviceName();
5993-
data += BLINKER_F("\",\"msg\":\"");
5994-
data += _msg;
5995-
data += BLINKER_F("\"}");
5996-
#elif defined(BLINKER_WIFI_SUBDEVICE)
5997-
String data = BLINKER_F("{\"sms\":\"");
5998-
data += _msg;
5999-
data += BLINKER_F("\"}");
6000-
#endif
6001-
6002-
if (_msg.length() > 20) {
6003-
return false;
6004-
}
5970+
// template<typename T>
5971+
// bool BlinkerApi::sms(const T& msg)
5972+
// {
5973+
// String _msg = STRING_format(msg);
5974+
5975+
// #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \
5976+
// defined(BLINKER_AT_MQTT) || defined(BLINKER_WIFI_GATEWAY) || \
5977+
// defined(BLINKER_NBIOT_SIM7020) || defined(BLINKER_GPRS_AIR202) || \
5978+
// defined(BLINKER_PRO_SIM7020) || defined(BLINKER_PRO_AIR202) || \
5979+
// defined(BLINKER_MQTT_AUTO) || defined(BLINKER_PRO_ESP) || \
5980+
// defined(BLINKER_LOWPOWER_AIR202) || defined(BLINKER_QRCODE_NBIOT_SIM7020) || \
5981+
// defined(BLINKER_NBIOT_SIM7000) || defined(BLINKER_QRCODE_NBIOT_SIM7000) || \
5982+
// defined(BLINKE_HTTP)
5983+
// String data = BLINKER_F("{\"deviceName\":\"");
5984+
// data += BProto::deviceName();
5985+
// data += BLINKER_F("\",\"key\":\"");
5986+
// data += BProto::authKey();
5987+
// data += BLINKER_F("\",\"msg\":\"");
5988+
// data += _msg;
5989+
// data += BLINKER_F("\"}");
5990+
// #elif defined(BLINKER_WIFI)
5991+
// String data = BLINKER_F("{\"deviceName\":\"");
5992+
// data += macDeviceName();
5993+
// data += BLINKER_F("\",\"msg\":\"");
5994+
// data += _msg;
5995+
// data += BLINKER_F("\"}");
5996+
// #elif defined(BLINKER_WIFI_SUBDEVICE)
5997+
// String data = BLINKER_F("{\"sms\":\"");
5998+
// data += _msg;
5999+
// data += BLINKER_F("\"}");
6000+
// #endif
6001+
6002+
// if (_msg.length() > 20) {
6003+
// return false;
6004+
// }
60056005

6006-
#if defined(BLINKER_WIFI_SUBDEVICE)
6007-
if (!checkSMS()) return false;
6008-
_smsTime = millis();
6006+
// #if defined(BLINKER_WIFI_SUBDEVICE)
6007+
// if (!checkSMS()) return false;
6008+
// _smsTime = millis();
60096009

6010-
return BProto::subPrint(data);
6011-
#else
6012-
return blinkerServer(BLINKER_CMD_SMS_NUMBER, data) != "false";
6013-
#endif
6014-
}
6010+
// return BProto::subPrint(data);
6011+
// #else
6012+
// return blinkerServer(BLINKER_CMD_SMS_NUMBER, data) != "false";
6013+
// #endif
6014+
// }
60156015

60166016
template<typename T>
6017-
bool BlinkerApi::sms(const T& msg, const char* cel)
6017+
bool BlinkerApi::sms(const T& msg, const String & cel)
60186018
{
60196019
String _msg = STRING_format(msg);
60206020

@@ -6065,7 +6065,7 @@ float BlinkerApi::gps(b_gps_t axis)
60656065
}
60666066

60676067
template<typename T>
6068-
bool BlinkerApi::push(const T& msg)
6068+
bool BlinkerApi::push(const T& msg, const String & users)
60696069
{
60706070
String _msg = STRING_format(msg);
60716071

@@ -6083,12 +6083,16 @@ float BlinkerApi::gps(b_gps_t axis)
60836083
data += BProto::authKey();
60846084
data += BLINKER_F("\",\"msg\":\"");
60856085
data += _msg;
6086+
data += BLINKER_F("\",\"receivers\":\"");
6087+
data += users;
60866088
data += BLINKER_F("\"}");
60876089
#elif defined(BLINKER_WIFI)
60886090
String data = BLINKER_F("{\"deviceName\":\"");
60896091
data += macDeviceName();
60906092
data += BLINKER_F("\",\"msg\":\"");
60916093
data += _msg;
6094+
data += BLINKER_F("\",\"receivers\":\"");
6095+
data += users;
60926096
data += BLINKER_F("\"}");
60936097
#elif defined(BLINKER_WIFI_SUBDEVICE)
60946098
String data = BLINKER_F("{\"push\":\"");
@@ -6147,7 +6151,7 @@ float BlinkerApi::gps(b_gps_t axis)
61476151
}
61486152

61496153
template<typename T>
6150-
bool BlinkerApi::wechat(const String & title, const String & state, const T& msg)
6154+
bool BlinkerApi::wechat(const String & title, const String & state, const T& msg, const String & users)
61516155
{
61526156
String _msg = STRING_format(msg);
61536157

@@ -6169,6 +6173,8 @@ float BlinkerApi::gps(b_gps_t axis)
61696173
data += state;
61706174
data += BLINKER_F("\",\"msg\":\"");
61716175
data += _msg;
6176+
data += BLINKER_F("\",\"receivers\":\"");
6177+
data += users;
61726178
data += BLINKER_F("\"}");
61736179
#elif defined(BLINKER_WIFI)
61746180
String data = BLINKER_F("{\"deviceName\":\"");
@@ -6179,6 +6185,8 @@ float BlinkerApi::gps(b_gps_t axis)
61796185
data += state;
61806186
data += BLINKER_F("\",\"msg\":\"");
61816187
data += _msg;
6188+
data += BLINKER_F("\",\"receivers\":\"");
6189+
data += users;
61826190
data += BLINKER_F("\"}");
61836191
#elif defined(BLINKER_WIFI_SUBDEVICE)
61846192
String data = BLINKER_F("{\"wechat\":\"");

src/Blinker/BlinkerConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// #include "Blinker/BlinkerUtility.h"
66
#include "../Server/BlinkerServer.h"
77

8-
#define BLINKER_VERSION "0.3.7.210421"
8+
#define BLINKER_VERSION "0.3.70210426"
99

1010
#define BLINKER_CONNECT_TIMEOUT_MS 10000UL
1111

src/modules/mqtt/Adafruit_MQTT.cpp

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -536,45 +536,47 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
536536
}
537537

538538
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
539-
uint16_t i, topiclen, datalen;
539+
uint16_t i, topiclen, datalen;
540540

541-
// Check if data is available to read.
542-
uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
543-
if (!len)
544-
return NULL; // No data available, just quit.
545-
DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len);
546-
DEBUG_PRINTBUFFER(buffer, len);
547-
548-
// Parse out length of packet.
549-
if(len <= 129)
550-
topiclen = buffer[3];
551-
else
552-
topiclen = buffer[4];
553-
DEBUG_PRINT(F("Looking for subscription len ")); DEBUG_PRINTLN(topiclen);
554-
555-
// Find subscription associated with this packet.
556-
for (i=0; i<MAXSUBSCRIPTIONS; i++) {
557-
if (subscriptions[i]) {
558-
// Skip this subscription if its name length isn't the same as the
559-
// received topic name.
560-
if (strlen(subscriptions[i]->topic) != topiclen)
561-
continue;
562-
// Stop if the subscription topic matches the received topic. Be careful
563-
// to make comparison case insensitive.
564-
if(len <= 129) {
565-
if (strncasecmp((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) {
566-
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
567-
break;
568-
}
569-
}
570-
else {
571-
if (strncasecmp((char*)buffer+5, subscriptions[i]->topic, topiclen) == 0) {
572-
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
573-
break;
541+
// Check if data is available to read.
542+
uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
543+
if (!len)
544+
return NULL; // No data available, just quit.
545+
DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len);
546+
DEBUG_PRINTBUFFER(buffer, len);
547+
548+
// Parse out length of packet.
549+
if (len < 3) return NULL;
550+
551+
if (len <= 129)
552+
topiclen = buffer[3];
553+
else
554+
topiclen = buffer[4];
555+
DEBUG_PRINT(F("Looking for subscription len ")); DEBUG_PRINTLN(topiclen);
556+
557+
// Find subscription associated with this packet.
558+
for (i=0; i<MAXSUBSCRIPTIONS; i++) {
559+
if (subscriptions[i]) {
560+
// Skip this subscription if its name length isn't the same as the
561+
// received topic name.
562+
if (strlen(subscriptions[i]->topic) != topiclen)
563+
continue;
564+
// Stop if the subscription topic matches the received topic. Be careful
565+
// to make comparison case insensitive.
566+
if(len <= 129) {
567+
if (strncasecmp((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) {
568+
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
569+
break;
570+
}
571+
}
572+
else {
573+
if (strncasecmp((char*)buffer+5, subscriptions[i]->topic, topiclen) == 0) {
574+
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
575+
break;
576+
}
577+
}
574578
}
575-
}
576579
}
577-
}
578580
if (i==MAXSUBSCRIPTIONS) {
579581
DEBUG_PRINTLN(F("Not found sub #"));
580582

0 commit comments

Comments
 (0)