SignalK / SensESP

Universal Signal K sensor framework for the ESP32 platform
https://signalk.org/SensESP/
Apache License 2.0
145 stars 79 forks source link

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

Open mestafin opened 4 months ago

mestafin commented 4 months ago

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 commented 3 months ago

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>();`