What am I doing wrong? I'd like ot use a DNS query to resolve the IP address of my MQTT broker but I can't get it to work. I've tried using the WiFi.config() method but it won't connect to my MQTT broker.
#include ESP8266Wifi.h
#include PubSubClient.h
IPAddress esp_ip(192,168,1,30);
IPAddress dns(192,168,1,22);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,1,1);
const char* broker = "mqtt"; //doesn't work
//IPAddress broker(192,168,1,24); //works fine
void callback(char* topic, byte* payload, unsigned int length){
}
WiFiClient wifiClient;
PubSubClient client(broker, 1883, callback, wifiClient);
void setup() {
WiFi.begin(ssid, password);
WiFi.config(esp_ip, dns, gateway, subnet);
//Wifi connects just fine
...
}
I've also tried the PubSubClient.setServer() method to no avail, the broker IP is not resolved and no connection is made. It works fine if I use an IPAddress variable instead of the char* to point out the broker. Can anyone help me?