Communication of Arduino with mqtt broker on raspberry via Ethernet

Hey,
I can't set my arduino as cilent on mosquitto broker.
I am trying to connect arduino to mosquitto on raspberry via ethernet cable.
I set raspberry static ip eth0 address 192.168.4.1 . Arduio pings on raspberry but i can't connect to mqqtt server.
I set in mosquitto configure allow_anonymous true but still does not work. Do you guys have any advice? I will be very grateful.

here is code

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 4, 100);
IPAddress server(192, 168, 4, 1); //my raspberry eth0 ip adress

// Callback function header
void callback(char* topic, byte* payload, unsigned int length);

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

// Callback function
void callback(char* topic, byte* payload, unsigned int length) {

  //turn the LED ON if the payload is '1' and publish to the MQTT server a confirmation message
  if (payload[0] == '1') {

    client.publish("outTopic", "value 1");
  }

  //turn the LED OFF if the payload is '0' and publish to the MQTT server a confirmation message
  if (payload[0] == '0') {

    client.publish("outTopic", "value 0");
  }
} // void callback


void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  if (client.connect("arduinoClient")) {
    Serial.println("connected to mqtt");
    client.publish("outTopic", "hello there");
    client.subscribe("inTopic");
  }
}

void loop()
{
  client.loop();
}

From networking - Mosquitto: Starting in local only mode - Stack Overflow

Mosquitto on Debian, to allow external connections add the following two lines to /etc/mosquitto/mosquitto.conf

listener 1883
allow_anonymous true

thanks for your reply. I have already done it but it still does not work.
Is there something more on your mind what can i do?

Use a MQTT client on another computer or mobile phone to prove that the Ras Pi allows external connections.

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