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