mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-13 00:22:10 +00:00
MQTT unit test can inject WiFiClient (#5716)
This commit is contained in:
parent
93e2bc7058
commit
9f7cbf1b4f
@ -282,7 +282,9 @@ void mqttInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if HAS_NETWORKING
|
#if HAS_NETWORKING
|
||||||
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE)
|
MQTT::MQTT() : MQTT(std::unique_ptr<MQTTClient>(new MQTTClient())) {}
|
||||||
|
MQTT::MQTT(std::unique_ptr<MQTTClient> _mqttClient)
|
||||||
|
: concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE), mqttClient(std::move(_mqttClient)), pubSub(*mqttClient)
|
||||||
#else
|
#else
|
||||||
MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
|
MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
|
||||||
#endif
|
#endif
|
||||||
@ -420,13 +422,13 @@ void MQTT::reconnect()
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Use non-TLS-encrypted session");
|
LOG_INFO("Use non-TLS-encrypted session");
|
||||||
pubSub.setClient(mqttClient);
|
pubSub.setClient(*mqttClient);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
pubSub.setClient(mqttClient);
|
pubSub.setClient(*mqttClient);
|
||||||
#endif
|
#endif
|
||||||
#elif HAS_NETWORKING
|
#elif HAS_NETWORKING
|
||||||
pubSub.setClient(mqttClient);
|
pubSub.setClient(*mqttClient);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::pair<String, uint16_t> hostAndPort = parseHostAndPort(serverAddr, serverPort);
|
std::pair<String, uint16_t> hostAndPort = parseHostAndPort(serverAddr, serverPort);
|
||||||
@ -444,7 +446,7 @@ void MQTT::reconnect()
|
|||||||
enabled = true; // Start running background process again
|
enabled = true; // Start running background process again
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
isMqttServerAddressPrivate = isPrivateIpAddress(mqttClient.remoteIP());
|
isMqttServerAddressPrivate = isPrivateIpAddress(mqttClient->remoteIP());
|
||||||
|
|
||||||
publishNodeInfo();
|
publishNodeInfo();
|
||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#if HAS_NETWORKING
|
#if HAS_NETWORKING
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
#include <memory>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAX_MQTT_QUEUE 16
|
#define MAX_MQTT_QUEUE 16
|
||||||
@ -32,24 +33,7 @@
|
|||||||
*/
|
*/
|
||||||
class MQTT : private concurrency::OSThread
|
class MQTT : private concurrency::OSThread
|
||||||
{
|
{
|
||||||
// supposedly the current version is busted:
|
|
||||||
// http://www.iotsharing.com/2017/08/how-to-use-esp32-mqtts-with-mqtts-mosquitto-broker-tls-ssl.html
|
|
||||||
#if HAS_WIFI
|
|
||||||
WiFiClient mqttClient;
|
|
||||||
#if !defined(ARCH_PORTDUINO)
|
|
||||||
#if (defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR < 3) || defined(RPI_PICO)
|
|
||||||
WiFiClientSecure wifiSecureClient;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if HAS_ETHERNET
|
|
||||||
EthernetClient mqttClient;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if HAS_NETWORKING
|
|
||||||
PubSubClient pubSub;
|
|
||||||
#endif
|
|
||||||
MQTT();
|
MQTT();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +77,29 @@ class MQTT : private concurrency::OSThread
|
|||||||
|
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
|
|
||||||
|
#ifndef PIO_UNIT_TESTING
|
||||||
private:
|
private:
|
||||||
|
#endif
|
||||||
|
// supposedly the current version is busted:
|
||||||
|
// http://www.iotsharing.com/2017/08/how-to-use-esp32-mqtts-with-mqtts-mosquitto-broker-tls-ssl.html
|
||||||
|
#if HAS_WIFI
|
||||||
|
using MQTTClient = WiFiClient;
|
||||||
|
#if !defined(ARCH_PORTDUINO)
|
||||||
|
#if (defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR < 3) || defined(RPI_PICO)
|
||||||
|
WiFiClientSecure wifiSecureClient;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if HAS_ETHERNET
|
||||||
|
using MQTTClient = EthernetClient;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_NETWORKING
|
||||||
|
std::unique_ptr<MQTTClient> mqttClient;
|
||||||
|
PubSubClient pubSub;
|
||||||
|
explicit MQTT(std::unique_ptr<MQTTClient> mqttClient);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string cryptTopic = "/2/e/"; // msh/2/e/CHANNELID/NODEID
|
std::string cryptTopic = "/2/e/"; // msh/2/e/CHANNELID/NODEID
|
||||||
std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID
|
std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID
|
||||||
std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages
|
std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages
|
||||||
|
Loading…
Reference in New Issue
Block a user