1technophile / OpenMQTTGateway

MQTT gateway for ESP8266 or ESP32 with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility & LoRa.
https://docs.openmqttgateway.com
GNU General Public License v3.0
3.57k stars 786 forks source link

Query DNS Server before connect #90

Closed tegila closed 6 years ago

tegila commented 7 years ago

I've using your code with my homeassistant server to integrate with my 433mhz PIR and door sensors.

But after changing my router 3 times, while searching for a good one, I was left without the integration OpenMQTTGateway provides and have to put back the nodemcu in the computer to write the new IP Address.

After a little research I found some function in the WiFi lib that can fix my problem.

The best solution will rely on something that check between IP String or Hostname and find the best way to reach the MQTT server.

// client parameters PubSubClient client; ... trc(F("WiFi connected")); IPAddress remote_addr; WiFi.hostByName(mqtt_server, remote_addr); client = PubSubClient(remote_addr, mqtt_port, callback, eClient);

1technophile commented 7 years ago

hello,

What I understand is that WiFi.hostByName(mqtt_server, remote_addr); return the IP adress of the host named mqtt_server. What is the benefit of checking against IP string?

1technophile commented 7 years ago

@tegila could you detail your proposal benefit?

1technophile commented 7 years ago

As i haven t feedback i close this issue, reopen it if you need

tegila commented 7 years ago

Hi @1technophile,

Sorry for missing the feedback (i had muted my notifications from github)

So, yes that is exactly what this function does, it get the ip from the dns name.

The benefit come from the fact that when I change my router, or reset, or anything that can change my realm of IP's from the router. I didn't need to get my OpenMQTTGateway device and reprogram it with the new IP address.

My homeassistant has always the same domain name ("hass"), so I can always query the dns against this name and never need reprogram my OpenMQTTGateway again.