You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am appreciate your Project ,so I want do some contribution, to feedback some question I meet.
I git clone this project to control my ESP8266 board,
if only use mqtt.onData event,it work fine,
but I add a publish call in onData function, the publish not send, other Subscriber can not receive which topic publish. the board also not jump exception.
and the mqtt.onPublish function also not call, I am confused with this, am i use wrong?
mqtt.onData([](String topic, String data, bool cont) {
Serial.printf("Data received, topic: %s, data: %s\r\n", topic.c_str(), data.c_str());
//mqtt.unSubscribe("/qos0");
Serial.printf("%s \r\n", data.c_str());
if (data.compareTo("1") == 0 || data.compareTo("ON") == 0)
{
digitalWrite(PIN_RELAY1, HIGH );
digitalWrite(PIN_RELAY2, HIGH );
mqtt.publish("homeassistant/switch/irrigation/state", "ON", 0, 0); //**actually not work**
//mqtt.publish("123", "ON", 0, 0);
digitalWrite(LED_BUILTIN, LOW); //LED ON
//delay(200);
}
//delay(1000); //delay 1 second
if (data.compareTo("0") == 0 || data.compareTo("OFF") == 0)
{
digitalWrite(PIN_RELAY1, LOW );
digitalWrite(PIN_RELAY2, LOW );
mqtt.publish("homeassistant/switch/irrigation/state", "OFF", 0, 0); // **actually not work**
//mqtt.publish("123", "OFF" , 0, 0);
digitalWrite(LED_BUILTIN, HIGH); //LED OUT
}
});
Serial.println("mqtt OnSub: ");
mqtt.onSubscribe([](int sub_id) {
Serial.printf("Subscribe topic id: %d ok\r\n", sub_id);
mqtt.publish("/qos0", "qos0", 0, 0); // **but this publish WORK FINE! i am so confused**
});
Serial.println("mqtt OnPub: ");
mqtt.onPublish([](int pub_id) { //**this function never call, i don't know why**
Serial.printf("onPublish return id: %d \r\n", pub_id);
});
So i use another esp8266 mqtt client PubSubClient, and it work fine.
void callback(char* topic, byte* payload, unsigned int length) {//call back function with PubSubClient
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
String s = "";
for (int i = 0; i < length; i++) {
s = s + (char)payload[i];
}
Serial.println(s);
// Switch on the LED if an 1 was received as first character
if (s == "ON") {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
client.publish("homeassistant/switch/irrigation/state", (char*)s.c_str());
} else {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
client.publish("homeassistant/switch/irrigation/state", (char*)s.c_str());
}
}
The text was updated successfully, but these errors were encountered:
Hi, I am appreciate your Project ,so I want do some contribution, to feedback some question I meet.
I git clone this project to control my ESP8266 board,
if only use mqtt.onData event,it work fine,
but I add a publish call in onData function, the publish not send, other Subscriber can not receive which topic publish. the board also not jump exception.
and the mqtt.onPublish function also not call, I am confused with this, am i use wrong?
So i use another esp8266 mqtt client PubSubClient, and it work fine.
The text was updated successfully, but these errors were encountered: