From 81d75e195574768a2acb5ad181ca998377aafee2 Mon Sep 17 00:00:00 2001 From: Francois <thiebolt@irit.fr> Date: Mon, 22 Jan 2024 21:33:54 +0100 Subject: [PATCH] update --- git-push.sh | 86 +++++- neosensor/libraries/ArduinoJson/CHANGELOG.md | 7 + .../libraries/ArduinoJson/CMakeLists.txt | 2 +- neosensor/libraries/ArduinoJson/README.md | 6 +- neosensor/libraries/ArduinoJson/appveyor.yml | 2 +- .../scripts/wandbox/JsonGeneratorExample.cpp | 5 - .../extras/tests/Cpp17/string_view.cpp | 14 +- .../extras/tests/JsonVariant/converters.cpp | 11 + .../extras/tests/Misc/CMakeLists.txt | 1 + .../extras/tests/Misc/issue1967.cpp | 13 + .../libraries/ArduinoJson/idf_component.yml | 2 +- neosensor/libraries/ArduinoJson/library.json | 2 +- .../libraries/ArduinoJson/library.properties | 2 +- .../Strings/Adapters/RamString.hpp | 3 +- .../src/ArduinoJson/Variant/ConverterImpl.hpp | 8 + .../ArduinoJson/Variant/VariantRefBase.hpp | 3 +- .../ArduinoJson/src/ArduinoJson/version.hpp | 6 +- neosensor/libraries/boards/neosensor.h | 2 +- .../libraries/neocampus/neocampus_comm.cpp | 247 ------------------ .../libraries/neocampus/neocampus_comm.h | 107 -------- neosensor/neosensor.ino | 6 +- 21 files changed, 156 insertions(+), 379 deletions(-) create mode 100644 neosensor/libraries/ArduinoJson/extras/tests/Misc/issue1967.cpp delete mode 100644 neosensor/libraries/neocampus/neocampus_comm.cpp delete mode 100644 neosensor/libraries/neocampus/neocampus_comm.h diff --git a/git-push.sh b/git-push.sh index 5a2fe163..59c7546a 100755 --- a/git-push.sh +++ b/git-push.sh @@ -1,20 +1,102 @@ #!/bin/bash # -# Simple helper script ;) +# Simple GIT-PUSH helper script ;) +# === +# Notes: +# === +# TODO: +# - regex with tokens to get taken into account +# === +# F.Thiebolt jan.24 removed git commit check return value (e.g nothing mode to commit) +# corrected typo 'bibucket' --> 'bitbucket' ! +# corrected check against *bitbucket* (instead of bitbucket*) +# F.Thiebolt sep.23 adaptation to gitlab URLs +# now differentiating push origin URL :D +# F.Thiebolt 2016 initial release # +_SCRIPTREV="240122" + +#DEBUG=1 + +# Debug +if [ ${DEBUG:-0} -eq 1 ]; then + exec &> >(tee -a /tmp/$(basename ${BASH_SOURCE[0]}).log) + echo -e "\n--- $(date +"%d-%m-%Y %H:%M") --- $(basename ${BASH_SOURCE[0]}) ----------------------------------------------" + echo -e "Nb input params = $#, \$1='$1', \$2='$2'" + env + echo -e "" + # enable trace mode + set -x +fi + + +echo -e "#\n#\tGIT-PUSH | push script revision ${_SCRIPTREV:-'unknown'}\n#" + if [ "$#" == "0" ]; then msg='update' else msg="$@" fi -#set -x # [dec.22] removed StrictHostKey checking export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" +# https://serverfault.com/questions/417241/extract-repository-name-from-github-url-in-bash +re="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+)(.git)*$" +if [[ $(git config --local remote.origin.url) =~ $re ]]; then + _protocol=${BASH_REMATCH[1]} + _separator=${BASH_REMATCH[2]} + _hostname=${BASH_REMATCH[3]} + _user=${BASH_REMATCH[4]} + _repo=${BASH_REMATCH[5]} +fi + +_git_username=${GIT_DEPLOY_USERNAME} +_git_token=${GIT_DEPLOY_TOKEN} +_git_hostname=$(git config --local remote.origin.url|sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/') +#_git_hostname=${_hostname} +_git_path=${_repo} +_git_remote_url="https://${_git_hostname}/${_git_path}" +#_git_remote_url="https://${_git_username}:${_git_token}@${_git_hostname}/${_git_path}" + +[ ${DEBUG:-0} -eq 1 ] && { env; } + + +# +# set remote url +# - bitbucket with ssh +# - gitlab with or without username specified +if [[ ${_protocol} == http* && ${_hostname} != *bitbucket* ]]; then + if [[ ${_hostname} == gitlab* ]]; then + # url is probably of type https://gitlab.irit.fr/gis-neocampus/datalake/docker_datalake + # thus DO NOT CHANGE remote url ! + echo -e "Gitlab url detected '$(git config --local remote.origin.url)'\n\twithout user specified ... thus nothing to change!" + else + echo -e "\n\tset git push remote url to '${_git_remote_url}' ..." + git remote set-url --push origin ${_git_remote_url} + [ $? -ne 0 ] && { echo -e "\n###ERROR: unable to set GIT remote url for repository '${_git_remote_url}' !!" >&2; exit 1; } + fi +fi + + git add --all +res=$? +[ $res -ne 0 ] && { echo -e "\n### git add ERROR code '$res' from REPO '$(git config --local remote.origin.url)' !" >&2; exit 1; } git commit -a -m "${msg}" +#res=$? +#[ $res -ne 0 ] && { echo -e "\n### git commit ERROR '$res' from REPO '$(git config --local remote.origin.url)' !" >&2; exit 1; } git push +res=$? +[ $res -ne 0 ] && { echo -e "\n### git push ERROR '$res' from REPO '$(git config --local remote.origin.url)' !" >&2; exit 1; } + + +# Debug +if [ ${DEBUG:-0} -eq 1 ]; then + echo -e "--- $(date +"%d-%m-%Y %H:%M") -----------------------------------------------------------\n" + # disable trace mode + set +x +fi + diff --git a/neosensor/libraries/ArduinoJson/CHANGELOG.md b/neosensor/libraries/ArduinoJson/CHANGELOG.md index 28c506ab..477e6fda 100644 --- a/neosensor/libraries/ArduinoJson/CHANGELOG.md +++ b/neosensor/libraries/ArduinoJson/CHANGELOG.md @@ -1,6 +1,13 @@ ArduinoJson: change log ======================= +v6.21.4 (2023-12-07) +------- + +* Fix error `'std::string' has not been declared` (issue #1967) +* Fix error `'std::string_view' has not been declared` (issue #1967) +* Fix error `no instance of overloaded function...` on recent IAR compilers (issue #2001) + v6.21.3 (2023-07-23) ------- diff --git a/neosensor/libraries/ArduinoJson/CMakeLists.txt b/neosensor/libraries/ArduinoJson/CMakeLists.txt index a79bc663..e1330235 100644 --- a/neosensor/libraries/ArduinoJson/CMakeLists.txt +++ b/neosensor/libraries/ArduinoJson/CMakeLists.txt @@ -10,7 +10,7 @@ if(ESP_PLATFORM) return() endif() -project(ArduinoJson VERSION 6.21.3) +project(ArduinoJson VERSION 6.21.4) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(CTest) diff --git a/neosensor/libraries/ArduinoJson/README.md b/neosensor/libraries/ArduinoJson/README.md index 16d93a3a..42e9bf7f 100644 --- a/neosensor/libraries/ArduinoJson/README.md +++ b/neosensor/libraries/ArduinoJson/README.md @@ -8,9 +8,9 @@ [](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) [](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[](https://www.ardu-badge.com/ArduinoJson/6.21.3) -[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.3) -[](https://components.espressif.com/components/bblanchon/arduinojson) +[](https://www.ardu-badge.com/ArduinoJson/6.21.4) +[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.4) +[](https://components.espressif.com/components/bblanchon/arduinojson) [](https://github.com/bblanchon/ArduinoJson/stargazers) [](https://github.com/sponsors/bblanchon) diff --git a/neosensor/libraries/ArduinoJson/appveyor.yml b/neosensor/libraries/ArduinoJson/appveyor.yml index 4a9789be..eb6d7bdd 100644 --- a/neosensor/libraries/ArduinoJson/appveyor.yml +++ b/neosensor/libraries/ArduinoJson/appveyor.yml @@ -1,4 +1,4 @@ -version: 6.21.3.{build} +version: 6.21.4.{build} environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 diff --git a/neosensor/libraries/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp b/neosensor/libraries/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp index b35d1856..474a0c30 100644 --- a/neosensor/libraries/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp +++ b/neosensor/libraries/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp @@ -20,11 +20,6 @@ int main() { // // DynamicJsonDocument doc(200); - // StaticJsonObject allocates memory on the stack, it can be - // replaced by DynamicJsonDocument which allocates in the heap. - // - // DynamicJsonDocument doc(200); - // Add values in the document // doc["sensor"] = "gps"; diff --git a/neosensor/libraries/ArduinoJson/extras/tests/Cpp17/string_view.cpp b/neosensor/libraries/ArduinoJson/extras/tests/Cpp17/string_view.cpp index 6a51ce2d..7ef65626 100644 --- a/neosensor/libraries/ArduinoJson/extras/tests/Cpp17/string_view.cpp +++ b/neosensor/libraries/ArduinoJson/extras/tests/Cpp17/string_view.cpp @@ -1,8 +1,16 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include <string_view> +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STD_STRING 0 + #include <ArduinoJson.h> #include <catch.hpp> -#include <string_view> - #if !ARDUINOJSON_ENABLE_STRING_VIEW # error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1 #endif @@ -19,7 +27,7 @@ TEST_CASE("string_view") { SECTION("JsonDocument::set()") { doc.set(std::string_view("123", 2)); - REQUIRE(doc.as<std::string>() == "12"); + REQUIRE(doc.as<std::string_view>() == "12"); } SECTION("JsonDocument::operator[]() const") { diff --git a/neosensor/libraries/ArduinoJson/extras/tests/JsonVariant/converters.cpp b/neosensor/libraries/ArduinoJson/extras/tests/JsonVariant/converters.cpp index cd4e7c21..89afc9b7 100644 --- a/neosensor/libraries/ArduinoJson/extras/tests/JsonVariant/converters.cpp +++ b/neosensor/libraries/ArduinoJson/extras/tests/JsonVariant/converters.cpp @@ -158,6 +158,11 @@ void convertToJson(char c, JsonVariant var) { char buf[] = {c, 0}; var.set(buf); } + +void convertFromJson(JsonVariantConst src, char& dst) { + auto p = src.as<const char*>(); + dst = p ? p[0] : 0; +} } // namespace ArduinoJson TEST_CASE("Convert char to string") { // issue #1922 @@ -165,3 +170,9 @@ TEST_CASE("Convert char to string") { // issue #1922 doc.set('a'); REQUIRE(doc.as<std::string>() == "a"); } + +TEST_CASE("Convert string to char") { // issue #1963 + StaticJsonDocument<64> doc; + doc.set("a"); + REQUIRE(doc.as<char>() == 'a'); +} diff --git a/neosensor/libraries/ArduinoJson/extras/tests/Misc/CMakeLists.txt b/neosensor/libraries/ArduinoJson/extras/tests/Misc/CMakeLists.txt index 5655a089..3a1eb898 100644 --- a/neosensor/libraries/ArduinoJson/extras/tests/Misc/CMakeLists.txt +++ b/neosensor/libraries/ArduinoJson/extras/tests/Misc/CMakeLists.txt @@ -6,6 +6,7 @@ add_executable(MiscTests arithmeticCompare.cpp conflicts.cpp FloatParts.cpp + issue1967.cpp JsonString.cpp NoArduinoHeader.cpp printable.cpp diff --git a/neosensor/libraries/ArduinoJson/extras/tests/Misc/issue1967.cpp b/neosensor/libraries/ArduinoJson/extras/tests/Misc/issue1967.cpp new file mode 100644 index 00000000..a8d6b948 --- /dev/null +++ b/neosensor/libraries/ArduinoJson/extras/tests/Misc/issue1967.cpp @@ -0,0 +1,13 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include <string> +#define ARDUINOJSON_ENABLE_STD_STRING 1 + +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STRING_VIEW 0 + +#include <ArduinoJson.h> diff --git a/neosensor/libraries/ArduinoJson/idf_component.yml b/neosensor/libraries/ArduinoJson/idf_component.yml index 51be4722..823d237d 100644 --- a/neosensor/libraries/ArduinoJson/idf_component.yml +++ b/neosensor/libraries/ArduinoJson/idf_component.yml @@ -1,4 +1,4 @@ -version: "6.21.3" +version: "6.21.4" description: >- A simple and efficient JSON library for embedded C++. ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. diff --git a/neosensor/libraries/ArduinoJson/library.json b/neosensor/libraries/ArduinoJson/library.json index 9b5d7df4..6d235477 100644 --- a/neosensor/libraries/ArduinoJson/library.json +++ b/neosensor/libraries/ArduinoJson/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/bblanchon/ArduinoJson.git" }, - "version": "6.21.3", + "version": "6.21.4", "authors": { "name": "Benoit Blanchon", "url": "https://blog.benoitblanchon.fr" diff --git a/neosensor/libraries/ArduinoJson/library.properties b/neosensor/libraries/ArduinoJson/library.properties index 6a285cf0..b3dfb40e 100644 --- a/neosensor/libraries/ArduinoJson/library.properties +++ b/neosensor/libraries/ArduinoJson/library.properties @@ -1,5 +1,5 @@ name=ArduinoJson -version=6.21.3 +version=6.21.4 author=Benoit Blanchon <blog.benoitblanchon.fr> maintainer=Benoit Blanchon <blog.benoitblanchon.fr> sentence=A simple and efficient JSON library for embedded C++. diff --git a/neosensor/libraries/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamString.hpp b/neosensor/libraries/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamString.hpp index 12c67c94..0fa2d5be 100644 --- a/neosensor/libraries/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamString.hpp +++ b/neosensor/libraries/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamString.hpp @@ -8,6 +8,7 @@ #include <string.h> // strcmp #include <ArduinoJson/Polyfills/assert.hpp> +#include <ArduinoJson/Polyfills/attributes.hpp> #include <ArduinoJson/Strings/StoragePolicy.hpp> #include <ArduinoJson/Strings/StringAdapter.hpp> @@ -27,7 +28,7 @@ class ZeroTerminatedRamString { return !str_; } - size_t size() const { + FORCE_INLINE size_t size() const { return str_ ? ::strlen(str_) : 0; } diff --git a/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp b/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp index e95b33e5..0708f52f 100644 --- a/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp +++ b/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp @@ -8,6 +8,14 @@ #include <ArduinoJson/Variant/JsonVariantConst.hpp> #include <ArduinoJson/Variant/VariantFunctions.hpp> +#if ARDUINOJSON_ENABLE_STD_STRING +# include <string> +#endif + +#if ARDUINOJSON_ENABLE_STRING_VIEW +# include <string_view> +#endif + ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE template <typename T, typename Enable> diff --git a/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp b/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp index 2afdda6a..321aca09 100644 --- a/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp +++ b/neosensor/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp @@ -61,7 +61,8 @@ class VariantRefBase : public VariantTag { return Converter<T>::fromJson(getVariant()); } - template <typename T> + template <typename T, + typename = typename enable_if<!is_same<T, TDerived>::value>::type> FORCE_INLINE operator T() const { return as<T>(); } diff --git a/neosensor/libraries/ArduinoJson/src/ArduinoJson/version.hpp b/neosensor/libraries/ArduinoJson/src/ArduinoJson/version.hpp index 5e6500a4..d0c30aad 100644 --- a/neosensor/libraries/ArduinoJson/src/ArduinoJson/version.hpp +++ b/neosensor/libraries/ArduinoJson/src/ArduinoJson/version.hpp @@ -4,8 +4,8 @@ #pragma once -#define ARDUINOJSON_VERSION "6.21.3" +#define ARDUINOJSON_VERSION "6.21.4" #define ARDUINOJSON_VERSION_MAJOR 6 #define ARDUINOJSON_VERSION_MINOR 21 -#define ARDUINOJSON_VERSION_REVISION 3 -#define ARDUINOJSON_VERSION_MACRO V6213 +#define ARDUINOJSON_VERSION_REVISION 4 +#define ARDUINOJSON_VERSION_MACRO V6214 diff --git a/neosensor/libraries/boards/neosensor.h b/neosensor/libraries/boards/neosensor.h index a6357ca7..3c008c1b 100644 --- a/neosensor/libraries/boards/neosensor.h +++ b/neosensor/libraries/boards/neosensor.h @@ -44,7 +44,7 @@ */ #define BOARD_NAME "neOSensor" #define BOARD_REVISION 1.2 -#define BOARD_FWREV 231027 // Firmware revision <year><month><day> in 2 digits each +#define BOARD_FWREV 231216 // Firmware revision <year><month><day> in 2 digits each diff --git a/neosensor/libraries/neocampus/neocampus_comm.cpp b/neosensor/libraries/neocampus/neocampus_comm.cpp deleted file mode 100644 index 6f3f488f..00000000 --- a/neosensor/libraries/neocampus/neocampus_comm.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* - * neOCampus operation - * - * MQTT client class. - * This class leverage the needs for a single MQTT(s) connection shared across - * various clients that can register a specific callback for each topic. - * - * --- - * TODO: - * - - * - * --- - * F.Thiebolt apr.21 added MQTT client settings through API (buffer_size, - * socker_timeout ...) - * F.Thiebolt aug.20 set MQTT comm class as an independant module in order to - * manage a single TCP(s) connexion with the MQTT server. - * Thiebolt F. July 17 - * - */ - - -/* - * Includes - */ -#include "neocampus.h" -#include "neocampus_comm.h" -#include "neocampus_utils.h" -#include "neocampus_debug.h" - -//#include "modulesMgt.h" - - -/* - * Global shared variables/functions - */ - - - -/* - * Definitions - */ - - - -// constructor -comm::comm( void ) { - - // call low-level base constructor - _comm(); -} - -// low-level base constructor -void comm::_comm( void ) { - _sensoClient = nullptr; -} - - -/* - * MQTT communications startup procedure - */ -boolean comm::start( senso *sensocampus ) { - - if( not sensocampus ) return false; - - bool _ret; - - // save pointer to sensOCampus object - _sensoClient = sensocampus; - - // configure MQTT client - mqttClient.setClient( _wifiClient ); - mqttClient.setServer( _sensoClient->getServer(), _sensoClient->getServerPort() ); - mqttClient.setCallback( [this] (char* topic, byte* payload, unsigned int length) { this->callback(topic, payload, length); }); - - // [apr.21] MQTT settings - mqttClient.setBufferSize(MQTT_MAX_PACKET_SIZE); - mqttClient.setKeepAlive(MQTT_KEEPALIVE); - mqttClient.setSocketTimeout(MQTT_SOCKET_TIMEOUT); - - // launch MQTT connexion + subscriptions + ... - _ret = this->reConnect(); - - return _ret; -} - -/* - * Module stop MQTT, save config (if any) and clean things - */ -boolean comm::stop( void ) { - bool _ret = true; - - if( mqttClient.connected() ) { -/* - // unsubscribe - log_info(F("\n\t[comm] unsubscribe from topic: ")); log_info(subTopic); - _ret = mqttClient.unsubscribe( subTopic ); - if( _ret ) { - log_info(F("\n\t[comm] topic successfully unsubscribed :)")); - } -*/ - // Stop MQTT connexion - log_info(F("\n\t[comm] disconnect from MQTT server ... ")); - mqttClient.disconnect(); - } - else { - log_info(F("\n\t[comm] stop module while mqtt not connected ... ")); - } - - log_flush(); - - return _ret; -} - -/* - * Callback: start processing MQTT messages received from broker - */ -void comm::callback(char* topic, byte* payload, unsigned int length) { -#if 0 - -TODO later - - // verify that topic matches the subscribed one - if( strncmp(topic, subTopic, strlen(subTopic)) ) { - log_error(F("\n[base][callback] unknwown topic: ")); log_debug(topic); log_flush(); - return; - } - - // does it matches our ID (i.e dest == "all" or dest == <unitID>) - StaticJsonDocument<COMMAND_JSON_SIZE> root; - - auto err = deserializeJson( root, payload ); - if( err ) { - log_error(F("\n[base][callback] ERROR parsing JSON payload @ callback: "));log_error(err.c_str()); log_flush(); - return; - } - - // check for destID field - if( (root.containsKey(F("dest"))==false) ) { - log_error(F("\n[base][callback] ERROR no 'dest' field' in JSON payload @ callback ?!?!")); - return; - } - /* ok, there's a dest, does it matches us - * (i.e dest='all' or dest=<our unitID> ??) - */ - // warning, we have a pointer to an inner part of a json message ... - char *_dest = (char*)(root[F("dest")].as<char*>()); - // ... then convert to lowercase :) - for( uint8_t i=0; i<strlen(_dest); i++ ) _dest[i] = tolower(_dest[i]); - - const char *generic_dest = PSTR("all"); - if( strncmp_P(_dest, generic_dest, strlen_P(generic_dest))!=0 and - strncmp(_dest, unitID, strlen(unitID))!=0 ) { - - // not for us - return; - } - - // call handler - handle_msg( root.as<JsonObject>() ); -#endif -} - - -/* - * reConnect - */ -boolean comm::reConnect( void ) { - // compute MQTT clientID - String clientID; - clientID += getAPname(); - clientID += "_"; - clientID += String(micros() & 0xffff, HEX); - //clientID += String(random(0xffff), HEX); - - log_info(F("\n\t[comm] (re)connect to MQTT server with CID = ")); log_debug(clientID.c_str()); log_flush(); - - // Loop until we're reconnected - uint8_t _retry=MQTT_CONNECT_MAX_RETRIES; - while( !mqttClient.connected() ) { - - if( mqttClient.connect( (char*)clientID.c_str(), _sensoClient->getUser(), _sensoClient->getPassword() ) ) { - yield(); - - // success :) - log_debug(F("\n\t[comm] connected :)")); - - // Once connected, publish an announcement... - //ret = mqttClient.publish("outTopic", "hello world"); - yield(); -#if 0 -TODO: subscriptions - // ... and resubscribe - bool _ret = mqttClient.subscribe( subTopic ); - yield(); - if( _ret ) { - log_debug(F("\n\t[comm] topic subscribed: ")); log_debug( subTopic ); log_flush(); - } - else { - // we continue even upon a subscribe failure - log_error(F("\n\t[comm] ERROR unable to subscribe to topic: ")); log_error( subTopic ); log_flush(); - } -#endif - } - else { - - // failure :( - log_error(F("\n\t[comm] connect failed with rc = ")); - log_error(mqttClient.state(),DEC); - - if( _retry-- ) { - log_debug(F("\n\t\t... sleeping a bit before retrying ...")); - delay((MQTT_CONNECT_MAX_RETRIES-_retry)*10*1000); - } - else { - log_error(F("\n\t[comm] ERROR no more retries to connect with MQTT broker ... reboot")); - _need2reboot = true; - return false; - } - } - } - - return true; -} - - -/* - * loop to process module's messages requiring callback call - */ -boolean comm::process( void ) { - - bool _ret; - - // check we're already connected - if( !mqttClient.connected() ) { - // if reconnect fails ESP will reboot so ne need to check return value - reConnect(); - } - - // MQTT client loop() to process messages requiring handler to get called - _ret = mqttClient.loop(); - - if( !_ret ) { - log_error(F("\n[comm] ERROR process() with rcState = ")); log_error(mqttClient.state(),DEC);log_flush(); - } - - return _ret; -} diff --git a/neosensor/libraries/neocampus/neocampus_comm.h b/neosensor/libraries/neocampus/neocampus_comm.h deleted file mode 100644 index 4c0d3aed..00000000 --- a/neosensor/libraries/neocampus/neocampus_comm.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * neOCampus operation - * - * MQTT client class. - * This class leverage the needs for a single MQTT(s) connection shared across - * various clients that can register a specific callback for each topic. - * - * --- - * TODO: - * - - * - * --- - * F.Thiebolt apr.21 changed BASE_MQTT_MSG_MAXLEN to MQTT_MAX_PACKET_SIZE - * F.Thiebolt aug.20 set MQTT comm class as an independant module in order to - * manage a single TCP(s) connexion with the MQTT server. - * Thiebolt F. July 17 - * - */ - - -#ifndef _NEOCAMPUS_COMM_H_ -#define _NEOCAMPUS_COMM_H_ - -/* - * Includes - */ - -#include <Arduino.h> -#include <ArduinoJson.h> -#if defined(ESP8266) - #include <ESP8266WiFi.h> -#elif defined(ESP32) - #include <WiFi.h> -#endif - -#include "neocampus.h" -#include "PubSubClient.h" -#include "sensocampus.h" - - -/* - * Global, shared stuffs - */ -extern bool _need2reboot; - - -/* - * Definitions - */ -#ifndef MQTT_CONNECT_MAX_RETRIES -#define MQTT_CONNECT_MAX_RETRIES 3 // maximum number of MQTT connect attempts -#endif - - - -/* - * Class - */ -class comm { - public: - // constructor(s) - comm( void ); - - boolean start( senso * ); - boolean stop( void ); - - boolean isConnected( void ); - boolean process( void ); - - /* publish */ - boolean publish(const char* topic, const char* payload); - boolean publish(const char* topic, const uint8_t * payload, unsigned int plength); - - /* modules to register a callback tied to a topic */ - boolean register_cb( const char* topic, MQTT_CALLBACK_SIGNATURE ); - - - /* - * public attributes - */ - - - private: - /* - * private methods - */ - // low-level init for constructors - void _comm( void ); - - boolean reConnect( void ); - void msgHandler( char*, uint8_t*, unsigned int ); - void callback( char* topic, byte* payload, unsigned int length ); - - /* - * private attributes - */ - // array of pointers to callbacks - - - // MQTT - senso *_sensoClient; - WiFiClient _wifiClient; - PubSubClient mqttClient; -}; - - -#endif /* _NEOCAMPUS_COMM_H_ */ diff --git a/neosensor/neosensor.ino b/neosensor/neosensor.ino index 5ca02a18..05a015e5 100644 --- a/neosensor/neosensor.ino +++ b/neosensor/neosensor.ino @@ -98,7 +98,7 @@ #include "neocampus_i2c.h" #include "sensocampus.h" #include "neocampus_OTA.h" -//#include "neocampus_comm.h" // future MQTT(s) comm module: a single MQTTclient shared with multiple subscribers featuring different callbacks + /* neOCampus modules * !! WARNING !! @@ -147,6 +147,10 @@ //const long gmtOffset_sec = 3600; [nov.21] daylight changing does not work //const int daylightOffset_sec = 3600; #endif +/* [dec.23] only ONE ntp server will get taken into account. + * This stems from tha fact that UT3 network's DNS does NOT resolve IRIT IPs + * and vice-versa ... hence leading to numerous DNS failures ! + */ #define NTP_DEFAULT_SERVER1 "pool.ntp.org" // DNS location aware //#define NTP_DEFAULT_SERVER1 "time.nist.gov" // DNS location aware //#define NTP_DEFAULT_SERVER2 "0.fr.pool.ntp.org" // DNS location aware -- GitLab