diff --git a/Makefile b/Makefile index e911b4558..e2ff47a4a 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ LIBRARIES := CPPCHECK = cppcheck # CHECKFLAGS = -q --force --std=c++17 -CHECKFLAGS = -q --force --std=c++11 +CHECKFLAGS = -q --force --std=c++11 -pthread #---------------------------------------------------------------------- # Languages Standard @@ -37,7 +37,7 @@ CXX_STANDARD := -std=c++11 # Defined Symbols #---------------------------------------------------------------------- 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) DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.6.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" diff --git a/lib_standalone/Arduino.cpp b/lib_standalone/Arduino.cpp index 34194b2d7..2afc4e78f 100644 --- a/lib_standalone/Arduino.cpp +++ b/lib_standalone/Arduino.cpp @@ -21,6 +21,10 @@ #include #include +#include +#include +#include + #include #include @@ -43,12 +47,28 @@ static unsigned long __millis = 0; static bool __output_pins[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))) { setup(); - while (millis() <= 10 * 1000) { - loop(); + std::thread t = std::thread(ClientLoop, nullptr); + // while (millis() <= 10 * 1000) { + while (1) { + if (exitProgram) + break; + std::this_thread::yield(); } - return 0; + t.join(); + return EXIT_SUCCESS; } // unsigned long millis() { @@ -64,6 +84,7 @@ void delay(unsigned long millis) { } void yield(void) { + std::this_thread::yield(); } int snprintf_P(char * str, size_t size, const char * format, ...) { diff --git a/lib_standalone/ESP8266React.h b/lib_standalone/ESP8266React.h index e5d8e5b02..34552fa01 100644 --- a/lib_standalone/ESP8266React.h +++ b/lib_standalone/ESP8266React.h @@ -101,7 +101,10 @@ class ESP8266React { : _settings(server, fs, nullptr) , _securitySettingsService(server, fs){}; - void begin(){}; + void begin() { + // initialize mqtt + _mqttClient = new espMqttClient(); + }; void loop(){}; SecurityManager * getSecurityManager() { diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 99f7c1886..e3eec030b 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -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) { 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) { @@ -588,9 +582,10 @@ void Mqtt::ha_status() { // add sub or pub task to the queue. // 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) { - if (topic.empty()) { - return false; + if (!mqtt_enabled_ || topic.empty()) { + return false; // quit, not using MQTT } + uint16_t packet_id = 0; char fulltopic[MQTT_TOPIC_MAX_SIZE]; diff --git a/src/mqtt.h b/src/mqtt.h index ac3c1effe..15e87f8ca 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -104,11 +104,7 @@ class Mqtt { #endif static bool connected() { -#if defined(EMSESP_STANDALONE) - return true; -#else return mqttClient_->connected(); -#endif } static MqttClient * client() {