I have a program that does 4 times the same thing with different parapmeters; and was trying to simplify my code to take one parameter as a variable.
Example (what was):
const char MQTT_PUB_IRRIGATION_TANK_VALVE[] = "ArgyleCourt/Property/Hub/IrrigationTank/Valve";
const char MQTT_PUB_HOUSE_BOREWATER_TANK_VALVE[] = "ArgyleCourt/Property/Hub/HouseBoreWaterTank/Valve";
publishTankValveStatusIrrigation(false);
void publishTankValveStatusIrrigation(bool demandStatus) {
if (demandStatus) {
mqttClient.publish(MQTT_PUB_IRRIGATION_TANK_VALVE, "ON");
} else {
mqttClient.publish(MQTT_PUB_IRRIGATION_TANK_VALVE, "OFF");
}
}
publishTankValveStatusHouse(false);
void publishTankValveStatusHouse(bool demandStatus) {
if (demandStatus) {
mqttClient.publish(MQTT_PUB_HOUSE_BOREWATER_TANK_VALVE, "ON");
} else {
mqttClient.publish(MQTT_PUB_HOUSE_BOREWATER_TANK_VALVE, "OFF");
}
}
to one function now passing the topic also inot the function, thus needing only one function:
publishTankValveStatus(false, MQTT_PUB_IRRIGATION_TANK_VALVE);
publishTankValveStatus(false, MQTT_PUB_HOUSE_BOREWATER_TANK_VALVE);
void publishTankValveStatus(bool demandStatus, char topicToPublishTo) {
if (demandStatus) {
mqttClient.publish(topicToPublishTo, "ON");
} else {
mqttClient.publish(topicToPublishTo, "OFF");
}
}
when I compile the simplified function, I get "warning: invalid conversion from 'const char*' to 'char' [-fpermissive]", but do neither understand why or how to fix it.