MQTT does not name a type error

Hi, i am trying to make a simple project using an example found on AddityaTannu.com. Basically its an Esp8266-07 module that has a relay attached to it and using MQTT it is supposed to turn on and off the relay when mqtt order is received.

I am using Arduino IDE version 1.6.9 on with the last arduino core found on github.

This is the arduino sketch that Addy uses on his example:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char *ssid =	"*******";		// cannot be longer than 32 characters!
const char *pass =	"*******";		//

// Update these with values suitable for your network.
IPAddress server(192, 168, 1, 155);

const int relay = D3;

#define BUFFER_SIZE 100

void callback(const MQTT::Publish& pub) {
  // handle message arrived
  Serial.print(pub.topic());
  Serial.print(" => ");

    Serial.println(pub.payload_string());

    if(pub.payload_string() == "on")
    {
      digitalWrite(relay, HIGH);
    }
    else
    {
      digitalWrite(relay, LOW);
    }

}

WiFiClient wclient;
PubSubClient client(wclient, server);

void setup() {

  pinMode(relay, OUTPUT);

  // Setup console
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();

  client.set_callback(callback);
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to ");
    Serial.print(ssid);
    Serial.println("...");
    WiFi.begin(ssid, pass);

    if (WiFi.waitForConnectResult() != WL_CONNECTED)
      return;
    Serial.println("WiFi connected");
  }

  if (WiFi.status() == WL_CONNECTED) {
    if (!client.connected()) {
      if (client.connect("ESP8266: AdyLight")) {
	client.publish("outTopic","hello world");
	client.subscribe("AdyLight");
      }
    }

    if (client.connected())
      client.loop();
  }
}

But when i verify it i get:

hkrelay:14: error: 'MQTT' does not name a type
 void callback(const MQTT::Publish& pub) {
                     ^
hkrelay:14: error: expected unqualified-id before '&' token
 void callback(const MQTT::Publish& pub) {
                                  ^
hkrelay:14: error: expected ')' before '&' token
hkrelay:14: error: expected initializer before 'pub'
 void callback(const MQTT::Publish& pub) {
                                    ^
hkrelay:14: error: 'MQTT' does not name a type
 void callback(const MQTT::Publish& pub) {
                     ^
hkrelay:14: error: expected unqualified-id before '&' token
 void callback(const MQTT::Publish& pub) {
                                  ^
hkrelay:14: error: expected ')' before '&' token
hkrelay:14: error: expected initializer before 'pub'
 void callback(const MQTT::Publish& pub) {
                                    ^
exit status 1
'MQTT' does not name a type

I guess that this example might be used with an old mqtt library? Or am i missing something else?

Thanks is advance folks

Juan

With pubsubclient, I am using the below callback signature

void callback(char* topic, byte* payload, unsigned int length)

Set the callback like

client.setCallback(callback);

Thanks for answering Sony, help me a little i am new to programming.

void callback(char* topic, byte* payload, unsigned int length)

Basically you create a data type named callback and define topic, payload and an integer and set its type right?

So in my code my variables are MQTT, Publish and Pub?

and on the other line i see just the "_" and C syntax differing. Is that ok?

So in my code my variables are MQTT, Publish and Pub?

No. MQTT is a class. MQTT::Publish is, or should be, something defined in that class. A link to the library that contains the MQTT class would be useful.

Pub is an argument.

I have a small post that explains MQTT using an ESP module, please have a look at the post

I wrote a server code in nodejs to test the setup.