get standadlone working with espMqttClient

This commit is contained in:
Proddy
2023-07-14 12:11:48 +02:00
parent 1b623014c1
commit f3d3a386ee
5 changed files with 33 additions and 18 deletions

View File

@@ -23,7 +23,7 @@ LIBRARIES :=
CPPCHECK = cppcheck CPPCHECK = cppcheck
# CHECKFLAGS = -q --force --std=c++17 # CHECKFLAGS = -q --force --std=c++17
CHECKFLAGS = -q --force --std=c++11 CHECKFLAGS = -q --force --std=c++11 -pthread
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# Languages Standard # Languages Standard
@@ -37,7 +37,7 @@ CXX_STANDARD := -std=c++11
# Defined Symbols # Defined Symbols
#---------------------------------------------------------------------- #----------------------------------------------------------------------
DEFINES += -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_PROGMEM=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0 DEFINES += -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_PROGMEM=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0
DEFINES += -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST -D__linux__ DEFINES += -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST -D__linux__ -DEMC_RX_BUFFER_SIZE=1500
DEFINES += $(ARGS) DEFINES += $(ARGS)
DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.6.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.6.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\"

View File

@@ -21,6 +21,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <iostream>
#include <thread>
#include <atomic>
#include <string> #include <string>
#include <Network.h> #include <Network.h>
@@ -43,12 +47,28 @@ static unsigned long __millis = 0;
static bool __output_pins[256]; static bool __output_pins[256];
static int __output_level[256]; static int __output_level[256];
std::atomic_bool exitProgram(false);
void ClientLoop(void * arg) {
(void)arg;
for (;;) {
loop();
if (exitProgram)
break;
}
}
int main(int argc __attribute__((unused)), char * argv[] __attribute__((unused))) { int main(int argc __attribute__((unused)), char * argv[] __attribute__((unused))) {
setup(); setup();
while (millis() <= 10 * 1000) { std::thread t = std::thread(ClientLoop, nullptr);
loop(); // while (millis() <= 10 * 1000) {
while (1) {
if (exitProgram)
break;
std::this_thread::yield();
} }
return 0; t.join();
return EXIT_SUCCESS;
} }
// unsigned long millis() { // unsigned long millis() {
@@ -64,6 +84,7 @@ void delay(unsigned long millis) {
} }
void yield(void) { void yield(void) {
std::this_thread::yield();
} }
int snprintf_P(char * str, size_t size, const char * format, ...) { int snprintf_P(char * str, size_t size, const char * format, ...) {

View File

@@ -101,7 +101,10 @@ class ESP8266React {
: _settings(server, fs, nullptr) : _settings(server, fs, nullptr)
, _securitySettingsService(server, fs){}; , _securitySettingsService(server, fs){};
void begin(){}; void begin() {
// initialize mqtt
_mqttClient = new espMqttClient();
};
void loop(){}; void loop(){};
SecurityManager * getSecurityManager() { SecurityManager * getSecurityManager() {

View File

@@ -393,12 +393,6 @@ void Mqtt::start() {
[this](const espMqttClientTypes::MessageProperties & properties, const char * topic, const uint8_t * payload, size_t len, size_t index, size_t total) { [this](const espMqttClientTypes::MessageProperties & properties, const char * topic, const uint8_t * payload, size_t len, size_t index, size_t total) {
on_message(topic, (const char *)payload, len); // receiving mqtt on_message(topic, (const char *)payload, len); // receiving mqtt
}); });
/*
mqttClient_->onPublish([this](uint16_t packetId) {
on_publish(packetId); // publish
});
*/
} }
void Mqtt::set_publish_time_boiler(uint16_t publish_time) { void Mqtt::set_publish_time_boiler(uint16_t publish_time) {
@@ -588,9 +582,10 @@ void Mqtt::ha_status() {
// add sub or pub task to the queue. // add sub or pub task to the queue.
// the base is not included in the topic // the base is not included in the topic
bool Mqtt::queue_message(const uint8_t operation, const std::string & topic, const std::string & payload, const bool retain) { bool Mqtt::queue_message(const uint8_t operation, const std::string & topic, const std::string & payload, const bool retain) {
if (topic.empty()) { if (!mqtt_enabled_ || topic.empty()) {
return false; return false; // quit, not using MQTT
} }
uint16_t packet_id = 0; uint16_t packet_id = 0;
char fulltopic[MQTT_TOPIC_MAX_SIZE]; char fulltopic[MQTT_TOPIC_MAX_SIZE];

View File

@@ -104,11 +104,7 @@ class Mqtt {
#endif #endif
static bool connected() { static bool connected() {
#if defined(EMSESP_STANDALONE)
return true;
#else
return mqttClient_->connected(); return mqttClient_->connected();
#endif
} }
static MqttClient * client() { static MqttClient * client() {