mirror of
https://github.com/serega404/EasyESPRelay.git
synced 2025-04-21 22:20:45 +03:00
Fix input string data
This commit is contained in:
parent
016848f0d2
commit
697659c0c5
17
src/src.ino
17
src/src.ino
@ -142,23 +142,26 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
Serial.println("New message: \"" + String(payload) + "\" in topic: " + String(topic));
|
String mess = String(payload).substring(0, len);
|
||||||
if (String(topic).substring(0, 21) == setStateTopic) {
|
|
||||||
if (String(payload).substring(0, 1) == "1") {
|
Serial.println("New message: \"" + mess + "\" in topic: " + String(topic));
|
||||||
|
|
||||||
|
if (String(topic).substring(0, strlen(setStateTopic)) == setStateTopic) {
|
||||||
|
if (mess == "1") {
|
||||||
Serial.println("RELAY: ON");
|
Serial.println("RELAY: ON");
|
||||||
digitalWrite(RELAY, HIGH);
|
digitalWrite(RELAY, HIGH);
|
||||||
mqttClient.publish(stateTopic, 1, true, "1");
|
mqttClient.publish(stateTopic, 1, true, "1");
|
||||||
} else if (String(payload).substring(0, 1) == "0") {
|
} else if (mess == "0") {
|
||||||
Serial.println("RELAY: OFF");
|
Serial.println("RELAY: OFF");
|
||||||
digitalWrite(RELAY, LOW);
|
digitalWrite(RELAY, LOW);
|
||||||
mqttClient.publish(stateTopic, 1, true, "0");
|
mqttClient.publish(stateTopic, 1, true, "0");
|
||||||
}
|
}
|
||||||
} else if(String(topic).substring(0, 16) == bootTopic) {
|
} else if(String(topic).substring(0, strlen(bootTopic)) == bootTopic) {
|
||||||
if (String(payload).substring(0, 1) == "1") {
|
if (mess == "1") {
|
||||||
Serial.println("BOOT: ON");
|
Serial.println("BOOT: ON");
|
||||||
mqttClient.publish(ipTopic, 1, true, WiFi.localIP().toString().c_str());
|
mqttClient.publish(ipTopic, 1, true, WiFi.localIP().toString().c_str());
|
||||||
bootMode = true;
|
bootMode = true;
|
||||||
} else if (String(payload).substring(0, 1) == "0") {
|
} else if (mess == "0") {
|
||||||
Serial.println("BOOT: OFF");
|
Serial.println("BOOT: OFF");
|
||||||
bootMode = false;
|
bootMode = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user