Yes, I followed that video and installed MQTT by Joel G…
Just tried it again and getting the same errors.
#include <MQTT.h>
#include <MQTTClient.h>
#include <system.h>
/*
* Device Title: MK-BlindsControl
* Device Description: MQTT Blinds Control
* Device Explanation: The device recieves an MQTT message from the server and
* changes the position of the servo motor
* Device information: https://www.MK-SmartHouse.com/blinds-control
*
* Author: Matt Kaczynski
* Website: http://www.MK-SmartHouse.com
*
* Code may only be distrbuted through http://www.MK-SmartHouse.com any other methods
* of obtaining or distributing are prohibited
* Copyright (c) 2016-2017
*
* Note: After flashing the code once you can remotely access your device by going to http://HOSTNAMEOFDEVICE.local/firmware
* obviously replace HOSTNAMEOFDEVICE with whatever you defined below. The user name and password are also defined below.
*/
#include <Servo.h>
#include <ESP8266WiFi.h>
#include <MQTTClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
/* ---------- DO NOT EDIT ANYTHING ABOVE THIS LINE ---------- */
//Only edit the settings in this section
/* WIFI Settings */
// Name of wifi network
const char* ssid = "WiFi";
// Password to wifi network
const char* password = "password";
/* Web Updater Settings */
// Host Name of Device
const char* host = "MK-BlindsControl1";
// Path to access firmware update page (Not Neccessary to change)
const char* update_path = "/firmware";
// Username to access the web update page
const char* update_username = "admin";
// Password to access the web update page
const char* update_password = "admin";
/* MQTT Settings */
// Topic which listens for commands
char* subscribeTopic = "MK-SmartHouse/utilities/MK-BlindsControl1";
//MQTT Server IP Address
const char* server = "192.168.0.4";
//Unique device ID
const char* mqttDeviceID = "MK-SmartHouseDevice1";
/* ---------- DO NOT EDIT ANYTHING BELOW THIS LINE ---------- */
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
Servo myservo;
WiFiClient net;
MQTTClient client;
unsigned long lastMillis = 0;
void connect();
void setup()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
client.begin(server, net);
client.onMessage(messageReceived);
connect();
MDNS.begin(host);
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
httpServer.begin();
MDNS.addService("http", "tcp", 80);
}
void connect()
{
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
}
while (!client.connect(mqttDeviceID))
{
delay(1000);
}
client.subscribe(subscribeTopic);
}
void loop()
{
client.loop();
delay(10);
if(!client.connected())
{
connect();
}
httpServer.handleClient();
}
void messageReceived(String &topic, String &payload)
{
String msgString = payload;
myservo.attach(13);
if (msgString == "UP")
{
myservo.write(0);
delay(1000);
}
else if (msgString == "DOWN")
{
myservo.write(180);
delay(1000);
}
else if (msgString == "STOP")
{
myservo.write(0);
delay(1000);
myservo.write(100);
delay(1000);
}
else if (msgString == "ON")
{
myservo.write(0);
delay(1000);
}
else if (msgString == "OFF")
{
myservo.write(180);
delay(1000);
}
else if (isValidNumber(msgString))
{
if(msgString.toInt() <= 60 && msgString.toInt() >= 40)
{
myservo.write(0);
delay(1000);
}
myservo.write(msgString.toInt() * 1.8);
delay(1000);
}
myservo.detach();
}
boolean isValidNumber(String str)
{
boolean isNum=false;
if(!(str.charAt(0) == '+' || str.charAt(0) == '-' || isDigit(str.charAt(0)))) return false;
for(byte i=1;i<str.length();i++)
{
if(!(isDigit(str.charAt(i)) || str.charAt(i) == '.')) return false;
}
return true;
}
Arduino: 1.6.9 (Windows 10), Board: “Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, QIO, 512K (no SPIFFS), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”
Q:\Downloads\MK-BlindsControl\MK-BlindsControl.ino: In function ‘void setup()’:
MK-BlindsControl:86: error: ‘messageReceived’ was not declared in this scope
client.onMessage(messageReceived);
^
Q:\Downloads\MK-BlindsControl\MK-BlindsControl.ino: In function ‘void messageReceived(String&, String&)’:
MK-BlindsControl:158: error: ‘isValidNumber’ was not declared in this scope
else if (isValidNumber(msgString))
^
exit status 1
‘messageReceived’ was not declared in this scope
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.