Ok thank you. I got feedback now and know what is wrong. I connected to my wifi but I can't connect to my HiveMQ free cloud mqtt broker:
In my HiveMQ console I got port 8883 (TLS ):

and the url which I put on my node-red node mqtt-broker-node in server attribute and the port 8883 and clicked "Use TLS" and in the Secruity label I enter username and password and I put in on my esp's code.
const char * mqtt_server = "7e2xxxxxxxxxxxxx71a.s1.eu.hivemq.cloud"; // Local IP address of Raspberry Pi or cloud mqtt broker
const char * username = "xxxxxxxxxx";
const char * pass = "xxxxxxxxxxxxxxx";
// Connecting to MQTT broker
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str(), username, pass)) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic", "hello world");
// ... and resubscribe
client.subscribe(sub1);
client.subscribe(sub2);
client.subscribe(sub3);
client.subscribe(sub4);
client.subscribe(sub5);
client.subscribe(sub6);
client.subscribe(sub7);
client.subscribe(sub8);
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
and in void setup i got:
void setup() {
setup_wifi();
client.setServer(mqtt_server, 8883);
client.setCallback(callback);
}
BTW: Anyway I got to ask. If I got e.g. GPIO01 (TX) I got defined it like: int led = 1 because it is GPIO01? So I got look at GPIO[NUMBER] not on the pcb D[NUMBER] e.g D1,D3,D7?
I have to defined it in Arduino IDE like this:
int LED = 1
or GPIO4
int LED2 = 4 // it is D2
What value for GPIO4? 2 or 4? beacuase it's digital pin 2 (D2) but it has GPIO4. ;/
