Discovery problems
This commit is contained in:
@@ -667,9 +667,10 @@ def publish_discovery(client):
|
|||||||
)
|
)
|
||||||
info(f"Discovery: gauge {i} ({g['name']})")
|
info(f"Discovery: gauge {i} ({g['name']})")
|
||||||
|
|
||||||
# Process MQTT messages between publishes
|
# Process MQTT messages between gauges
|
||||||
|
for _ in range(5):
|
||||||
client.check_msg()
|
client.check_msg()
|
||||||
utime.sleep_ms(30)
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
client.publish(
|
client.publish(
|
||||||
gt["led_red_disc"],
|
gt["led_red_disc"],
|
||||||
@@ -771,6 +772,11 @@ def publish_discovery(client):
|
|||||||
)
|
)
|
||||||
info(f"Discovery: gauge {i} status green")
|
info(f"Discovery: gauge {i} status green")
|
||||||
|
|
||||||
|
# Process between gauges to avoid MQTT blocking
|
||||||
|
for _ in range(5):
|
||||||
|
client.check_msg()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
|
||||||
def publish_state(client):
|
def publish_state(client):
|
||||||
for i, g in enumerate(gauge_objects):
|
for i, g in enumerate(gauge_objects):
|
||||||
@@ -794,14 +800,17 @@ def main():
|
|||||||
connect_wifi(WIFI_SSID, WIFI_PASSWORD)
|
connect_wifi(WIFI_SSID, WIFI_PASSWORD)
|
||||||
|
|
||||||
# Check if we need to publish discovery
|
# Check if we need to publish discovery
|
||||||
|
discovery_published = False
|
||||||
try:
|
try:
|
||||||
with open(".discovery_ok", "r") as f:
|
with open(".discovery_ok", "r") as f:
|
||||||
discovery_published = f.read()
|
content = f.read()
|
||||||
info("Discovery flag file exists, skipping discovery")
|
if content.strip() == "ok":
|
||||||
discovery_published = True
|
discovery_published = True
|
||||||
|
info("Discovery flag exists - skipping discovery")
|
||||||
except:
|
except:
|
||||||
info("No discovery flag file - publishing discovery")
|
info("No discovery flag - will publish discovery")
|
||||||
discovery_published = False
|
|
||||||
|
info(f"Discovery: {discovery_published}")
|
||||||
|
|
||||||
# Connect MQTT first (needed for discovery)
|
# Connect MQTT first (needed for discovery)
|
||||||
connect_mqtt()
|
connect_mqtt()
|
||||||
|
|||||||
Reference in New Issue
Block a user