mirror of
https://github.com/schinken/esp8266-geigercounter.git
synced 2024-11-24 09:30:20 +01:00
Refactor MQTT connect
This commit is contained in:
parent
b9c3cf0d6c
commit
9ee13ff425
1 changed files with 9 additions and 13 deletions
|
@ -18,9 +18,12 @@ float lastuSv = 0, currentuSv = 0;
|
|||
|
||||
void setup() {
|
||||
|
||||
WiFi.hostname("GeigerCounter");
|
||||
WiFi.hostname("ESP-GeigerCounter");
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
mqttClient.setClient(wifiClient);
|
||||
mqttClient.setServer(mqttHost, 1883);
|
||||
|
||||
Serial.begin(115200);
|
||||
geigerCounterSerial.begin(BAUD_GEIGERCOUNTER);
|
||||
|
||||
|
@ -69,19 +72,12 @@ void updateRadiationValues() {
|
|||
|
||||
void connectMqtt() {
|
||||
|
||||
bool newConnection = false;
|
||||
|
||||
while (!mqttClient.connected()) {
|
||||
mqttClient.setClient(wifiClient);
|
||||
mqttClient.setServer(mqttHost, 1883);
|
||||
mqttClient.connect("geigercounter", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected");
|
||||
|
||||
delay(1000);
|
||||
newConnection = true;
|
||||
}
|
||||
|
||||
if (newConnection) {
|
||||
if (mqttClient.connect("geigercounter", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected")) {
|
||||
mqttClient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
|
||||
} else {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue