mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
manually merge in official 0.9.0 version
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Marvin Roger
|
Copyright (c) 2015-2021 Marvin Roger
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ AsyncMqttClient::AsyncMqttClient()
|
|||||||
, _tail(nullptr)
|
, _tail(nullptr)
|
||||||
, _sent(0)
|
, _sent(0)
|
||||||
, _state(DISCONNECTED)
|
, _state(DISCONNECTED)
|
||||||
, _tlsBadFingerprint(false)
|
, _disconnectReason(AsyncMqttClientDisconnectReason::TCP_DISCONNECTED)
|
||||||
, _lastClientActivity(0)
|
, _lastClientActivity(0)
|
||||||
, _lastServerActivity(0)
|
, _lastServerActivity(0)
|
||||||
, _lastPingRequestTime(0)
|
, _lastPingRequestTime(0)
|
||||||
@@ -194,7 +194,6 @@ void AsyncMqttClient::_freeCurrentParsedPacket() {
|
|||||||
|
|
||||||
void AsyncMqttClient::_clear() {
|
void AsyncMqttClient::_clear() {
|
||||||
_lastPingRequestTime = 0;
|
_lastPingRequestTime = 0;
|
||||||
_tlsBadFingerprint = false;
|
|
||||||
_freeCurrentParsedPacket();
|
_freeCurrentParsedPacket();
|
||||||
_clearQueue(true); // keep session data for now
|
_clearQueue(true); // keep session data for now
|
||||||
|
|
||||||
@@ -219,7 +218,7 @@ void AsyncMqttClient::_onConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sslFoundFingerprint) {
|
if (!sslFoundFingerprint) {
|
||||||
_tlsBadFingerprint = true;
|
_disconnectReason = AsyncMqttClientDisconnectReason::TLS_BAD_FINGERPRINT;
|
||||||
_client.close(true);
|
_client.close(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -243,17 +242,10 @@ void AsyncMqttClient::_onConnect() {
|
|||||||
void AsyncMqttClient::_onDisconnect() {
|
void AsyncMqttClient::_onDisconnect() {
|
||||||
log_i("TCP disconn");
|
log_i("TCP disconn");
|
||||||
_state = DISCONNECTED;
|
_state = DISCONNECTED;
|
||||||
AsyncMqttClientDisconnectReason reason;
|
|
||||||
|
|
||||||
if (_tlsBadFingerprint) {
|
|
||||||
reason = AsyncMqttClientDisconnectReason::TLS_BAD_FINGERPRINT;
|
|
||||||
} else {
|
|
||||||
reason = AsyncMqttClientDisconnectReason::TCP_DISCONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
_clear();
|
_clear();
|
||||||
|
|
||||||
for (auto callback : _onDisconnectUserCallbacks) callback(reason);
|
for (auto callback : _onDisconnectUserCallbacks) callback(_disconnectReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -541,6 +533,8 @@ void AsyncMqttClient::_onConnAck(bool sessionPresent, uint8_t connectReturnCode)
|
|||||||
for (auto callback : _onConnectUserCallbacks) callback(sessionPresent);
|
for (auto callback : _onConnectUserCallbacks) callback(sessionPresent);
|
||||||
} else {
|
} else {
|
||||||
// Callbacks are handled by the onDisconnect function which is called from the AsyncTcp lib
|
// Callbacks are handled by the onDisconnect function which is called from the AsyncTcp lib
|
||||||
|
_disconnectReason = static_cast<AsyncMqttClientDisconnectReason>(connectReturnCode);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
_handleQueue(); // send any remaining data from continued session
|
_handleQueue(); // send any remaining data from continued session
|
||||||
}
|
}
|
||||||
@@ -710,6 +704,7 @@ void AsyncMqttClient::connect() {
|
|||||||
if (_state != DISCONNECTED) return;
|
if (_state != DISCONNECTED) return;
|
||||||
log_i("CONNECTING");
|
log_i("CONNECTING");
|
||||||
_state = CONNECTING;
|
_state = CONNECTING;
|
||||||
|
_disconnectReason = AsyncMqttClientDisconnectReason::TCP_DISCONNECTED; // reset any previous
|
||||||
|
|
||||||
_client.setRxTimeout(_keepAlive);
|
_client.setRxTimeout(_keepAlive);
|
||||||
|
|
||||||
@@ -770,6 +765,12 @@ uint16_t AsyncMqttClient::publish(const char* topic, uint8_t qos, bool retain, c
|
|||||||
return msg->packetId();
|
return msg->packetId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AsyncMqttClient::clearQueue() {
|
||||||
|
if (_state != DISCONNECTED) return false;
|
||||||
|
_clearQueue(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const char* AsyncMqttClient::getClientId() const {
|
const char* AsyncMqttClient::getClientId() const {
|
||||||
return _clientId;
|
return _clientId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ class AsyncMqttClient {
|
|||||||
uint16_t subscribe(const char* topic, uint8_t qos);
|
uint16_t subscribe(const char* topic, uint8_t qos);
|
||||||
uint16_t unsubscribe(const char* topic);
|
uint16_t unsubscribe(const char* topic);
|
||||||
uint16_t publish(const char* topic, uint8_t qos, bool retain, const char* payload = nullptr, size_t length = 0, bool dup = false, uint16_t message_id = 0);
|
uint16_t publish(const char* topic, uint8_t qos, bool retain, const char* payload = nullptr, size_t length = 0, bool dup = false, uint16_t message_id = 0);
|
||||||
|
bool clearQueue(); // Not MQTT compliant!
|
||||||
|
|
||||||
const char* getClientId() const;
|
const char* getClientId() const;
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ class AsyncMqttClient {
|
|||||||
DISCONNECTING,
|
DISCONNECTING,
|
||||||
DISCONNECTED
|
DISCONNECTED
|
||||||
} _state;
|
} _state;
|
||||||
bool _tlsBadFingerprint;
|
AsyncMqttClientDisconnectReason _disconnectReason;
|
||||||
uint32_t _lastClientActivity;
|
uint32_t _lastClientActivity;
|
||||||
uint32_t _lastServerActivity;
|
uint32_t _lastServerActivity;
|
||||||
uint32_t _lastPingRequestTime;
|
uint32_t _lastPingRequestTime;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
enum class AsyncMqttClientDisconnectReason : int8_t {
|
enum class AsyncMqttClientDisconnectReason : uint8_t {
|
||||||
TCP_DISCONNECTED = 0,
|
TCP_DISCONNECTED = 0,
|
||||||
|
|
||||||
MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1,
|
MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ PubAckOutPacket::PubAckOutPacket(PendingAck pendingAck) {
|
|||||||
_packetId = pendingAck.packetId;
|
_packetId = pendingAck.packetId;
|
||||||
_data[2] = pendingAck.packetId >> 8;
|
_data[2] = pendingAck.packetId >> 8;
|
||||||
_data[3] = pendingAck.packetId & 0xFF;
|
_data[3] = pendingAck.packetId & 0xFF;
|
||||||
// _released = false;
|
|
||||||
if (packetType() == AsyncMqttClientInternals::PacketType.PUBREL ||
|
if (packetType() == AsyncMqttClientInternals::PacketType.PUBREL ||
|
||||||
packetType() == AsyncMqttClientInternals::PacketType.PUBREC) {
|
packetType() == AsyncMqttClientInternals::PacketType.PUBREC) {
|
||||||
_released = false;
|
_released = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user