diff --git a/lib/pubsubclient/src/PubSubClient.cpp b/lib/pubsubclient/src/PubSubClient.cpp
index 1f989ffc4..e736d6d3a 100644
--- a/lib/pubsubclient/src/PubSubClient.cpp
+++ b/lib/pubsubclient/src/PubSubClient.cpp
@@ -137,6 +137,12 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass
}
boolean PubSubClient::connect(const char *id, const char *user, const char *pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage, boolean cleanSession) {
+# ifdef USE_SECOND_HEAP
+ if (!initBuffer()) {
+ return false;
+ }
+# endif // ifdef USE_SECOND_HEAP
+
if (!connected()) {
int result = 0;
@@ -285,6 +291,12 @@ boolean PubSubClient::readByte(uint8_t * result, uint16_t * index){
}
uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
+# ifdef USE_SECOND_HEAP
+ if (!initBuffer()) {
+ return 0;
+ }
+# endif // ifdef USE_SECOND_HEAP
+
uint16_t len = 0;
if(!readByte(buffer, &len)) return 0;
bool isPublish = (buffer[0]&0xF0) == MQTTPUBLISH;
@@ -672,6 +684,12 @@ uint16_t PubSubClient::writeString(const char* string, uint8_t* buf, uint16_t po
}
size_t PubSubClient::appendBuffer(uint8_t data) {
+# ifdef USE_SECOND_HEAP
+ if (!initBuffer()) {
+ return 0;
+ }
+# endif // ifdef USE_SECOND_HEAP
+
buffer[_bufferWritePos] = data;
++_bufferWritePos;
if (_bufferWritePos >= MQTT_MAX_PACKET_SIZE) {
diff --git a/platformio_core_defs.ini b/platformio_core_defs.ini
index f2aadbe5f..2bea6bf09 100644
--- a/platformio_core_defs.ini
+++ b/platformio_core_defs.ini
@@ -64,6 +64,8 @@ lib_ignore = ESP32_ping
; Keep optimization flag to -O2
; See: https://github.com/platformio/platform-espressif8266/issues/288
+; For "-fno-strict-aliasing"
+; See: https://github.com/esp8266/Arduino/issues/8261
[esp82xx_2_7_x]
build_flags = -DNDEBUG
-mtarget-align
diff --git a/platformio_esp82xx_base.ini b/platformio_esp82xx_base.ini
index c2fb70d42..81a9676d6 100644
--- a/platformio_esp82xx_base.ini
+++ b/platformio_esp82xx_base.ini
@@ -17,10 +17,10 @@ platform_packages = ${core_stage.platform_packages}
lib_ignore = ${core_stage.lib_ignore}
[regular_platform]
-build_flags = ${core312_platform.build_flags}
-platform = ${core312_platform.platform}
-platform_packages = ${core312_platform.platform_packages}
-lib_ignore = ${core312_platform.lib_ignore}
+build_flags = ${core_stage_2ndheap.build_flags}
+platform = ${core_stage_2ndheap.platform}
+platform_packages = ${core_stage_2ndheap.platform_packages}
+lib_ignore = ${core_stage_2ndheap.lib_ignore}
[beta_platform_2ndheap]
@@ -82,6 +82,7 @@ src_filter = +<*> -<.git/> -<.svn/> - - - CHUNKED_BUFFER_SIZE) {
+ if (data.length() > (CHUNKED_BUFFER_SIZE + 1)) {
data = String(); // Clear also allocated memory
} else {
data.clear();
@@ -385,6 +381,7 @@ void Web_StreamingBuffer::sendHeaderBlocking(bool allowOriginAll,
const uint32_t freeBeforeSend = ESP.getFreeHeap();
const uint32_t beginWait = millis();
+
web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
web_server.sendHeader(F("Cache-Control"), F("no-cache"));
diff --git a/src/src/DataStructs/WiFi_AP_Candidate.cpp b/src/src/DataStructs/WiFi_AP_Candidate.cpp
index 92bb55bd3..589359c96 100644
--- a/src/src/DataStructs/WiFi_AP_Candidate.cpp
+++ b/src/src/DataStructs/WiFi_AP_Candidate.cpp
@@ -173,16 +173,21 @@ String WiFi_AP_Candidate::toString(const String& separator) const {
result += encryption_type();
if (phy_known()) {
- result += ' ';
- if (phy_11b) result += 'b';
- if (phy_11g) result += 'g';
- if (phy_11n) result += 'n';
+ String phy_str;
+
+ if (phy_11b) phy_str += 'b';
+ if (phy_11g) phy_str += 'g';
+ if (phy_11n) phy_str += 'n';
#ifdef ESP32
- if (phy_11ax) result += F("/ax");
- if (phy_lr) result += F("/lr");
- if (ftm_initiator) result += F("/FTM_i");
- if (ftm_responder) result += F("/FTM_r");
+ if (phy_11ax) phy_str += F("/ax");
+ if (phy_lr) phy_str += F("/lr");
+ if (ftm_initiator) phy_str += F("/FTM_i");
+ if (ftm_responder) phy_str += F("/FTM_r");
#endif
+
+ if (phy_str.length()) {
+ result += strformat(F(" (%s)"), phy_str.c_str());
+ }
}
return result;
}
diff --git a/src/src/Helpers/StringConverter.cpp b/src/src/Helpers/StringConverter.cpp
index 04684d8ca..18590265c 100644
--- a/src/src/Helpers/StringConverter.cpp
+++ b/src/src/Helpers/StringConverter.cpp
@@ -64,7 +64,8 @@ bool equals(const String& str, const char& c) {
void move_special(String& dest, String&& source) {
#ifdef USE_SECOND_HEAP
- if ((source.length() > 0) && !mmu_is_iram(&(source[0]))) {
+ // Only try to store larger strings here as those tend to be kept for a longer period.
+ if ((source.length() >= 32) && mmu_is_dram(&(source[0]))) {
// The string was not allocated on the 2nd heap, so copy instead of move
HeapSelectIram ephemeral;
if (dest.reserve(source.length())) {
@@ -92,8 +93,10 @@ bool reserve_special(String& str, size_t size) {
}
// FIXME TD-er: Should also use this for ESP32 with PSRAM to allocate on PSRAM
#ifdef USE_SECOND_HEAP
- {
+ if (size >= 32) {
+ // Only try to store larger strings here as those tend to be kept for a longer period.
HeapSelectIram ephemeral;
+ // String does round up to nearest multiple of 16 bytes, so no need to round up to multiples of 32 bit here
if (str.reserve(size)) {
return true;
}