Skip to content

Commit

Permalink
Merge pull request #567 from blinker-iot/dev_3.0
Browse files Browse the repository at this point in the history
update codes
  • Loading branch information
i3water authored Mar 22, 2021
2 parents 500adf3 + 01b9bb8 commit 8e056f2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 130 deletions.
2 changes: 1 addition & 1 deletion examples/Blinker_Air/Air_WiFi/Air_WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void dataRead(const String & data)
Blinker.print("millis", BlinkerTime);

digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
Blinker.aqi();
Blinker.air();

Blinker.delay(60000);
}
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ wechat KEYWORD2
weather KEYWORD2
weatherForecast KEYWORD2
aqi KEYWORD2
air KEYWORD2
status KEYWORD2
flush KEYWORD2
init KEYWORD2
Expand Down
121 changes: 1 addition & 120 deletions src/Adapters/BlinkerMQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ void BlinkerMQTT::flush()
{
BLINKER_LOG_ALL(BLINKER_F("flush"));

_needCheckShare = false;
// _needCheckShare = false;

free(msgBuf_MQTT); isFresh_MQTT = false; isAvail_MQTT = false;
isAliAvail = false; isDuerAvail = false; isMIOTAvail = false;//isBavail = false;
Expand Down Expand Up @@ -1863,125 +1863,6 @@ int BlinkerMQTT::connectServer() {
String host = BLINKER_F(BLINKER_SERVER_HOST);
String fingerprint = BLINKER_F("84 5f a4 8a 70 5e 79 7e f5 b3 b4 20 45 c8 35 55 72 f6 85 5a");

// WiFiClientSecure client_s;

// BearSSL::WiFiClientSecure *client_s;

// client_s = new BearSSL::WiFiClientSecure();

// BLINKER_LOG_ALL(BLINKER_F("connecting to "), host);

// // BLINKER_LOG_FreeHeap();

// uint8_t connet_times = 0;
// // client_s.stop();
// ::delay(100);

// // bool mfln = client_s.probeMaxFragmentLength(host, httpsPort, 1024);
// // if (mfln) {
// // client_s.setBufferSizes(1024, 1024);
// // }
// client_s->setFingerprint(fingerprint.c_str());

// client_s->setInsecure();

// // while (1) {
// bool cl_connected = false;
// if (!client_s->connect(host, httpsPort)) {
// BLINKER_ERR_LOG(BLINKER_F("server connection failed"));
// // connet_times++;

// ::delay(1000);
// }
// else {
// BLINKER_LOG_ALL(BLINKER_F("connection succeed"));
// cl_connected = true;

// // break;
// }

// // if (connet_times >= 4 && !cl_connected) return BLINKER_CMD_FALSE;
// // }

// String client_msg;

// String url_iot = BLINKER_F("/api/v1/user/device/diy/auth?authKey=");
// url_iot += _authKey;
// url_iot += _aliType;
// url_iot += _duerType;

// // #if defined(BLINKER_ALIGENIE_LIGHT)
// // url_iot += BLINKER_F("&aliType=light");
// // #elif defined(BLINKER_ALIGENIE_OUTLET)
// // url_iot += BLINKER_F("&aliType=outlet");
// // #elif defined(BLINKER_ALIGENIE_SWITCH)
// // #elif defined(BLINKER_ALIGENIE_SENSOR)
// // url_iot += BLINKER_F("&aliType=sensor");
// // #endif

// BLINKER_LOG_ALL(BLINKER_F("HTTPS begin: "), host, url_iot);

// client_msg = BLINKER_F("GET ");
// client_msg += url_iot;
// client_msg += BLINKER_F(" HTTP/1.1\r\nHost: ");
// client_msg += host;
// client_msg += BLINKER_F(":");
// client_msg += STRING_format(httpsPort);
// client_msg += BLINKER_F("\r\nConnection: close\r\n\r\n");

// client_s->print(client_msg);

// BLINKER_LOG_ALL(BLINKER_F("client_msg: "), client_msg);

// unsigned long timeout = millis();
// while (client_s->available() == 0) {
// if (millis() - timeout > 5000) {
// BLINKER_LOG_ALL(BLINKER_F(">>> Client Timeout !"));
// client_s->stop();
// return false;
// }
// }

// String _dataGet;
// String lastGet;
// String lengthOfJson;
// while (client_s->available()) {
// // String line = client_s.readStringUntil('\r');
// _dataGet = client_s->readStringUntil('\n');

// if (_dataGet.startsWith("Content-Length: ")){
// int addr_start = _dataGet.indexOf(' ');
// int addr_end = _dataGet.indexOf('\0', addr_start + 1);
// lengthOfJson = _dataGet.substring(addr_start + 1, addr_end);
// }

// if (_dataGet == "\r") {
// BLINKER_LOG_ALL(BLINKER_F("headers received"));

// break;
// }
// }

// for(int i=0;i<lengthOfJson.toInt();i++){
// lastGet += (char)client_s->read();
// }

// // BLINKER_LOG_FreeHeap();

// client_s->stop();
// client_s->flush();

// free(client_s);

// // BLINKER_LOG_FreeHeap();

// _dataGet = lastGet;

// BLINKER_LOG_ALL(BLINKER_F("_dataGet: "), _dataGet);

// String payload = _dataGet;


#ifndef BLINKER_WITHOUT_SSL
client_mqtt.stop();

Expand Down
16 changes: 8 additions & 8 deletions src/Blinker/BlinkerApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ class BlinkerApi : public BlinkerProtocol
#if !defined(BLINKER_AT_MQTT)
void weather(uint32_t _city = 0);
void weatherForecast(uint32_t _city = 0);
void aqi(uint32_t _city = 0);
void air(uint32_t _city = 0);
#else
String weather(uint32_t _city = 0);
String weatherForecast(uint32_t _city = 0);
String aqi(uint32_t _city = 0);
String air(uint32_t _city = 0);
#endif

void log(const String & msg);
Expand Down Expand Up @@ -650,7 +650,7 @@ class BlinkerApi : public BlinkerProtocol
int16_t yday() { return atGetInt(BLINKER_CMD_YDAY); }
void weather(uint32_t _city = 0);
void weatherForecast(uint32_t _city = 0);
void aqi(uint32_t _city = 0);
void air(uint32_t _city = 0);
void log(const String & msg);
void coordinate(float _long, float _lat);
template<typename T>
Expand Down Expand Up @@ -6207,7 +6207,7 @@ float BlinkerApi::gps(b_gps_t axis)
#endif
}

void BlinkerApi::aqi(uint32_t _city)
void BlinkerApi::air(uint32_t _city)
{
String data = BLINKER_F("/air?");

Expand Down Expand Up @@ -6384,7 +6384,7 @@ float BlinkerApi::gps(b_gps_t axis)
#endif
}

String BlinkerApi::aqi(uint32_t _city)
String BlinkerApi::air(uint32_t _city)
{
String data = BLINKER_F("/air?");

Expand Down Expand Up @@ -13956,7 +13956,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num)
reqData = BLINKER_F("+");
reqData += BLINKER_CMD_WEATHER_AT;
reqData += BLINKER_F(":");
reqData += STRING_format(weather(_slaverAT->getParam(0)));
reqData += STRING_format(weather(_slaverAT->getParam(0).toInt()));

BProto::serialPrint(reqData);
BProto::serialPrint(BLINKER_CMD_OK);
Expand All @@ -13967,7 +13967,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num)
reqData = BLINKER_F("+");
reqData += BLINKER_CMD_AQI_AT;
reqData += BLINKER_F(":");
reqData += STRING_format(aqi(_slaverAT->getParam(0)));
reqData += STRING_format(air(_slaverAT->getParam(0).toInt()));

BProto::serialPrint(reqData);
BProto::serialPrint(BLINKER_CMD_OK);
Expand Down Expand Up @@ -14420,7 +14420,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num)
}


void BlinkerApi::aqi(uint32_t _city)
void BlinkerApi::air(uint32_t _city)
{
if (_airFunc)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Blinker/BlinkerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

#define BLINKER_AT_MSG_TIMEOUT 1000UL

#define BLINKER_SERVER_CONNECT_LIMIT 12
#define BLINKER_SERVER_CONNECT_LIMIT 3

#if defined(BLINKER_DATA_HOUR_UPDATE)
#define BLINKER_DATA_FREQ_TIME 3600UL
Expand Down

0 comments on commit 8e056f2

Please sign in to comment.