El ESP8266 solo llega al broker si le pongo una IP estática, y TI no permite IP estáticas
Traducido del English por IA ·
Nodo de temperatura de una cámara fría con ESP8266 (Wemos D1 mini), PubSubClient sobre BearSSL hacia Hermetry en 8883. En casa funcionaba con DHCP. En la planta, con DHCP se une a la Wi-Fi, obtiene una dirección y luego nunca se conecta al broker:
WiFi connected, IP 10.20.31.144
Attempting MQTT connection...failed, rc=-2
Attempting MQTT connection...failed, rc=-2
Nuestro técnico de mantenimiento lo «arregló» fijando una IP estática, la puerta de enlace, la máscara de subred y 8.8.8.8 como DNS en WiFi.config(). Entonces se conecta de inmediato. Ahora TI encontró la dirección estática y quiere eliminarla: todo en esa red debe usar DHCP. ¿Qué hace DHCP de forma distinta que rompe la conexión?
Cold room temperature node on an ESP8266 (Wemos D1 mini), PubSubClient over BearSSL to Hermetry on 8883. At home it worked on DHCP. At the plant, on DHCP it joins Wi-Fi, gets an address, and then never connects to the broker:
WiFi connected, IP 10.20.31.144
Attempting MQTT connection...failed, rc=-2
Attempting MQTT connection...failed, rc=-2
Our maintenance tech «fixed» it by hardcoding a static IP, gateway, subnet and 8.8.8.8 as DNS in WiFi.config(). Then it connects straight away. Now IT found the static address and wants it gone, everything on that network has to be DHCP. What is DHCP doing differently that breaks the connection?
Traducido del English por IA ·
¿Quizás la concesión DHCP tarda y el código intenta conectarse a MQTT antes de que la dirección esté lista?
Maybe the DHCP lease is slow and the code tries MQTT before the address is ready?
Traducido del English por IA ·
¿Podrías conectarte directamente a la dirección IP del broker? Así el DNS no importa.
Could you just connect to the broker’s IP address instead? Then DNS doesn’t matter.
Traducido del English por IA ·
Kevin, no: el broker necesita SNI, así que tienes que conectarte por nombre de host, y la verificación del certificado también se hace contra ese nombre. La IP es un callejón sin salida.La pista es que la configuración estática del técnico incluía 8.8.8.8. rc=-2 en PubSubClient es «connect failed», que en un 8266 es muy a menudo una resolución de nombres fallida. Lo he visto varias veces en redes de planta: el servidor DHCP entrega el servidor DNS interno de la planta, y ese solo responde a nombres internos o bloquea las consultas externas. Con la configuración estática, la placa usaba 8.8.8.8 en su lugar y todo funcionaba. Añade esto después de conectar y lo verás:
Serial.println(WiFi.dnsIP());
IPAddress ip;
Serial.println(WiFi.hostByName(MQTT_HOST, ip) ? ip.toString() : "lookup failed");
Luego pide a TI una de dos cosas: que su DNS resuelva el nombre de host del broker de tu organización (aparece en la tarjeta Connection details del dispositivo), o que permitan el DNS saliente desde esa VLAN. Y mientras hablas con ellos, el TCP 8883 saliente también debe estar abierto, además del 443 si alguna vez usas HTTPS. La suposición de Wilson merece protegerse de todos modos: espera a que WiFi.localIP() sea distinto de cero antes de la primera conexión.
Kevin, no: the broker needs SNI, so you have to connect by host name, and the certificate check is against that name too. IP is a dead end.
The clue is that the tech’s static config included 8.8.8.8. rc=-2 in PubSubClient is «connect failed», which on an 8266 is very often a failed name lookup. I’ve seen this on plant networks a few times: the DHCP server hands out the plant’s internal DNS server, and that one only answers for internal names, or blocks outside lookups. With static config the board used 8.8.8.8 instead and everything worked. Add this after connecting and you’ll see it:
Serial.println(WiFi.dnsIP());
IPAddress ip;
Serial.println(WiFi.hostByName(MQTT_HOST, ip) ? ip.toString() : "lookup failed");
Then ask IT for one of two things: let their DNS resolve your organisation’s broker host name (it’s on the device’s Connection details card), or allow outbound DNS from that VLAN. And while you’re talking to them, outbound TCP 8883 has to be open as well, plus 443 if you ever use HTTPS. Wilson’s guess is worth guarding against anyway: wait for WiFi.localIP() to be non-zero before the first connect.
Traducido del English por IA ·
Lo has clavado. dnsIP era un servidor interno y la resolución de nombres fallaba. TI añadió un reenviador para el host del broker, el nodo volvió a usar DHCP y se conectó al primer intento. Prefirieron hacer eso antes que ver una IP estática.
You nailed it. dnsIP was an internal server and the lookup failed. IT added a forwarder for the broker host, the node is back on DHCP and connected first try. They were happier to do that than to see a static IP.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

