diff --git a/examples/Blinker_DuerOS/DuerOS_LIGHT/DuerOS_LIGHT.ino b/examples/Blinker_DuerOS/DuerOS_LIGHT/DuerOS_LIGHT.ino index a43a496b..12a10970 100644 --- a/examples/Blinker_DuerOS/DuerOS_LIGHT/DuerOS_LIGHT.ino +++ b/examples/Blinker_DuerOS/DuerOS_LIGHT/DuerOS_LIGHT.ino @@ -263,6 +263,22 @@ void duerRelativeBright(int32_t bright) BlinkerDuerOS.print(); } +void duerColoTemp(int32_t colorTemp) +{ + BLINKER_LOG("need set colorTemperature: ", colorTemp); + + BlinkerDuerOS.colorTemp(colorTemp); + BlinkerDuerOS.print(); +} + +void duerRelativeColoTemp(int32_t colorTemp) +{ + BLINKER_LOG("need set relative colorTemperature: ", colorTemp); + + BlinkerDuerOS.colorTemp(colorTemp); + BlinkerDuerOS.print(); +} + void duerQuery(int32_t queryCode) { BLINKER_LOG("DuerOS Query codes: ", queryCode); @@ -309,6 +325,8 @@ void setup() BlinkerDuerOS.attachCancelMode(duercMode); BlinkerDuerOS.attachBrightness(duerBright); BlinkerDuerOS.attachRelativeBrightness(duerRelativeBright); + BlinkerDuerOS.attachColorTemperature(duerColoTemp); + BlinkerDuerOS.attachRelativeColorTemperature(duerRelativeColoTemp); BlinkerDuerOS.attachQuery(duerQuery); pinMode(14, OUTPUT); diff --git a/examples/Blinker_Image/Image_WiFi/Image_WiFi.ino b/examples/Blinker_Image/Image_WiFi/Image_WiFi.ino index e98edf83..11591b6b 100644 --- a/examples/Blinker_Image/Image_WiFi/Image_WiFi.ino +++ b/examples/Blinker_Image/Image_WiFi/Image_WiFi.ino @@ -57,6 +57,11 @@ BlinkerImage Image1("img_abc"); int counter = 0; +void image1_callback(int32_t num) +{ + BLINKER_LOG("image is tapped, number is : ", num); +} + void button1_callback(const String & state) { BLINKER_LOG("get button state: ", state); @@ -85,6 +90,7 @@ void setup() Blinker.attachData(dataRead); Button1.attach(button1_callback); + Image1.attach(image1_callback); } void loop() { diff --git a/examples/Blinker_OTA/OTA_WiFi/OTA_WiFi.ino b/examples/Blinker_OTA/OTA_WiFi/OTA_WiFi.ino index de04cbd1..10929f2c 100644 --- a/examples/Blinker_OTA/OTA_WiFi/OTA_WiFi.ino +++ b/examples/Blinker_OTA/OTA_WiFi/OTA_WiFi.ino @@ -14,7 +14,7 @@ * if use ESP8266 with Blinker. * https://github.com/esp8266/Arduino/releases * - * Make sure installed 1.0.5 or later ESP32/Arduino package, + * Make sure installed 1.0.4 or later ESP32/Arduino package, * if use ESP32 with Blinker. * https://github.com/espressif/arduino-esp32/releases * @@ -58,9 +58,10 @@ char type[] = "Your Device Type"; char auth[] = "Your Device Secret Key"; -#define BLINKER_OTA_BLINK_TIME 500 +BlinkerButton Button1("btn-abc"); +BlinkerNumber Number1("num-abc"); -uint32_t os_time; +int counter = 0; void button1_callback(const String & state) { @@ -141,19 +142,10 @@ void dataRead(const String & data) Number1.print(counter); } -// void otaStatus(uint32_t load_size, uint32_t total_size) -// { -// if (millis() - os_time >= BLINKER_OTA_BLINK_TIME) -// { -// os_time = millis(); - -// digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); -// } -// } - void setup() { Serial.begin(115200); + BLINKER_DEBUG.stream(Serial); BLINKER_DEBUG.debugAll(); pinMode(LED_BUILTIN, OUTPUT); @@ -170,7 +162,6 @@ void setup() Blinker.attachDoubleClick(doubleClick); attachInterrupt(BLINKER_BUTTON_PIN, buttonTick, CHANGE); #endif - // BlinkerUpdater.onProgress(otaStatus); } void loop() diff --git a/keywords.txt b/keywords.txt index 260d957f..ffd98cae 100644 --- a/keywords.txt +++ b/keywords.txt @@ -53,7 +53,9 @@ attachLongPressPowerdown KEYWORD2 attachLongPressReset KEYWORD2 attachNoButtonReset KEYWORD2 attachAQI KEYWORD2 +attachAir KEYWORD2 attachWeather KEYWORD2 +attachWeatherForecast KEYWORD2 attachConfigGet KEYWORD2 attachDataGet KEYWORD2 pressedTime KEYWORD2 @@ -106,6 +108,7 @@ sms KEYWORD2 push KEYWORD2 wechat KEYWORD2 weather KEYWORD2 +weatherForecast KEYWORD2 aqi KEYWORD2 status KEYWORD2 flush KEYWORD2 diff --git a/src/Adapters/BlinkerBLE.h b/src/Adapters/BlinkerBLE.h index 3a74ace7..bf29af5d 100644 --- a/src/Adapters/BlinkerBLE.h +++ b/src/Adapters/BlinkerBLE.h @@ -243,7 +243,7 @@ int BlinkerBLE::print(char * data, bool needCheck) s_send = s.substring(num*(20), s.length()); else s_send = s.substring(num*(20), (num+1)*20); - + // BLINKER_LOG_ALL("s_send: ", s_send); pCharacteristic->setValue(s_send.c_str()); pCharacteristic->notify(); delay(5); @@ -267,6 +267,7 @@ void BlinkerBLE::onDisconnect(BLEServer* pServer) { deviceConnected = false; BLINKER_LOG_ALL("BLE disconnect"); + pServer->startAdvertising(); } void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) diff --git a/src/Adapters/BlinkerMQTT.h b/src/Adapters/BlinkerMQTT.h index 85b369d5..e7a4b280 100644 --- a/src/Adapters/BlinkerMQTT.h +++ b/src/Adapters/BlinkerMQTT.h @@ -872,6 +872,8 @@ void BlinkerMQTT::parseData(const char* data) BLINKER_ERR_LOG_ALL(BLINKER_F("No authority uuid found, check is from bridge/share device, data: "), dataGet); _needCheckShare = true; + + dataGet = data; } } } @@ -880,13 +882,13 @@ void BlinkerMQTT::parseData(const char* data) BLINKER_ERR_LOG_ALL(BLINKER_F("No authority&share uuid found, check is from bridge/share device, data: "), dataGet); _needCheckShare = true; + + dataGet = data; } // dataGet = String((char *)iotSub_MQTT->lastread); // root.printTo(dataGet); // serializeJson(root, dataGet); - dataGet = data; - // BLINKER_ERR_LOG_ALL(BLINKER_F("No authority uuid found, // check is from bridge/share device, \ // data: "), dataGet); @@ -1014,7 +1016,7 @@ int BlinkerMQTT::print(char * data, bool needCheck) // data_add = BLINKER_F(",\"fromDevice\":\""); // strcat(data, data_add.c_str()); strcat(data, ",\"fromDevice\":\""); - strcat(data, MQTT_ID_MQTT); + strcat(data, DEVICE_NAME_MQTT); // data_add = BLINKER_F("\",\"toDevice\":\""); // strcat(data, data_add.c_str()); strcat(data, "\",\"toDevice\":\""); @@ -1212,7 +1214,7 @@ int BlinkerMQTT::bPrint(char * name, const String & data) data_add += data; data_add += BLINKER_F(",\"fromDevice\":\""); - data_add += MQTT_ID_MQTT; + data_add += DEVICE_NAME_MQTT; data_add += BLINKER_F("\",\"toDevice\":\""); data_add += name; data_add += BLINKER_F("\",\"deviceType\":\"DiyBridge\"}"); @@ -1309,7 +1311,7 @@ int BlinkerMQTT::aliPrint(const String & data) data_add += data; data_add += BLINKER_F(",\"fromDevice\":\""); - data_add += MQTT_ID_MQTT; + data_add += DEVICE_NAME_MQTT; data_add += BLINKER_F("\",\"toDevice\":\"AliGenie_r\""); data_add += BLINKER_F(",\"deviceType\":\"vAssistant\"}"); @@ -1341,7 +1343,7 @@ int BlinkerMQTT::aliPrint(const String & data) strcpy(BLINKER_RRPC_PUB_TOPIC_MQTT, "/sys/"); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_PRODUCTINFO_MQTT); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/"); - strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_ID_MQTT); + strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, DEVICE_NAME_MQTT); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/rrpc/response/"); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, message_id); @@ -1401,7 +1403,7 @@ int BlinkerMQTT::duerPrint(const String & data, bool report) } data_add += BLINKER_F(",\"fromDevice\":\""); - data_add += MQTT_ID_MQTT; + data_add += DEVICE_NAME_MQTT; data_add += BLINKER_F("\",\"toDevice\":\"DuerOS_r\""); data_add += BLINKER_F(",\"deviceType\":\"vAssistant\"}"); @@ -1434,7 +1436,7 @@ int BlinkerMQTT::duerPrint(const String & data, bool report) strcpy(BLINKER_RRPC_PUB_TOPIC_MQTT, "/sys/"); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_PRODUCTINFO_MQTT); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/"); - strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_ID_MQTT); + strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, DEVICE_NAME_MQTT); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/rrpc/response/"); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, message_id); @@ -1487,7 +1489,7 @@ int BlinkerMQTT::miPrint(const String & data) data_add += data; data_add += BLINKER_F(",\"fromDevice\":\""); - data_add += MQTT_ID_MQTT; + data_add += DEVICE_NAME_MQTT; data_add += BLINKER_F("\",\"toDevice\":\"MIOT_r\""); data_add += BLINKER_F(",\"deviceType\":\"vAssistant\"}"); @@ -1519,7 +1521,7 @@ int BlinkerMQTT::miPrint(const String & data) strcpy(BLINKER_RRPC_PUB_TOPIC_MQTT, "/sys/"); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_PRODUCTINFO_MQTT); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/"); - strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_ID_MQTT); + strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, DEVICE_NAME_MQTT); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/rrpc/response/"); strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, message_id); @@ -1669,7 +1671,7 @@ int BlinkerMQTT::autoPrint(unsigned long id) payload += String(id); payload += BLINKER_F("}}}"); payload += BLINKER_F(",\"fromDevice\":\""); - payload += STRING_format(MQTT_ID_MQTT); + payload += STRING_format(DEVICE_NAME_MQTT); payload += BLINKER_F("\",\"deviceType\":\"Auto\""); payload += BLINKER_F(",\"toDevice\":\"serverClient\"}"); // "\",\"deviceType\":\"" + "type" + "\"}"; diff --git a/src/Adapters/BlinkerPROESP.h b/src/Adapters/BlinkerPROESP.h index 96e049ef..f6f93ee7 100644 --- a/src/Adapters/BlinkerPROESP.h +++ b/src/Adapters/BlinkerPROESP.h @@ -200,7 +200,11 @@ class BlinkerPROESP : public BlinkerStream #if defined(ESP8266) - BearSSL::WiFiClientSecure client_mqtt; + #ifndef BLINKER_WITHOUT_SSL + BearSSL::WiFiClientSecure client_mqtt; + #else + WiFiClient client_mqtt; + #endif // WiFiClientSecure client_mqtt; #elif defined(ESP32) WiFiClientSecure client_s; @@ -318,8 +322,10 @@ int BlinkerPROESP::connect() BLINKER_LOG(BLINKER_F("Connecting to MQTT... ")); #if defined(ESP8266) - client_mqtt.setInsecure(); - ::delay(10); + #ifndef BLINKER_WITHOUT_SSL + client_mqtt.setInsecure(); + ::delay(10); + #endif #endif BLINKER_LOG_FreeHeap_ALL(); @@ -777,14 +783,17 @@ void BlinkerPROESP::parseData(const char* data) BLINKER_ERR_LOG_ALL(BLINKER_F("No authority uuid found, check is from bridge/share device, data: "), dataGet); _needCheckShare = true; + dataGet = data; } } } - // else - // { + else + { + dataGet = data; + } // dataGet = String((char *)iotSub_PRO->lastread); // root.printTo(dataGet); - serializeJson(root, dataGet); + // serializeJson(root, dataGet); // BLINKER_ERR_LOG_ALL(BLINKER_F("No authority uuid found, // check is from bridge/share device, \ @@ -1842,10 +1851,16 @@ int BlinkerPROESP::connectServer() { // client_mqtt.stop(); - std::unique_ptrclient_s(new BearSSL::WiFiClientSecure); + #ifndef BLINKER_WITHOUT_SSL + client_mqtt.stop(); - // client_s->setFingerprint(fingerprint); - client_s->setInsecure(); + std::unique_ptrclient_s(new BearSSL::WiFiClientSecure); + + // client_s->setFingerprint(fingerprint); + client_s->setInsecure(); + #else + WiFiClient client_s; + #endif String url_iot = BLINKER_F("/api/v1/user/device/auth/get?deviceType="); url_iot += _deviceType; @@ -1891,7 +1906,19 @@ int BlinkerPROESP::connectServer() { url_iot += BLINKER_MIOT_TYPE; #endif - url_iot = "https://" + host + url_iot; + url_iot += BLINKER_F("&version="); + url_iot += BLINKER_OTA_VERSION_CODE; + #ifndef BLINKER_WITHOUT_SSL + url_iot += BLINKER_F("&protocol=mqtts"); + #else + url_iot += BLINKER_F("&protocol=mqtt"); + #endif + + #ifndef BLINKER_WITHOUT_SSL + url_iot = "https://" + host + url_iot; + #else + url_iot = "http://" + host + url_iot; + #endif BLINKER_LOG_ALL(BLINKER_F("HTTPS begin: "), url_iot); @@ -1899,7 +1926,11 @@ int BlinkerPROESP::connectServer() { String payload; + #ifndef BLINKER_WITHOUT_SSL if (http.begin(*client_s, url_iot)) { // HTTPS + #else + if (http.begin(client_s, url_iot)) { + #endif // Serial.print("[HTTPS] GET...\n"); // start connection and send HTTP header @@ -2084,10 +2115,16 @@ int BlinkerPROESP::connectServer() { #if defined(ESP8266) // client_mqtt.stop(); - std::unique_ptrclient_s(new BearSSL::WiFiClientSecure); + #ifndef BLINKER_WITHOUT_SSL + client_mqtt.stop(); + + std::unique_ptrclient_s(new BearSSL::WiFiClientSecure); - // client_s->setFingerprint(fingerprint); - client_s->setInsecure(); + // client_s->setFingerprint(fingerprint); + client_s->setInsecure(); + #else + WiFiClient client_s; + #endif String url_iot = BLINKER_F("/api/v1/user/device/auth?authKey="); url_iot += AUTHKEY_PRO; @@ -2129,11 +2166,20 @@ int BlinkerPROESP::connectServer() { #elif defined(BLINKER_MIOT_TYPE) url_iot += BLINKER_MIOT_TYPE; #endif - + url_iot += BLINKER_F("&version="); url_iot += BLINKER_OTA_VERSION_CODE; + #ifndef BLINKER_WITHOUT_SSL + url_iot += BLINKER_F("&protocol=mqtts"); + #else + url_iot += BLINKER_F("&protocol=mqtt"); + #endif - url_iot = "https://" + host + url_iot; + #ifndef BLINKER_WITHOUT_SSL + url_iot = "https://" + host + url_iot; + #else + url_iot = "http://" + host + url_iot; + #endif HTTPClient http; @@ -2141,8 +2187,11 @@ int BlinkerPROESP::connectServer() { BLINKER_LOG_ALL(BLINKER_F("[HTTP] begin: "), url_iot); + #ifndef BLINKER_WITHOUT_SSL if (http.begin(*client_s, url_iot)) { // HTTPS - + #else + if (http.begin(client_s, url_iot)) { + #endif // Serial.print("[HTTPS] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); @@ -2213,9 +2262,14 @@ int BlinkerPROESP::connectServer() { #elif defined(BLINKER_MIOT_TYPE) url_iot += BLINKER_MIOT_TYPE; #endif - + url_iot += BLINKER_F("&version="); url_iot += BLINKER_OTA_VERSION_CODE; + #ifndef BLINKER_WITHOUT_SSL + url_iot += BLINKER_F("&protocol=mqtts"); + #else + url_iot += BLINKER_F("&protocol=mqtt"); + #endif BLINKER_LOG_ALL(BLINKER_F("HTTPS begin: "), url_iot); @@ -2310,8 +2364,15 @@ int BlinkerPROESP::connectServer() { // String _deviceName = _userID.substring(12, 36); // MQTT_DEVICEID_PRO = (char*)malloc((_deviceName.length()+1)*sizeof(char)); // String _deviceName = _userID.substring(12, 36); - MQTT_DEVICEID_PRO = (char*)malloc((_userID.length()+1)*sizeof(char)); - strcpy(MQTT_DEVICEID_PRO, _userID.c_str()); + // MQTT_DEVICEID_PRO = (char*)malloc((_userID.length()+1)*sizeof(char)); + // strcpy(MQTT_DEVICEID_PRO, _userID.c_str()); + #if defined(BLINKER_WITHOUT_SSL) + MQTT_DEVICEID_PRO = (char*)malloc((24+1)*sizeof(char)); + strcpy(MQTT_DEVICEID_PRO, _userName.substring(0, 24).c_str()); + #else + MQTT_DEVICEID_PRO = (char*)malloc((_userID.length()+1)*sizeof(char)); + strcpy(MQTT_DEVICEID_PRO, _userID.c_str()); + #endif MQTT_ID_PRO = (char*)malloc((_userID.length()+1)*sizeof(char)); strcpy(MQTT_ID_PRO, _userID.c_str()); MQTT_NAME_PRO = (char*)malloc((_userName.length()+1)*sizeof(char)); @@ -2541,11 +2602,14 @@ int BlinkerPROESP::connectServer() { #if defined(ESP8266) // client_s->stop(); - client_mqtt.setInsecure(); + // if (!isMQTTinit) + #ifndef BLINKER_WITHOUT_SSL + client_mqtt.setInsecure(); + #endif + #elif defined(ESP32) + client_s.setInsecure(); #endif - // connect(); - - + // connect(); return true; } diff --git a/src/Blinker/BlinkerApi.h b/src/Blinker/BlinkerApi.h index 6f2105ec..78e6b7e9 100644 --- a/src/Blinker/BlinkerApi.h +++ b/src/Blinker/BlinkerApi.h @@ -374,13 +374,13 @@ class BlinkerApi : public BlinkerProtocol template bool wechat(const String & title, const String & state, const T& msg); #if !defined(BLINKER_AT_MQTT) - void weather(const String & _city = BLINKER_CMD_DEFAULT); - void weatherForecast(const String & _city = BLINKER_CMD_DEFAULT); - void aqi(const String & _city = BLINKER_CMD_DEFAULT); + void weather(uint32_t _city = 0); + void weatherForecast(uint32_t _city = 0); + void aqi(uint32_t _city = 0); #else - String weather(const String & _city = BLINKER_CMD_DEFAULT); - String weatherForecast(const String & _city = BLINKER_CMD_DEFAULT); - String aqi(const String & _city = BLINKER_CMD_DEFAULT); + String weather(uint32_t _city = 0); + String weatherForecast(uint32_t _city = 0); + String aqi(uint32_t _city = 0); #endif void log(const String & msg); @@ -551,10 +551,10 @@ class BlinkerApi : public BlinkerProtocol { _DuerOSSetBrightnessFunc = newFunction; } void attachDuerOSRelativeBrightness(blinker_callback_with_int32_arg_t newFunction) { _DuerOSSetRelativeBrightnessFunc = newFunction; } - // void attachDuerOSSetColorTemperature(blinker_callback_with_int32_arg_t newFunction) - // { _DuerOSSetColorTemperature = newFunction; } - // void attachDuerOSRelativeColorTemperature(blinker_callback_with_int32_arg_t newFunction) - // { _DuerOSSetRelativeColorTemperature = newFunction; } + void attachDuerOSSetColorTemperature(blinker_callback_with_int32_arg_t newFunction) + { _DuerOSSetColorTemperature = newFunction; } + void attachDuerOSRelativeColorTemperature(blinker_callback_with_int32_arg_t newFunction) + { _DuerOSSetRelativeColorTemperature = newFunction; } void attachDuerOSQuery(blinker_callback_with_int32_uint8_arg_t newFunction) { _DuerOSQueryFunc_m = newFunction; } void attachDuerOSQuery(blinker_callback_with_int32_arg_t newFunction) @@ -648,9 +648,9 @@ class BlinkerApi : public BlinkerProtocol int8_t month() { return atGetInt(BLINKER_CMD_MONTH); } int16_t year() { return atGetInt(BLINKER_CMD_YEAR); } int16_t yday() { return atGetInt(BLINKER_CMD_YDAY); } - void weather(const String & _city = BLINKER_CMD_DEFAULT); - void weatherForecast(const String & _city = BLINKER_CMD_DEFAULT); - void aqi(const String & _city = BLINKER_CMD_DEFAULT); + void weather(uint32_t _city = 0); + void weatherForecast(uint32_t _city = 0); + void aqi(uint32_t _city = 0); void log(const String & msg); void coordinate(float _long, float _lat); template @@ -1053,8 +1053,8 @@ class BlinkerApi : public BlinkerProtocol blinker_callback_with_string_arg_t _DuerOSSetcModeFunc = NULL; blinker_callback_with_string_arg_t _DuerOSSetBrightnessFunc = NULL; blinker_callback_with_int32_arg_t _DuerOSSetRelativeBrightnessFunc = NULL; - // blinker_callback_with_int32_arg_t _DuerOSSetColorTemperature = NULL; - // blinker_callback_with_int32_arg_t _DuerOSSetRelativeColorTemperature = NULL; + blinker_callback_with_int32_arg_t _DuerOSSetColorTemperature = NULL; + blinker_callback_with_int32_arg_t _DuerOSSetRelativeColorTemperature = NULL; blinker_callback_with_int32_uint8_arg_t _DuerOSQueryFunc_m = NULL; blinker_callback_with_int32_arg_t _DuerOSQueryFunc = NULL; @@ -2037,7 +2037,7 @@ class BlinkerApi : public BlinkerProtocol break; // return BLINKER_CMD_FALSE; case BLINKER_CMD_WEATHER_NUMBER : - url_iot = BLINKER_F("/api/v2"); + url_iot = BLINKER_F("/api/v3"); url_iot += msg; http.begin(host, url_iot); @@ -2045,7 +2045,7 @@ class BlinkerApi : public BlinkerProtocol httpCode = http.GET(); break; case BLINKER_CMD_WEATHER_FORECAST_NUMBER : - url_iot = BLINKER_F("/api/v2"); + url_iot = BLINKER_F("/api/v3"); url_iot += msg; http.begin(host, url_iot); @@ -2053,7 +2053,7 @@ class BlinkerApi : public BlinkerProtocol httpCode = http.GET(); break; case BLINKER_CMD_AQI_NUMBER : - url_iot = BLINKER_F("/api/v2"); + url_iot = BLINKER_F("/api/v3"); url_iot += msg; http.begin(host, url_iot); @@ -2292,6 +2292,10 @@ class BlinkerApi : public BlinkerProtocol payload = data_rp[BLINKER_CMD_DETAIL].as(); else if (_type == BLINKER_CMD_LOWPOWER_FREQ_GET_NUM) payload = data_rp[BLINKER_CMD_DETAIL][BLINKER_CMD_FREQ].as(); + else if (_type == BLINKER_CMD_WEATHER_FORECAST_NUMBER || \ + _type == BLINKER_CMD_WEATHER_NUMBER || \ + _type == BLINKER_CMD_AQI_NUMBER) + payload = data_rp[BLINKER_CMD_DETAIL].as(); else payload = data_rp[BLINKER_CMD_DETAIL][BLINKER_CMD_DATA].as(); } @@ -2919,11 +2923,11 @@ void BlinkerApi::needInit() begin(); - BLINKER_LOG(BLINKER_F( + BLINKER_LOG_ALL(BLINKER_F( "\n===========================================================" "\n================= Blinker PRO mode init ! =================" - "\nWarning! EEPROM address 1280-1535 is used for PRO ESP Mode!" - "\n============= DON'T USE THESE EEPROM ADDRESS! =============" + "\n EEPROM address 1280-1535 is used for PRO ESP Mode!" + "\n========= PLEASE AVOID USING THESE EEPROM ADDRESS! ========" "\n===========================================================\n")); // BLINKER_LOG(BLINKER_F("Already used: "), BLINKER_ONE_AUTO_DATA_SIZE); @@ -6106,17 +6110,15 @@ float BlinkerApi::gps(b_gps_t axis) } #if !defined(BLINKER_AT_MQTT) - void BlinkerApi::weather(const String & _city) + void BlinkerApi::weather(uint32_t _city) { - String data = BLINKER_F("/weather/"); + String data = BLINKER_F("/weather?"); - if (_city != BLINKER_CMD_DEFAULT) + if (_city != 0) { - data += _city; - data += BLINKER_F("?"); - } - else { - data += BLINKER_F("sichuan-chengdushi?"); + data += BLINKER_F("code="); + data += STRING_format(_city); + data += BLINKER_F("&"); } #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \ @@ -6129,7 +6131,7 @@ float BlinkerApi::gps(b_gps_t axis) data += BLINKER_F("device="); data += BProto::deviceName(); data += BLINKER_F("&key="); - data += BProto::authKey(); + data += BProto::token(); #elif defined(BLINKER_WIFI) data += BLINKER_F("deviceName="); data += macDeviceName(); @@ -6156,17 +6158,15 @@ float BlinkerApi::gps(b_gps_t axis) #endif } - void BlinkerApi::weatherForecast(const String & _city) + void BlinkerApi::weatherForecast(uint32_t _city) { - String data = BLINKER_F("/forecast/"); + String data = BLINKER_F("/forecast?"); - if (_city != BLINKER_CMD_DEFAULT) + if (_city != 0) { - data += _city; - data += BLINKER_F("?"); - } - else { - data += BLINKER_F("sichuan-chengdushi?"); + data += BLINKER_F("code="); + data += STRING_format(_city); + data += BLINKER_F("&"); } #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \ @@ -6180,7 +6180,7 @@ float BlinkerApi::gps(b_gps_t axis) data += BLINKER_F("device="); data += BProto::deviceName(); data += BLINKER_F("&key="); - data += BProto::authKey(); + data += BProto::token(); #elif defined(BLINKER_WIFI) data += BLINKER_F("deviceName="); data += macDeviceName(); @@ -6207,17 +6207,15 @@ float BlinkerApi::gps(b_gps_t axis) #endif } - void BlinkerApi::aqi(const String & _city) + void BlinkerApi::aqi(uint32_t _city) { - String data = BLINKER_F("/air/"); + String data = BLINKER_F("/air?"); - if (_city != BLINKER_CMD_DEFAULT) + if (_city != 0) { - data += _city; - data += BLINKER_F("?"); - } - else { - data += BLINKER_F("sichuan-chengdushi?"); + data += BLINKER_F("code="); + data += STRING_format(_city); + data += BLINKER_F("&"); } #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \ @@ -6231,7 +6229,7 @@ float BlinkerApi::gps(b_gps_t axis) data += BLINKER_F("device="); data += BProto::deviceName(); data += BLINKER_F("&key="); - data += BProto::authKey(); + data += BProto::token(); #elif defined(BLINKER_WIFI) data += BLINKER_F("deviceName="); data += macDeviceName(); @@ -6287,17 +6285,15 @@ float BlinkerApi::gps(b_gps_t axis) } #else - String BlinkerApi::weather(const String & _city) + String BlinkerApi::weather(uint32_t _city) { - String data = BLINKER_F("/weather/"); + String data = BLINKER_F("/weather?"); - if (_city != BLINKER_CMD_DEFAULT) + if (_city != 0) { - data += _city; - data += BLINKER_F("?"); - } - else { - data += BLINKER_F("sichuan-chengdushi?"); + data += BLINKER_F("code="); + data += STRING_format(_city); + data += BLINKER_F("&"); } #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \ @@ -6311,7 +6307,7 @@ float BlinkerApi::gps(b_gps_t axis) data += BLINKER_F("device="); data += BProto::deviceName(); data += BLINKER_F("&key="); - data += BProto::authKey(); + data += BProto::token(); #elif defined(BLINKER_WIFI) data += BLINKER_F("device="); data += macDeviceName(); @@ -6339,17 +6335,15 @@ float BlinkerApi::gps(b_gps_t axis) } - String BlinkerApi::weatherForecast(const String & _city) + String BlinkerApi::weatherForecast(uint32_t _city) { - String data = BLINKER_F("/forecast/"); + String data = BLINKER_F("/forecast?"); - if (_city != BLINKER_CMD_DEFAULT) + if (_city != 0) { - data += _city; - data += BLINKER_F("?"); - } - else { - data += BLINKER_F("sichuan-chengdushi?"); + data += BLINKER_F("code="); + data += STRING_format(_city); + data += BLINKER_F("&"); } #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \ @@ -6363,7 +6357,7 @@ float BlinkerApi::gps(b_gps_t axis) data += BLINKER_F("device="); data += BProto::deviceName(); data += BLINKER_F("&key="); - data += BProto::authKey(); + data += BProto::token(); #elif defined(BLINKER_WIFI) data += BLINKER_F("device="); data += macDeviceName(); @@ -6390,17 +6384,15 @@ float BlinkerApi::gps(b_gps_t axis) #endif } - String BlinkerApi::aqi(const String & _city) + String BlinkerApi::aqi(uint32_t _city) { - String data = BLINKER_F("/air/"); + String data = BLINKER_F("/air?"); - if (_city != BLINKER_CMD_DEFAULT) + if (_city != 0) { - data += _city; - data += BLINKER_F("?"); - } - else { - data += BLINKER_F("sichuan-chengdushi?"); + data += BLINKER_F("code="); + data += STRING_format(_city); + data += BLINKER_F("&"); } #if defined(BLINKER_MQTT) || defined(BLINKER_PRO) || \ @@ -6414,7 +6406,7 @@ float BlinkerApi::gps(b_gps_t axis) data += BLINKER_F("device="); data += BProto::deviceName(); data += BLINKER_F("&key="); - data += BProto::authKey(); + data += BProto::token(); #elif defined(BLINKER_WIFI) data += BLINKER_F("device="); data += macDeviceName(); @@ -6574,8 +6566,8 @@ float BlinkerApi::gps(b_gps_t axis) BLINKER_LOG(BLINKER_F( "\n===========================================================" "\n================== Blinker Timer loaded! ==================" - "\nWarning!EEPROM address 1536-2431 is used for Blinker Timer!" - "\n============= DON'T USE THESE EEPROM ADDRESS! =============" + "\n EEPROM address 1536-2431 is used for Blinker Timer!" + "\n========= PLEASE AVOID USING THESE EEPROM ADDRESS! ========" "\n===========================================================\n")); checkTimerErase(); @@ -8849,8 +8841,8 @@ char * BlinkerApi::widgetName_tab(uint8_t num) { BLINKER_LOG(BLINKER_F("=======================================================")); BLINKER_LOG(BLINKER_F("=========== Blinker Auto Control mode init! ===========")); - BLINKER_LOG(BLINKER_F("Warning!EEPROM address 0-1279 is used for Auto Control!")); - BLINKER_LOG(BLINKER_F("=========== DON'T USE THESE EEPROM ADDRESS! ===========")); + BLINKER_LOG(BLINKER_F(" EEPROM address 0-1279 is used for Auto Control!")); + BLINKER_LOG(BLINKER_F("======= PLEASE AVOID USING THESE EEPROM ADDRESS! ======")); BLINKER_LOG(BLINKER_F("=======================================================")); // BLINKER_LOG(BLINKER_F("Already used: "), BLINKER_ONE_AUTO_DATA_SIZE); @@ -11787,7 +11779,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) // return BLINKER_CMD_FALSE; case BLINKER_CMD_WEATHER_NUMBER : url_iot = host; - url_iot += BLINKER_F("/api/v2"); + url_iot += BLINKER_F("/api/v3"); url_iot += msg; #if defined(ESP8266) @@ -11804,7 +11796,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) break; case BLINKER_CMD_WEATHER_FORECAST_NUMBER : url_iot = host; - url_iot += BLINKER_F("/api/v2"); + url_iot += BLINKER_F("/api/v3"); url_iot += msg; #if defined(ESP8266) @@ -11821,7 +11813,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) break; case BLINKER_CMD_AQI_NUMBER : url_iot = host; - url_iot += BLINKER_F("/api/v2"); + url_iot += BLINKER_F("/api/v3"); url_iot += msg; #if defined(ESP8266) @@ -12324,7 +12316,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) // DynamicJsonBuffer jsonBuffer; // JsonObject& data_rp = jsonBuffer.parseObject(payload); - DynamicJsonDocument jsonBuffer(1024); + DynamicJsonDocument jsonBuffer(2048); DeserializationError error = deserializeJson(jsonBuffer, payload); JsonObject data_rp = jsonBuffer.as(); @@ -12339,6 +12331,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) } else { + BLINKER_LOG_ALL(BLINKER_F("_type: "), _type); // String _payload = data_rp[BLINKER_CMD_DETAIL][BLINKER_CMD_DATA]; // payload = _payload; @@ -12348,6 +12341,10 @@ char * BlinkerApi::widgetName_tab(uint8_t num) payload = data_rp[BLINKER_CMD_DETAIL].as(); else if (_type == BLINKER_CMD_LOWPOWER_FREQ_GET_NUM) payload = data_rp[BLINKER_CMD_DETAIL][BLINKER_CMD_FREQ].as(); + else if (_type == BLINKER_CMD_WEATHER_FORECAST_NUMBER || \ + _type == BLINKER_CMD_WEATHER_NUMBER || \ + _type == BLINKER_CMD_AQI_NUMBER) + payload = data_rp[BLINKER_CMD_DETAIL].as(); else payload = data_rp[BLINKER_CMD_DETAIL][BLINKER_CMD_DATA].as(); } @@ -12739,21 +12736,21 @@ char * BlinkerApi::widgetName_tab(uint8_t num) if (_DuerOSSetRelativeBrightnessFunc) _DuerOSSetRelativeBrightnessFunc(- setValue.toInt()); } - // else if (rootSet.containsKey(BLINKER_CMD_COLORTEMP)) { - // String setValue = rootSet[BLINKER_CMD_COLORTEMP]; + else if (rootSet.containsKey(BLINKER_CMD_COLORTEMP)) { + String setValue = rootSet[BLINKER_CMD_COLORTEMP]; - // if (_DuerOSSetColorTemperature) _DuerOSSetColorTemperature(setValue.toInt()); - // } - // else if (rootSet.containsKey(BLINKER_CMD_UPCOLORTEMP)) { - // String setValue = rootSet[BLINKER_CMD_UPCOLORTEMP]; + if (_DuerOSSetColorTemperature) _DuerOSSetColorTemperature(setValue.toInt()); + } + else if (rootSet.containsKey(BLINKER_CMD_UPCOLORTEMP)) { + String setValue = rootSet[BLINKER_CMD_UPCOLORTEMP]; - // if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(setValue.toInt()); - // } - // else if (rootSet.containsKey(BLINKER_CMD_DOWNCOLORTEMP)) { - // String setValue = rootSet[BLINKER_CMD_DOWNCOLORTEMP]; + if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(setValue.toInt()); + } + else if (rootSet.containsKey(BLINKER_CMD_DOWNCOLORTEMP)) { + String setValue = rootSet[BLINKER_CMD_DOWNCOLORTEMP]; - // if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(- setValue.toInt()); - // } + if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(- setValue.toInt()); + } else if (rootSet.containsKey(BLINKER_CMD_MODE)) { String setMode = rootSet[BLINKER_CMD_MODE]; @@ -13084,18 +13081,18 @@ char * BlinkerApi::widgetName_tab(uint8_t num) { if (_DuerOSSetRelativeBrightnessFunc) _DuerOSSetRelativeBrightnessFunc(- value.toInt()); } - // else if (STRING_find_string_value(_data, value, BLINKER_CMD_COLORTEMP)) - // { - // if (_DuerOSSetColorTemperature) _DuerOSSetColorTemperature(value.toInt()); - // } - // else if (STRING_find_string_value(_data, value, BLINKER_CMD_UPCOLORTEMP)) - // { - // if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(value.toInt()); - // } - // else if (STRING_find_string_value(_data, value, BLINKER_CMD_DOWNCOLORTEMP)) - // { - // if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(- value.toInt()); - // } + else if (STRING_find_string_value(_data, value, BLINKER_CMD_COLORTEMP)) + { + if (_DuerOSSetColorTemperature) _DuerOSSetColorTemperature(value.toInt()); + } + else if (STRING_find_string_value(_data, value, BLINKER_CMD_UPCOLORTEMP)) + { + if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(value.toInt()); + } + else if (STRING_find_string_value(_data, value, BLINKER_CMD_DOWNCOLORTEMP)) + { + if (_DuerOSSetRelativeColorTemperature) _DuerOSSetRelativeColorTemperature(- value.toInt()); + } else if (STRING_find_string_value(_data, value, BLINKER_CMD_MODE)) { if (_DuerOSSetModeFunc) _DuerOSSetModeFunc(value); @@ -14405,7 +14402,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) } - void BlinkerApi::weather(const String & _city) + void BlinkerApi::weather(uint32_t _city) { if (_weatherFunc) { @@ -14414,7 +14411,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) } - void BlinkerApi::weatherForecast(const String & _city) + void BlinkerApi::weatherForecast(uint32_t _city) { if (_weather_forecast_Func) { @@ -14423,7 +14420,7 @@ char * BlinkerApi::widgetName_tab(uint8_t num) } - void BlinkerApi::aqi(const String & _city) + void BlinkerApi::aqi(uint32_t _city) { if (_airFunc) { diff --git a/src/Functions/BlinkerDuerOS.h b/src/Functions/BlinkerDuerOS.h index c6a42017..3da58258 100644 --- a/src/Functions/BlinkerDuerOS.h +++ b/src/Functions/BlinkerDuerOS.h @@ -44,6 +44,16 @@ class BLINKERDUEROS Blinker.attachDuerOSRelativeBrightness(newFunction); } + void attachColorTemperature(blinker_callback_with_int32_arg_t newFunction) + { + Blinker.attachDuerOSSetColorTemperature(newFunction); + } + + void attachRelativeColorTemperature(blinker_callback_with_int32_arg_t newFunction) + { + Blinker.attachDuerOSRelativeColorTemperature(newFunction); + } + void attachQuery(blinker_callback_with_int32_uint8_arg_t newFunction) { Blinker.attachDuerOSQuery(newFunction); @@ -167,6 +177,26 @@ class BLINKERDUEROS strcpy(aMode, payload.c_str()); _fresh |= 0x01 << 2; + } + + void colorTemp(int clrTemp) + { + String payload = BLINKER_F("\""); + payload += STRING_format(BLINKER_CMD_COLORTEMP); + payload += BLINKER_F("\":\""); + payload += STRING_format(clrTemp); + payload += BLINKER_F("\""); + + // Blinker.DuerOSPrint(payload); + + if (_fresh >> 3 & 0x01) { + free(aCtemp); + } + + aCtemp = (char*)malloc((payload.length()+1)*sizeof(char)); + strcpy(aCtemp, payload.c_str()); + + _fresh |= 0x01 << 3; } void brightness(int now_bright) @@ -179,14 +209,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 3 & 0x01) { + if (_fresh >> 4 & 0x01) { free(aBright); } aBright = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aBright, payload.c_str()); - _fresh |= 0x01 << 3; + _fresh |= 0x01 << 4; } void brightness(int pre_bright, int now_bright) @@ -201,14 +231,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 3 & 0x01) { + if (_fresh >> 4 & 0x01) { free(aBright); } aBright = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aBright, payload.c_str()); - _fresh |= 0x01 << 3; + _fresh |= 0x01 << 4; } void temp(double _temp) @@ -221,14 +251,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 4 & 0x01) { + if (_fresh >> 5 & 0x01) { free(aTemp); } aTemp = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aTemp, payload.c_str()); - _fresh |= 0x01 << 4; + _fresh |= 0x01 << 5; } void temp(float _temp) @@ -241,14 +271,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 4 & 0x01) { + if (_fresh >> 5 & 0x01) { free(aTemp); } aTemp = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aTemp, payload.c_str()); - _fresh |= 0x01 << 4; + _fresh |= 0x01 << 5; } void temp(int _temp) @@ -261,14 +291,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 4 & 0x01) { + if (_fresh >> 5 & 0x01) { free(aTemp); } aTemp = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aTemp, payload.c_str()); - _fresh |= 0x01 << 4; + _fresh |= 0x01 << 5; } void humi(double _humi) @@ -281,14 +311,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 5 & 0x01) { + if (_fresh >> 6 & 0x01) { free(aHumi); } aHumi = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aHumi, payload.c_str()); - _fresh |= 0x01 << 5; + _fresh |= 0x01 << 6; } void humi(float _humi) @@ -301,14 +331,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 5 & 0x01) { + if (_fresh >> 6 & 0x01) { free(aHumi); } aHumi = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aHumi, payload.c_str()); - _fresh |= 0x01 << 5; + _fresh |= 0x01 << 6; } void humi(int _humi) @@ -321,14 +351,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 5 & 0x01) { + if (_fresh >> 6 & 0x01) { free(aHumi); } aHumi = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aHumi, payload.c_str()); - _fresh |= 0x01 << 5; + _fresh |= 0x01 << 6; } void pm25(double _pm25) @@ -341,14 +371,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 6 & 0x01) { + if (_fresh >> 7 & 0x01) { free(aPm25); } aPm25 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aPm25, payload.c_str()); - _fresh |= 0x01 << 6; + _fresh |= 0x01 << 7; } void pm25(float _pm25) @@ -361,14 +391,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 6 & 0x01) { + if (_fresh >> 7 & 0x01) { free(aPm25); } aPm25 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aPm25, payload.c_str()); - _fresh |= 0x01 << 6; + _fresh |= 0x01 << 7; } void pm25(int _pm25) @@ -381,14 +411,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 6 & 0x01) { + if (_fresh >> 7 & 0x01) { free(aPm25); } aPm25 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aPm25, payload.c_str()); - _fresh |= 0x01 << 6; + _fresh |= 0x01 << 7; } void pm10(double _pm10) @@ -401,14 +431,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 7 & 0x01) { + if (_fresh >> 8 & 0x01) { free(aPm10); } aPm10 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aPm10, payload.c_str()); - _fresh |= 0x01 << 7; + _fresh |= 0x01 << 8; } void pm10(float _pm10) @@ -421,14 +451,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 7 & 0x01) { + if (_fresh >> 8 & 0x01) { free(aPm10); } aPm10 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aPm10, payload.c_str()); - _fresh |= 0x01 << 7; + _fresh |= 0x01 << 8; } void pm10(int _pm10) @@ -441,14 +471,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 7 & 0x01) { + if (_fresh >> 8 & 0x01) { free(aPm10); } aPm10 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aPm10, payload.c_str()); - _fresh |= 0x01 << 7; + _fresh |= 0x01 << 8; } void co2(double _co2) @@ -461,14 +491,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 8 & 0x01) { + if (_fresh >> 9 & 0x01) { free(aCO2); } aCO2 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aCO2, payload.c_str()); - _fresh |= 0x01 << 8; + _fresh |= 0x01 << 9; } void co2(float _co2) @@ -481,14 +511,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 8 & 0x01) { + if (_fresh >> 9 & 0x01) { free(aCO2); } aCO2 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aCO2, payload.c_str()); - _fresh |= 0x01 << 8; + _fresh |= 0x01 << 9; } void co2(int _co2) @@ -501,14 +531,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 8 & 0x01) { + if (_fresh >> 9 & 0x01) { free(aCO2); } aCO2 = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aCO2, payload.c_str()); - _fresh |= 0x01 << 8; + _fresh |= 0x01 << 9; } void aqi(int _aqi) @@ -521,14 +551,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 9 & 0x01) { + if (_fresh >> 10 & 0x01) { free(aAQI); } aAQI = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aAQI, payload.c_str()); - _fresh |= 0x01 << 9; + _fresh |= 0x01 << 10; } void time(uint32_t _time) @@ -540,14 +570,14 @@ class BLINKERDUEROS // Blinker.DuerOSPrint(payload); - if (_fresh >> 10 & 0x01) { + if (_fresh >> 11 & 0x01) { free(aTIME); } aTIME = (char*)malloc((payload.length()+1)*sizeof(char)); strcpy(aTIME, payload.c_str()); - _fresh |= 0x01 << 10; + _fresh |= 0x01 << 11; } void print() @@ -587,12 +617,21 @@ class BLINKERDUEROS if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); + duerData += aCtemp; + + free(aCtemp); + } + + if (_fresh >> 4 & 0x01) { + if (duerData.length()) duerData += BLINKER_F(","); + else duerData += BLINKER_F("{"); + duerData += aBright; free(aBright); } - if (_fresh >> 4 & 0x01) { + if (_fresh >> 5 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -601,7 +640,7 @@ class BLINKERDUEROS free(aTemp); } - if (_fresh >> 5 & 0x01) { + if (_fresh >> 6 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -610,7 +649,7 @@ class BLINKERDUEROS free(aHumi); } - if (_fresh >> 6 & 0x01) { + if (_fresh >> 7 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -619,7 +658,7 @@ class BLINKERDUEROS free(aPm25); } - if (_fresh >> 7 & 0x01) { + if (_fresh >> 8 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -628,7 +667,7 @@ class BLINKERDUEROS free(aPm10); } - if (_fresh >> 8 & 0x01) { + if (_fresh >> 9 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -637,7 +676,7 @@ class BLINKERDUEROS free(aCO2); } - if (_fresh >> 9 & 0x01) { + if (_fresh >> 10 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -646,7 +685,7 @@ class BLINKERDUEROS free(aAQI); } - if (_fresh >> 10 & 0x01) { + if (_fresh >> 11 & 0x01) { if (duerData.length()) duerData += BLINKER_F(","); else duerData += BLINKER_F("{"); @@ -831,6 +870,7 @@ class BLINKERDUEROS char * aState; char * aColor; char * aMode; + char * aCtemp; char * aBright; char * aTemp; char * aHumi; diff --git a/src/Functions/BlinkerImage.h b/src/Functions/BlinkerImage.h index 14ec9336..59449cb8 100644 --- a/src/Functions/BlinkerImage.h +++ b/src/Functions/BlinkerImage.h @@ -7,10 +7,18 @@ class BlinkerImage { public : - BlinkerImage(char _name[]) + BlinkerImage(char _name[], blinker_callback_with_int32_arg_t _func = NULL) { - numName = (char*)malloc((strlen(_name)+1)*sizeof(char)); - strcpy(numName, _name); + wNum = Blinker.attachWidget(_name, _func); + // numName = (char*)malloc((strlen(_name)+1)*sizeof(char)); + // strcpy(numName, _name); + } + + void attach(blinker_callback_with_int32_arg_t _func) + { + if (wNum == 0) return; + + Blinker.freshAttachWidget(Blinker.widgetName_int(wNum), _func); } uint8_t getNum() { return num; } @@ -19,15 +27,16 @@ class BlinkerImage { num = _num; - String ImageData = BLINKER_F("{\"img\":"); - ImageData += STRING_format(num); - ImageData += BLINKER_F("}"); + // String ImageData = BLINKER_F("{\"img\":"); + // ImageData += STRING_format(num); + // ImageData += BLINKER_F("}"); - Blinker.printArray(numName, ImageData); + // Blinker.printArray(numName, ImageData); + Blinker.print(Blinker.widgetName_int(wNum), num); } private : - char * numName; + uint8_t wNum; uint8_t num = 0; }; diff --git a/src/Functions/BlinkerOTA.h b/src/Functions/BlinkerOTA.h index edd5ced0..e7f5f11b 100644 --- a/src/Functions/BlinkerOTA.h +++ b/src/Functions/BlinkerOTA.h @@ -121,12 +121,13 @@ bool BlinkerOTA::update() { saveOTACheck(); #if defined(ESP8266) - #ifndef BLINKER_WITHOUT_SSL + // #ifndef BLINKER_WITHOUT_SSL BearSSL::WiFiClientSecure client_s; BLINKER_LOG_FreeHeap(); - - client_mqtt.stop(); + #ifndef BLINKER_WITHOUT_SSL + client_mqtt.stop(); + #endif ::delay(100); bool mfln = client_s.probeMaxFragmentLength(ota_host, ota_port, 1024); @@ -164,9 +165,9 @@ bool BlinkerOTA::update() { // return true; // } - #else - WiFiClient client_s; - #endif + // #else + // WiFiClient client_s; + // #endif #elif defined(ESP32) client_s.stop();