MQTT void callback, nothing happens


hello,

i'm testing arduino , mqtt cloud.
for publish goes well, arduino publishes "hello world"

but void callback function nothing happens.
with mqtt.fx client, i'm subscribed topics "status" , "commando".
at "status" see arduino live.

when publish mqtt.fx client topic "commando".
i can see arrived in client, not in serial monitor of arduino.

why void callback function not used?

code: [select]

#include <spi.h>
#include <pubsubclient.h>
#include <ethernet.h>

#define server "m20.cloudmqtt.com"
int port = 13365;

// update these values suitable network.
byte mac[]    = {  0xde, 0xed, 0xba, 0xfe, 0xfe, 0xed };
byte ip[]     = { 192, 168, 0, 120 };

unsigned long time;
char message_buff[100];

ethernetclient ethclient;
pubsubclient client(server, port, callback, ethclient);

void setup()
{
  // init serial link debugging
  serial.begin(115200);
 
  ethernet.begin(mac, ip);
  if (client.connect("arduino-mqtt","test","test")) {
    client.publish("/arduino/status/","hello world");
    client.subscribe("/arduino/commando/");
    serial.println("connected");
  }
 
  if (ethernet.begin(mac) == 0)
  {
      serial.println("failed configure ethernet using dhcp");
      return;
  }
}

void loop()
{
  // mqtt client loop processing
  client.loop();
}


void callback(char* topic, byte* payload, unsigned int length) {
 
  if (strcmp(topic, "/arduino/commando/") == 0) {
    string msg = tostring(payload, length);
    serial.println(msg);
  }else{
    serial.println("arduino topic not found");
  } 
}

//
// tostring function
//
string tostring(byte* payload, unsigned int length) {
  int = 0;
  char buff[length + 1];
  (i = 0; < length; i++) {
    buff[i] = payload[i];
  }
  buff[i] = '\0';
  string msg = string(buff);
  return msg;
}



Arduino Forum > Topics > Home Automation and Networked Objects > MQTT void callback, nothing happens


arduino

Comments