Hi,
I am experiencing a problem when compiling the code below.
This code is only to test MQTT and JSON functionality before developing the actual functionality.
Here comes the compiler-error:
src/mqtt_pulse_switch.h:18:88: error: no matching function for call to 'MqttPulseSwitch::subscribe_json(const char [32], void (MqttPulseSwitch::*)(ArduinoJson::JsonObject&))'
What I don’t understand is that I am using the function call “subscribe_json” direcly from the example in the documentation. I looked in the API, but as I am not that experienced in C, I did not come closer to understanding the problem.
Can anyone help, please?
Thanks
class MqttPulseSwitch : public Component, public CustomMQTTDevice {
public:
int string_id = 0; //varmestreng 1 til 5
int dutycycle = 20; //percentage_pn
int interval = 120; //minutes - 0=off
int switch_pin = 27; //switch output pin
int target_temp = 21; //måltemperatur
void setup() override {
pinMode(27, OUTPUT);
bool state;
subscribe("vvv46/heating/floor/unit/measured/", &MqttPulseSwitch::on_message);
subscribe_json("vvv46/heating/floor/unit/setup/", &MqttPulseSwitch::on_json_message);
publish("vvv46/heating/floor/unit/availability/", "online");
}
void on_message(const std::string &payload) {
float payloadAsFloat = std::stof(payload);
if (payloadAsFloat < target_temp) {
digitalWrite(27, HIGH);
publish("vvv46/heating/floor/unit/3/", 1);
} else {
digitalWrite(27, LOW);
publish("vvv46/heating/floor/unit/3/", 0);
}
}
void on_json_message(JsonObject &root) {
if (!root.containsKey("string_id"))
return;
int string_id = root["string_id"];
if (root["string_id"] = 3) {
//streng 3 - køkkenvarme
dutycycle = root["dutycycle"];
interval = root["interval"];
switch_pin = root["switch_pin"];
target_temp = root["target_temp"];
dutycycle = root["dutycycle"];
}
publish_json("vvv46/heating/floor/unit/received/", [=](JsonObject &root2) {
root2["message"] = "JSON received";
root2["string_id"] = string_id;
root2["dutycycle"] = dutycycle;
root2["interval"] = interval;
root2["switch_pin"] = switch_pin;
root2["target_temp"] = target_temp;
});
}
};