OpenCode experiments...
This commit is contained in:
28
gauge.py
28
gauge.py
@@ -25,7 +25,6 @@ import network
|
|||||||
import utime
|
import utime
|
||||||
import ujson
|
import ujson
|
||||||
import gc
|
import gc
|
||||||
import usocket
|
|
||||||
from machine import UART
|
from machine import UART
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -574,23 +573,7 @@ def connect_wifi(ssid, password, timeout_s=15, force_reconnect=False):
|
|||||||
info(f" SSID : {ssid}")
|
info(f" SSID : {ssid}")
|
||||||
info(f" MAC : {mac}")
|
info(f" MAC : {mac}")
|
||||||
info(f" IP : {ip} mask:{mask} gw:{gw} dns:{dns}")
|
info(f" IP : {ip} mask:{mask} gw:{gw} dns:{dns}")
|
||||||
utime.sleep_ms(500)
|
utime.sleep_ms(2000)
|
||||||
if dns in ("0.0.0.0", ""):
|
|
||||||
info("DNS not yet from DHCP — waiting ...")
|
|
||||||
for _ in range(30):
|
|
||||||
utime.sleep_ms(200)
|
|
||||||
ip, mask, gw, dns = _wifi_sta.ifconfig()
|
|
||||||
if dns not in ("0.0.0.0", ""):
|
|
||||||
info(f"DHCP settled: DNS={dns}")
|
|
||||||
break
|
|
||||||
info(" still waiting ...")
|
|
||||||
utime.sleep_ms(1000)
|
|
||||||
info(f"Testing DNS for {MQTT_BROKER} ...")
|
|
||||||
try:
|
|
||||||
ai = usocket.getaddrinfo(MQTT_BROKER, MQTT_PORT)
|
|
||||||
info(f"DNS resolved: {ai[0][4][0]}")
|
|
||||||
except Exception as e:
|
|
||||||
warn(f"DNS test failed: {e}")
|
|
||||||
return ip
|
return ip
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
last_error = e
|
last_error = e
|
||||||
@@ -909,16 +892,9 @@ def connect_mqtt():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
broker_ip = MQTT_BROKER
|
|
||||||
try:
|
|
||||||
ai = usocket.getaddrinfo(MQTT_BROKER, MQTT_PORT)
|
|
||||||
broker_ip = ai[0][4][0]
|
|
||||||
info(f"Resolved {MQTT_BROKER} → {broker_ip}")
|
|
||||||
except Exception as e:
|
|
||||||
warn(f"Could not resolve {MQTT_BROKER}: {e} — using hostname as-is")
|
|
||||||
client = MQTTClient(
|
client = MQTTClient(
|
||||||
client_id=MQTT_CLIENT_ID,
|
client_id=MQTT_CLIENT_ID,
|
||||||
server=broker_ip,
|
server=MQTT_BROKER,
|
||||||
port=MQTT_PORT,
|
port=MQTT_PORT,
|
||||||
user=MQTT_USER,
|
user=MQTT_USER,
|
||||||
password=MQTT_PASSWORD,
|
password=MQTT_PASSWORD,
|
||||||
|
|||||||
Reference in New Issue
Block a user