I keep getting errors when trying this code: Generic Custom Component — ESPHome
Nevertheless, all works great if I comment the json related lines (functions subscribe_json and publish_json).
The file platformio.ini auto generated by esphome have this dependency: bblanchon/[email protected]
I wonder if the code above is still expecting ArduinoJson v5 instead of the current ArduinoJson v6!
Can anyone please confirm this or suggest a way to solve the problem?
Thanks
PS - Here are the compilation errors:
In file included from src\main.cpp:34:0:
src\my_custom_component.h: In member function 'virtual void MyCustomComponent::setup()':
src\my_custom_component.h:13:73: error: no matching function for call to 'MyCustomComponent::subscribe_json(const char [15], void
(MyCustomComponent::*)(ArduinoJson::JsonObject&))'
subscribe_json("the/json/topic", &MyCustomComponent::on_json_message);
^
In file included from src\esphome.h:30:0,
from src\main.cpp:3:
src\esphome\components\mqtt\custom_mqtt_device.h:96:8: note: candidate: template<class T> void esphome::mqtt::CustomMQTTDevice::subscribe_json(const string&, void (T::*)(const string&, ArduinoJson::JsonObject), uint8_t)
void subscribe_json(const std::string &topic, void (T::*callback)(const std::string &, JsonObject), uint8_t qos = 0);
^
src\esphome\components\mqtt\custom_mqtt_device.h:96:8: note: template argument deduction/substitution failed:
In file included from src\main.cpp:34:0:
src\my_custom_component.h:13:73: note: mismatched types 'const string& {aka const std::__cxx11::basic_string<char>&}' and 'ArduinoJson::JsonObject& {aka ArduinoJson6185_D1::ObjectRef&}'
subscribe_json("the/json/topic", &MyCustomComponent::on_json_message);
^
In file included from src\esphome.h:30:0,
from src\main.cpp:3:
src\esphome\components\mqtt\custom_mqtt_device.h:98:29: note: candidate: template<class T> void esphome::mqtt::CustomMQTTDevice::subscribe_json(const string&, void (T::*)(ArduinoJson::JsonObject), uint8_t)
template<typename T> void subscribe_json(const std::string &topic, void (T::*callback)(JsonObject), uint8_t qos = 0);
^
src\esphome\components\mqtt\custom_mqtt_device.h:98:29: note: template argument deduction/substitution failed:
In file included from src\main.cpp:34:0:
src\my_custom_component.h:13:73: note: mismatched types 'ArduinoJson::JsonObject {aka ArduinoJson6185_D1::ObjectRef}' and 'ArduinoJson::JsonObject& {aka ArduinoJson6185_D1::ObjectRef&}'
subscribe_json("the/json/topic", &MyCustomComponent::on_json_message);
^
src\my_custom_component.h: In member function 'void MyCustomComponent::on_json_message(ArduinoJson::JsonObject&)':
src\my_custom_component.h:34:6: error: no matching function for call to 'MyCustomComponent::publish_json(const char [21], MyCustomComponent::on_json_message(ArduinoJson::JsonObject&)::<lambda(ArduinoJson::JsonObject&)>)'
});
^
In file included from src\esphome.h:30:0,
from src\main.cpp:3:
src\esphome\components\mqtt\custom_mqtt_device.h:167:8: note: candidate: bool esphome::mqtt::CustomMQTTDevice::publish_json(const
string&, const json_build_t&, uint8_t, bool)
bool publish_json(const std::string &topic, const json::json_build_t &f, uint8_t qos, bool retain);
^
src\esphome\components\mqtt\custom_mqtt_device.h:167:8: note: candidate expects 4 arguments, 2 provided
src\esphome\components\mqtt\custom_mqtt_device.h:184:8: note: candidate: bool esphome::mqtt::CustomMQTTDevice::publish_json(const
string&, const json_build_t&)
bool publish_json(const std::string &topic, const json::json_build_t &f);
^
src\esphome\components\mqtt\custom_mqtt_device.h:184:8: note: no known conversion for argument 2 from 'MyCustomComponent::on_json_message(ArduinoJson::JsonObject&)::<lambda(ArduinoJson::JsonObject&)>' to 'const json_build_t& {aka const std::function<void(ArduinoJson6185_D1::ObjectRef)>&}'