Arduino - obtain data from rabbitmq

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");
}

Bellow is config for mqttClient

 #include <WiFiNINA.h>
  #include <ArduinoMqttClient.h>

  WiFiClient    wifiClient;
  MqttClient    mqttClient(wifiClient);

Any idea what's wrong ?

Welcome to the forum

Please post your full sketch, using code tags when you do

1 Like

There must have been some result!

does mqttClient.connect not give you a return code, or any other diagnostics on what went wrong?

Does your Broker "see" the connection attempt?

Can you ping the server from your Arduino?

Are you sure the IP address, username & password are all correct?

without results - i had in mind that my result is invalid :slight_smile:

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

 Serial.println(WiFi.ping("192.168.0.14"));
  Serial.println(WiFi.ping("192.168.0.10"));
  Serial.println(WiFi.ping("8.8.8.8"));

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.

Of course - it's a different node, so it must have a different IP address!

In fact a PC might have several different IP addresses - one for each interface (eg, one for Ethernet and one for WiFi)

Thanks for claryfication @awneil !

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.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.