Skip to content

Commit 6a4b7a1

Browse files
committed
if on ethernet, show it's IP and not WiFi
1 parent 621c73a commit 6a4b7a1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/mqtt.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void Mqtt::resubscribe() {
160160

161161
// Main MQTT loop - sends out top item on publish queue
162162
void Mqtt::loop() {
163-
// exit if MQTT is not enabled or if there is no WIFI
163+
// exit if MQTT is not enabled or if there is no network connection
164164
if (!connected()) {
165165
return;
166166
}
@@ -589,7 +589,7 @@ bool Mqtt::get_publish_onchange(uint8_t device_type) {
589589
// MQTT onConnect - when an MQTT connect is established
590590
// send out some inital MQTT messages
591591
void Mqtt::on_connect() {
592-
if (connecting_) { // prevent duplicating connections
592+
if (connecting_) { // prevent duplicated connections
593593
return;
594594
}
595595

@@ -611,7 +611,11 @@ void Mqtt::on_connect() {
611611

612612
doc["version"] = EMSESP_APP_VERSION;
613613
#ifndef EMSESP_STANDALONE
614-
doc["ip"] = WiFi.localIP().toString();
614+
if (ETH.linkUp()) {
615+
doc["ip"] = ETH.localIP().toString();
616+
} else {
617+
doc["ip"] = WiFi.localIP().toString();
618+
}
615619
#endif
616620
publish(F_(info), doc.as<JsonObject>());
617621

@@ -672,7 +676,7 @@ void Mqtt::ha_status() {
672676
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
673677

674678
// create the sensors
675-
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Wifi strength"), EMSdevice::DeviceType::SYSTEM, F("rssi"));
679+
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("WiFi strength"), EMSdevice::DeviceType::SYSTEM, F("rssi"));
676680
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime"), EMSdevice::DeviceType::SYSTEM, F("uptime"));
677681
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime (sec)"), EMSdevice::DeviceType::SYSTEM, F("uptime_sec"));
678682
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Free heap memory"), EMSdevice::DeviceType::SYSTEM, F("freemem"));

0 commit comments

Comments
 (0)