Bläddra i källkod

added reconnect to loop

master
agr 4 år sedan
förälder
incheckning
023f9c750d
1 ändrade filer med 25 tillägg och 17 borttagningar
  1. +25
    -17
      Klappe_Arduino.ino

+ 25
- 17
Klappe_Arduino.ino Visa fil

@@ -60,6 +60,25 @@ void callback(char *topic, byte *payload, unsigned int length) {
}
}

void mqttreconnect() {
if (mqttClient.connect("arduino-1", "loxberry", "OSVL0AMqISFXgr5g")) {
// connection succeeded
Serial.println("Connected ");
boolean r = mqttClient.subscribe("loxone/hof/Gansetorauf");
Serial.println("loxone/hof/Gansetorauf subscribe ");
Serial.println(r);
r = mqttClient.subscribe("loxone/hof/Gansetorzu");
Serial.println("loxone/hof/Gansetorzu subscribe ");
Serial.println(r);
} else {
// connection failed
// mqttClient.state() will provide more information
// on why it failed.
Serial.println("Connection failed ");
Serial.println(mqttClient.state());
}
}

void setup() {
// Open serial communications and wait for port to open:

@@ -74,21 +93,8 @@ void setup() {
mqttClient.setServer("192.168.11.35", 1883);
mqttClient.setCallback(callback);

if (mqttClient.connect("arduino-1", "loxberry", "OSVL0AMqISFXgr5g")) {
// connection succeeded
Serial.println("Connected ");
boolean r = mqttClient.subscribe("loxone/hof/Gansetorauf");
Serial.println("loxone/hof/Gansetorauf subscribe ");
Serial.println(r);
r = mqttClient.subscribe("loxone/hof/Gansetorzu");
Serial.println("loxone/hof/Gansetorzu subscribe ");
Serial.println(r);
} else {
// connection failed
// mqttClient.state() will provide more information
// on why it failed.
Serial.println("Connection failed ");
}
mqttreconnect();

// Relais
pinMode(relais1pin, OUTPUT);
pinMode(relais2pin, OUTPUT);
@@ -100,9 +106,11 @@ void loop() {
//

while (true) {

if (!mqttClient.loop()) {
mqttreconnect();
}
delay(1000);
mqttClient.loop();
}

}

Laddar…
Avbryt
Spara