mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
update mqtClient
This commit is contained in:
@@ -9,7 +9,7 @@ the LICENSE file.
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef EMC_TX_TIMEOUT
|
#ifndef EMC_TX_TIMEOUT
|
||||||
#define EMC_TX_TIMEOUT 5000
|
#define EMC_TX_TIMEOUT 2000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EMC_RX_BUFFER_SIZE
|
#ifndef EMC_RX_BUFFER_SIZE
|
||||||
@@ -29,7 +29,7 @@ the LICENSE file.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EMC_MIN_FREE_MEMORY
|
#ifndef EMC_MIN_FREE_MEMORY
|
||||||
#define EMC_MIN_FREE_MEMORY 4096
|
#define EMC_MIN_FREE_MEMORY 16384
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EMC_ESP8266_MULTITHREADING
|
#ifndef EMC_ESP8266_MULTITHREADING
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ the LICENSE file.
|
|||||||
#define EMC_SEMAPHORE_TAKE() xSemaphoreTake(_xSemaphore, portMAX_DELAY)
|
#define EMC_SEMAPHORE_TAKE() xSemaphoreTake(_xSemaphore, portMAX_DELAY)
|
||||||
#define EMC_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore)
|
#define EMC_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore)
|
||||||
#define EMC_GET_FREE_MEMORY() std::max(ESP.getMaxAllocHeap(), ESP.getMaxAllocPsram())
|
#define EMC_GET_FREE_MEMORY() std::max(ESP.getMaxAllocHeap(), ESP.getMaxAllocPsram())
|
||||||
#define EMC_YIELD() taskYIELD()
|
#define EMC_YIELD() vTaskDelay(1)
|
||||||
#define EMC_GENERATE_CLIENTID(x) snprintf(x, EMC_CLIENTID_LENGTH, "esp32%06llx", ESP.getEfuseMac());
|
#define EMC_GENERATE_CLIENTID(x) snprintf(x, EMC_CLIENTID_LENGTH, "esp32%06llx", ESP.getEfuseMac());
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include <Arduino.h> // millis(), ESP.getFreeHeap();
|
#include <Arduino.h> // millis(), ESP.getFreeHeap();
|
||||||
|
|||||||
@@ -332,8 +332,8 @@ int MqttClient::_sendPacket() {
|
|||||||
EMC_SEMAPHORE_TAKE();
|
EMC_SEMAPHORE_TAKE();
|
||||||
OutgoingPacket * packet = _outbox.getCurrent();
|
OutgoingPacket * packet = _outbox.getCurrent();
|
||||||
|
|
||||||
int32_t wantToWrite = 0;
|
size_t wantToWrite = 0;
|
||||||
int32_t written = 0;
|
size_t written = 0;
|
||||||
if (packet && (wantToWrite == written)) {
|
if (packet && (wantToWrite == written)) {
|
||||||
// mixing signed with unsigned here but safe because of MQTT packet size limits
|
// mixing signed with unsigned here but safe because of MQTT packet size limits
|
||||||
wantToWrite = packet->packet.available(_bytesSent);
|
wantToWrite = packet->packet.available(_bytesSent);
|
||||||
@@ -341,12 +341,7 @@ int MqttClient::_sendPacket() {
|
|||||||
EMC_SEMAPHORE_GIVE();
|
EMC_SEMAPHORE_GIVE();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
written = _transport->write(packet->packet.data(_bytesSent), wantToWrite);
|
written = _transport->write(packet->packet.data(_bytesSent), wantToWrite);
|
||||||
if (written < 0) {
|
|
||||||
emc_log_w("Write error, check connection");
|
|
||||||
EMC_SEMAPHORE_GIVE();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
packet->timeSent = millis();
|
packet->timeSent = millis();
|
||||||
_lastClientActivity = millis();
|
_lastClientActivity = millis();
|
||||||
_bytesSent += written;
|
_bytesSent += written;
|
||||||
@@ -707,7 +702,9 @@ uint16_t MqttClient::getQueue() const {
|
|||||||
espMqttClientInternals::Outbox<OutgoingPacket>::Iterator it = _outbox.front();
|
espMqttClientInternals::Outbox<OutgoingPacket>::Iterator it = _outbox.front();
|
||||||
uint16_t count = 0;
|
uint16_t count = 0;
|
||||||
while (it) {
|
while (it) {
|
||||||
|
// if (it.get()->packet.packetType() == PacketType.PUBLISH) {
|
||||||
++count;
|
++count;
|
||||||
|
// }
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
EMC_SEMAPHORE_GIVE();
|
EMC_SEMAPHORE_GIVE();
|
||||||
|
|||||||
Reference in New Issue
Block a user