Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in constant_sensor.h (Release 2.7.3-alpha) #682

Open
mestafin opened this issue Mar 7, 2024 · 1 comment
Open

Bug in constant_sensor.h (Release 2.7.3-alpha) #682

mestafin opened this issue Mar 7, 2024 · 1 comment

Comments

@mestafin
Copy link

mestafin commented Mar 7, 2024

I declare the following constant string sensor:

auto *mode = new StringConstantSensor("managed", 1000, "/config/mode");

I get the following error:

line 26 in main.cpp is

#include "sensesp/sensors/constant_sensor.h"

It looks like it has something to do with ArduinoJson 6.2


In file included from src/main.cpp:26:
.pio/libdeps/esp32dev/SensESP/src/sensesp/sensors/constant_sensor.h: In instantiation of 'bool sensesp::ConstantSensor<T>::set_configuration(const ArduinoJson::V6215PB2::JsonObject&) [with T = String]':
.pio/libdeps/esp32dev/SensESP/src/sensesp/sensors/constant_sensor.h:72:16:   required from here
.pio/libdeps/esp32dev/SensESP/src/sensesp/sensors/constant_sensor.h:75:14: error: ambiguous overload for 'operator=' (operand types are 'String' and 'ArduinoJson::V6215PB2::detail::enable_if<true, ArduinoJson::V6215PB2::detail::MemberProxy<ArduinoJson::V6215PB2::JsonObject, const char*> >::type' {aka 'ArduinoJson::V6215PB2::detail::MemberProxy<ArduinoJson::V6215PB2::JsonObject, const char*>'})
       value_ = config["value"];
In file included from .pio/libdeps/esp32dev/NMEA2000-library/src/N2kDef.h:57,
                 from .pio/libdeps/esp32dev/NMEA2000-library/src/N2kStream.h:39,
                 from .pio/libdeps/esp32dev/NMEA2000-library/src/N2kMsg.h:44,
                 from .pio/libdeps/esp32dev/NMEA2000-library/src/N2kMessages.h:57,
                 from src/main.cpp:13:
/Users/johan/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:104:18: note: candidate: 'String& String::operator=(const String&)'
         String & operator =(const String &rhs);
                  ^~~~~~~~
/Users/johan/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:105:18: note: candidate: 'String& String::operator=(const char*)'
         String & operator =(const char *cstr);
                  ^~~~~~~~
/Users/johan/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:106:18: note: candidate: 'String& String::operator=(const __FlashStringHelper*)'
         String & operator = (const __FlashStringHelper *str) {return *this = reinterpret_cast<const char*>(str);}
                  ^~~~~~~~
/Users/johan/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:108:18: note: candidate: 'String& String::operator=(String&&)'
         String & operator =(String &&rval);
                  ^~~~~~~~
/Users/johan/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:109:18: note: candidate: 'String& String::operator=(StringSumHelper&&)'
         String & operator =(StringSumHelper &&rval);

if I open the source file in visual code / platformio, it show an error in this function below on this line

value_ = config["value"];

  virtual bool set_configuration(const JsonObject &config) override {
    // Neither of the configuration parameters are mandatory
    if (config.containsKey("value")) {
      value_ = config["value"];
    }
    if (config.containsKey("interval")) {
      send_interval_ = config["interval"];
    }
    return true;
  }
@mestafin mestafin changed the title Bug in constant_sensor.h Bug in constant_sensor.h (Release 2.7.3-alpha) Mar 7, 2024
@mestafin
Copy link
Author

mestafin commented Mar 8, 2024

Found the solution

You have to change line 75 in constant_sensor.h with the following:

old line:

value_ = config["value"];

new line:

` value_ = config["value"].as<T>();`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant