Localhost
in the code on your ESP is the ESP itself. You are trying to connect from the ESP, to the ESP.
Localhost
always refers to "this computer", just like the IP address 127.0.0.1 does.
"This computer" as seen from the code on the ESP is the ESP itself, and not the computer that is running the MQTT server.
Assuming the syntax is correct otherwise: in the line const char* mqttServer = "localhost:1833";
you need to put in the IP address or name of the computer that runs your MQTT server instead of localhost
. I don't know if you also need to change the port.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…