knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.85k stars 1.48k forks source link

yun #210

Open yveshanoulle opened 8 years ago

yveshanoulle commented 8 years ago

I'm trying to send an MQT message from an arduino yun. When I do this manually on the server, it works. When I do it with this code, nothing happend .

I don't get any errors, yet I don't get any message either. I tried two different arduino's they both have the same result. (Nothing) Most arduino examples are about receiving messages. that works. (I took that code out, tom minimize the testing) Any idea's what I should check?

#include <PubSubClient.h>
#include <Wire.h>
#include <Bridge.h>
#include <BridgeClient.h>

IPAddress server(192, 168, 1, 122);

BridgeClient ethClient;
PubSubClient client(ethClient);

#define AName "165ARD"
char TemperatureFilterChar[20] =     "162ARD/Temperature/";
char Temperature[3] =     "23";

void setup() {
  Bridge.begin();

  Console.begin();
  client.setServer(server, 1883);

//  PubSubClient setClient (client)
  delay(5000);

  if (client.publish(TemperatureFilterChar,Temperature))
  {
   Console.println("published");
}   
}

void reconnect() {

  while (!client.connected()) {
      Console.println("Attempting MQTT connection...");
    if (client.connect(AName)) {
      Console.println("connected");

      client.publish(TemperatureFilterChar,Temperature);

    }
    else
    {
      Console.println("failed, rc=");
      Console.println(client.state());
      Console.println(" try again in 5 seconds");
      delay(5000);
    }
  }
}

void loop() {

   client.publish(TemperatureFilterChar,Temperature);

  delay(1000);

}
knolleary commented 8 years ago

What console output do you get?