diff --git a/Makefile b/Makefile index e2ff47a4a..236667ad7 100644 --- a/Makefile +++ b/Makefile @@ -23,15 +23,17 @@ LIBRARIES := CPPCHECK = cppcheck # CHECKFLAGS = -q --force --std=c++17 -CHECKFLAGS = -q --force --std=c++11 -pthread +CHECKFLAGS = -q --force --std=c++11 #---------------------------------------------------------------------- # Languages Standard #---------------------------------------------------------------------- -# C_STANDARD := -std=c17 +C_STANDARD := -std=c17 # CXX_STANDARD := -std=c++17 -C_STANDARD := -std=c11 -CXX_STANDARD := -std=c++11 +CXX_STANDARD := -std=gnu++17 + +# C_STANDARD := -std=c11 +# CXX_STANDARD := -std=c++11 #---------------------------------------------------------------------- # Defined Symbols @@ -79,7 +81,7 @@ CPPFLAGS += -g3 CPPFLAGS += -Os CFLAGS += $(CPPFLAGS) -CFLAGS += -Wall -Wextra -Werror -Wswitch-enum -Wno-unused-parameter +CFLAGS += -Wall -Wextra -Werror -Wswitch-enum -Wno-unused-parameter -Wno-inconsistent-missing-override -Wno-missing-braces -Wno-unused-lambda-capture CXXFLAGS += $(CFLAGS) -MMD diff --git a/interface/package.json b/interface/package.json index 70b5d9796..08b84ca52 100644 --- a/interface/package.json +++ b/interface/package.json @@ -53,7 +53,7 @@ "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", "cspell": "^6.31.1", - "eslint": "^8.44.0", + "eslint": "^8.45.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb-typescript": "^17.1.0", "eslint-config-prettier": "^8.8.0", diff --git a/interface/yarn.lock b/interface/yarn.lock index 8deea2580..ece5f3f7d 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -1967,7 +1967,7 @@ __metadata: alova: ^2.9.2 async-validator: ^4.2.5 cspell: ^6.31.1 - eslint: ^8.44.0 + eslint: ^8.45.0 eslint-config-airbnb: ^19.0.4 eslint-config-airbnb-typescript: ^17.1.0 eslint-config-prettier: ^8.8.0 @@ -3488,9 +3488,9 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^8.44.0": - version: 8.44.0 - resolution: "eslint@npm:8.44.0" +"eslint@npm:^8.45.0": + version: 8.45.0 + resolution: "eslint@npm:8.45.0" dependencies: "@eslint-community/eslint-utils": ^4.2.0 "@eslint-community/regexpp": ^4.4.0 @@ -3517,7 +3517,6 @@ __metadata: globals: ^13.19.0 graphemer: ^1.4.0 ignore: ^5.2.0 - import-fresh: ^3.0.0 imurmurhash: ^0.1.4 is-glob: ^4.0.0 is-path-inside: ^3.0.3 @@ -3529,11 +3528,10 @@ __metadata: natural-compare: ^1.4.0 optionator: ^0.9.3 strip-ansi: ^6.0.1 - strip-json-comments: ^3.1.0 text-table: ^0.2.0 bin: eslint: bin/eslint.js - checksum: a31ca4571a67012629936d891141a4a5747d5902fb7f4e10119a5acd632e0976b9ba1b761d8c81cff8a9cc3e796df2c56f86c02535fd977de962a98ce585624a + checksum: 2a043b8d3b9a5684e2f66bd446c3dc8522cc7afbb0982d0a5be76ea1f578d0e617598a7b289616a861ab8272b57f6056acb2b264bec6302c9b0921a1cfa66fdb languageName: node linkType: hard @@ -4254,7 +4252,7 @@ __metadata: languageName: node linkType: hard -"import-fresh@npm:^3.0.0, import-fresh@npm:^3.2.1, import-fresh@npm:^3.3.0": +"import-fresh@npm:^3.2.1, import-fresh@npm:^3.3.0": version: 3.3.0 resolution: "import-fresh@npm:3.3.0" dependencies: @@ -6406,7 +6404,7 @@ __metadata: languageName: node linkType: hard -"strip-json-comments@npm:^3.1.0, strip-json-comments@npm:^3.1.1": +"strip-json-comments@npm:^3.1.1": version: 3.1.1 resolution: "strip-json-comments@npm:3.1.1" checksum: 9681a6257b925a7fa0f285851c0e613cc934a50661fa7bb41ca9cbbff89686bb4a0ee366e6ecedc4daafd01e83eee0720111ab294366fe7c185e935475ebcecd diff --git a/lib/espMqttClient/src/Transport/ClientPosix.cpp b/lib/espMqttClient/src/Transport/ClientPosix.cpp index 83b555d1b..76ea5649f 100644 --- a/lib/espMqttClient/src/Transport/ClientPosix.cpp +++ b/lib/espMqttClient/src/Transport/ClientPosix.cpp @@ -13,80 +13,81 @@ the LICENSE file. namespace espMqttClientInternals { ClientPosix::ClientPosix() -: _sockfd(-1) -, _host() { - // empty + : _sockfd(-1) + , _host() { + // empty } ClientPosix::~ClientPosix() { - ClientPosix::stop(); + ClientPosix::stop(); } bool ClientPosix::connect(IPAddress ip, uint16_t port) { - if (connected()) stop(); + if (connected()) + stop(); - _sockfd = ::socket(AF_INET, SOCK_STREAM, 0); - if (_sockfd < 0) { - emc_log_e("Error %d opening socket", errno); - } + _sockfd = ::socket(AF_INET, SOCK_STREAM, 0); + if (_sockfd < 0) { + emc_log_e("Error %d opening socket", errno); + } - int flag = 1; - if (setsockopt(_sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) < 0) { - emc_log_e("Error %d disabling nagle", errno); - } + int flag = 1; + if (setsockopt(_sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) < 0) { + emc_log_e("Error %d disabling nagle", errno); + } - memset(&_host, 0, sizeof(_host)); - _host.sin_family = AF_INET; - _host.sin_addr.s_addr = htonl(uint32_t(ip)); - _host.sin_port = ::htons(port); + memset(&_host, 0, sizeof(_host)); + _host.sin_family = AF_INET; + _host.sin_addr.s_addr = htonl(uint32_t(ip)); + _host.sin_port = htons(port); - int ret = ::connect(_sockfd, (struct sockaddr *)&_host, sizeof(_host)); + int ret = ::connect(_sockfd, (struct sockaddr *)&_host, sizeof(_host)); - if (ret < 0) { - emc_log_e("Error connecting: %d - (%d) %s", ret, errno, strerror(errno)); + if (ret < 0) { + emc_log_e("Error connecting: %d - (%d) %s", ret, errno, strerror(errno)); + return false; + } + + emc_log_i("Connected"); + return true; +} + +bool ClientPosix::connect(const char * host, uint16_t port) { + // tbi + (void)host; + (void)port; return false; - } - - emc_log_i("Connected"); - return true; } -bool ClientPosix::connect(const char* host, uint16_t port) { - // tbi - (void) host; - (void) port; - return false; +size_t ClientPosix::write(const uint8_t * buf, size_t size) { + return ::send(_sockfd, buf, size, 0); } -size_t ClientPosix::write(const uint8_t* buf, size_t size) { - return ::send(_sockfd, buf, size, 0); -} - -int ClientPosix::read(uint8_t* buf, size_t size) { - int ret = ::recv(_sockfd, buf, size, MSG_DONTWAIT); - /* +int ClientPosix::read(uint8_t * buf, size_t size) { + int ret = ::recv(_sockfd, buf, size, MSG_DONTWAIT); + /* if (ret < 0) { emc_log_e("Error reading: %s", strerror(errno)); } */ - return ret; + return ret; } void ClientPosix::stop() { - if (_sockfd >= 0) { - ::close(_sockfd); - _sockfd = -1; - } + if (_sockfd >= 0) { + ::close(_sockfd); + _sockfd = -1; + } } bool ClientPosix::connected() { - return _sockfd >= 0; + return _sockfd >= 0; } bool ClientPosix::disconnected() { - return _sockfd < 0; + return _sockfd < 0; } -} // namespace espMqttClientInternals +} // namespace espMqttClientInternals #endif diff --git a/platformio.ini b/platformio.ini index 4b9a078cb..7e72571b5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -144,12 +144,13 @@ build_flags = ${common.build_flags} -O2 platform = native build_flags = -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_PROGMEM=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0 - -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST + -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST -D__linux__ -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.6.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" -lpthread - -std=gnu++11 -Og -ggdb + -std=gnu++17 -Og -ggdb build_src_flags = -Wall -Wextra -Werror -Wswitch-enum -Wno-unused-parameter -Wno-inconsistent-missing-override -Wno-unused-lambda-capture + -Wno-missing-braces -I./lib_standalone -I./lib/ArduinoJson/src -I./lib/uuid-common/src diff --git a/src/mqtt.cpp b/src/mqtt.cpp index ef2f4d061..f3a4cdfcb 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -210,13 +210,18 @@ void Mqtt::incoming(const char * topic, const char * payload) { // received an MQTT message that we subscribed too // topic is the full path // payload is json or a single string and converted to a json with key 'value' -void Mqtt::on_message(const char * topic, const char * payload, size_t len) const { +void Mqtt::on_message(const char * topic, const char * message, size_t len) const { + // This causes a compile error "error: variable-sized object may not be initialized" + // so commenting out and assuming with the new mqtt lib it's always null terminated + + /* // sometimes the payload is not terminated correctly, so make a copy // convert payload to a null-terminated char string char message[len + 2] = {'\0'}; if (payload != nullptr) { strlcpy(message, payload, len + 1); } + */ #if defined(EMSESP_DEBUG) if (len) { diff --git a/src/mqtt.h b/src/mqtt.h index dc530c25c..edc4377a9 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -251,7 +251,7 @@ class Mqtt { static std::vector mqtt_subfunctions_; // list of mqtt subscribe callbacks for all devices - uint32_t last_mqtt_poll_ = 0; + // uint32_t last_mqtt_poll_ = 0; uint32_t last_publish_boiler_ = 0; uint32_t last_publish_thermostat_ = 0; uint32_t last_publish_solar_ = 0; @@ -259,7 +259,7 @@ class Mqtt { uint32_t last_publish_other_ = 0; uint32_t last_publish_sensor_ = 0; uint32_t last_publish_heartbeat_ = 0; - uint32_t last_publish_queue_ = 0; + // uint32_t last_publish_queue_ = 0; static bool connecting_; static bool initialized_;