Skip to content

Commit

Permalink
Fix mqtt enable (#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slider0007 authored Mar 8, 2023
1 parent 1f5d4de commit 431df73
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions code/components/jomjol_controlGPIO/server_GPIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void gpioHandlerTask(void *arg) {

void GpioPin::gpioInterrupt(int value) {
#ifdef ENABLE_MQTT
if (_mqttTopic != "") {
if (_mqttTopic.compare("") != 0) {
ESP_LOGD(TAG, "gpioInterrupt %s %d", _mqttTopic.c_str(), value);

MQTTPublish(_mqttTopic, value ? "true" : "false", 1);
Expand Down Expand Up @@ -115,7 +115,7 @@ void GpioPin::init()
}

#ifdef ENABLE_MQTT
if ((_mqttTopic != "") && ((_mode == GPIO_PIN_MODE_OUTPUT) || (_mode == GPIO_PIN_MODE_OUTPUT_PWM) || (_mode == GPIO_PIN_MODE_BUILT_IN_FLASH_LED))) {
if ((_mqttTopic.compare("") != 0) && ((_mode == GPIO_PIN_MODE_OUTPUT) || (_mode == GPIO_PIN_MODE_OUTPUT_PWM) || (_mode == GPIO_PIN_MODE_BUILT_IN_FLASH_LED))) {
std::function<bool(std::string, char*, int)> f = std::bind(&GpioPin::handleMQTT, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
MQTTregisterSubscribeFunction(_mqttTopic, f);
}
Expand All @@ -141,7 +141,7 @@ void GpioPin::setValue(bool value, gpio_set_source setSource, std::string* error
gpio_set_level(_gpio, value);

#ifdef ENABLE_MQTT
if ((_mqttTopic != "") && (setSource != GPIO_SET_SOURCE_MQTT)) {
if ((_mqttTopic.compare("") != 0) && (setSource != GPIO_SET_SOURCE_MQTT)) {
MQTTPublish(_mqttTopic, value ? "true" : "false", 1);
}
#endif //ENABLE_MQTT
Expand All @@ -153,6 +153,7 @@ void GpioPin::publishState() {
if (newState != currentState) {
ESP_LOGD(TAG,"publish state of GPIO %d new state %d", _gpio, newState);
#ifdef ENABLE_MQTT
if (_mqttTopic.compare("") != 0)
MQTTPublish(_mqttTopic, newState ? "true" : "false", 1);
#endif //ENABLE_MQTT
currentState = newState;
Expand Down Expand Up @@ -359,9 +360,9 @@ bool GpioHandler::readConfig()
gpio_int_type_t intType = resolveIntType(toLower(splitted[2]));
uint16_t dutyResolution = (uint8_t)atoi(splitted[3].c_str());
#ifdef ENABLE_MQTT
bool mqttEnabled = toLower(splitted[4]) == "true";
bool mqttEnabled = (toLower(splitted[4]) == "true");
#endif // ENABLE_MQTT
bool httpEnabled = toLower(splitted[5]) == "true";
bool httpEnabled = (toLower(splitted[5]) == "true");
char gpioName[100];
if (splitted.size() >= 7) {
strcpy(gpioName, trim(splitted[6]).c_str());
Expand Down

0 comments on commit 431df73

Please sign in to comment.