I developed small android app to send data for my own rabbitmq server. Next, i installed mqtt plugin.
Now Im struggling with connection rabbitmq to arduino ? I tried to connect by given piece of code, without results:
void connectMQTT() {
Serial.print("Attempting to MQTT broker: ");
mqttClient.setUsernamePassword(MQTT_USER, MQTT_PASSWD);
while (!mqttClient.connect("192.168.0.14", 1883)) { //192.168.0.14 is local ip, port 1883 is for mqtt
delay(5000);
}
Serial.println("You're connected to the MQTT broker");
mqttClient.subscribe("NanoIot33_1/sub");
}
without results - i had in mind that my result is invalid
mqttClient.connect return error code -2 what supposedly means "Connection refused by server". But im afraid its not true and im not getting connection at all.
Broker didnt see any connection attempts.
Im digging deeper with ping. I discover that my local windows IP is 192.168.0.10 but when i invoke
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
then 192.168.0.14 will be results. I suppose its ok that my arduino nano 33 iot has diffrent ip than windows, true ?
Next, i tried to ping
and results are: 0, -1, >=0 - so im connecting to xxx.14 and to xxx.8 but not to windows ip. Code -1 mean WL_PING_DEST_UNREACHABLE, But why cant i ping in my local network ? There is no problem to ping from windows to arduino.
Any idea how to check why arduino cant ping PC in same network ?
Im using wifi.
Edit:
I updated the firewall to ping access on my computer and it worked. Unfortunately the connection to the server still doesn't work, even after disabling the firewall.
OK, i got it. I was soooooo dump. My mqtt server is running on virtualbox. I opened a good port from virtualbox, but to 127.0.0.1 instead of ip from ipconfig.