I modified the MQTT example present under MQTT library pubsubclient for Arduino.
My MQTT server address is 192.168.1.6 with port 8081.
To this MQTT server,another MQTT client in my mobile is able to connect.
But this is not working with Arduino.There is no error shown during compilation or during uploading.
Infact,I am not able to see the connection result messages such as "Connected" or "Not connected" which i given in Serial.println() in setup function.
I am resetting Arduino before uploading the program.Please let me know why this is not showing any output....
#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 };
byte server[] = {192, 168, 1, 6 };
//byte ip[] = { 172, 16, 0, 100 };
void callback(char* topic, byte* payload, unsigned int length) {
// handle message arrived
}
EthernetClient ethClient;
PubSubClient client(server, 8081, callback, ethClient);
void setup()
{
Ethernet.begin(mac);
if (client.connect("*")) {
Serial.begin(9600);
Serial.println("Connected to MQTT Server");
client.publish("outTopic","hello world");
// client.subscribe("inTopic");
}
else
{
Serial.println("Could not connect to MQTT Server");
}
}
void loop()
{
//client.loop();
}