Bladeren bron

added reconnect to loop

master
agr 4 jaren geleden
bovenliggende
commit
023f9c750d
1 gewijzigde bestanden met toevoegingen van 25 en 17 verwijderingen
  1. +25
    -17
      Klappe_Arduino.ino

+ 25
- 17
Klappe_Arduino.ino Bestand weergeven

@@ -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();
}

}

Laden…
Annuleren
Opslaan