Blinds control sketch compiling issue


#1

Hi all,
Having an issued compiling sketch for blinds control. I get an error:

Q:\Desktop\Automated Blinds\MK-BlindsControl\MK-BlindsControl.ino: In function ‘void setup()’:

MK-BlindsControl:82: error: ‘messageReceived’ was not declared in this scope

client.onMessage(messageReceived);

                ^

Q:\Desktop\Automated Blinds\MK-BlindsControl\MK-BlindsControl.ino: In function ‘void messageReceived(String&, String&)’:

MK-BlindsControl:154: error: ‘isValidNumber’ was not declared in this scope

else if (isValidNumber(msgString))

                               ^

exit status 1
‘messageReceived’ was not declared in this scope

Please advise.


#2

It’s hard to tell here, but you check your syntax in the Adrino interface to see if it matches what is shown in the guide.


#3

I used the sketch provided by Matt with no changes.

/*
 * 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 = "Network";

// 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-BlindsControll"; 

//MQTT Server IP Address
const char* server = "192.168.1.104";

//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;
}

#4

Are you using the MQTT library I mention in the door sensor video?


#5

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.


#6

Ok, I played around with different versions of the libraries and got it working. Thanks.


#7

hey, what liberary did you end up using? i get the same error


#8

Hey I could Use some Help Fixing My Compiler Problems.

I loaded the .Json and ran it. But I get these Errors on compile.

D:\OxygenControl\MKBlinds\MK-BlindsControl\MK-BlindsControl.ino:21:24: fatal error: MQTTClient.h: No such file or directory

#include <MQTTClient.h>

                    ^

compilation terminated.

Multiple libraries were found for “Servo.h”
Used: C:\Users\Thomas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\Servo
Not used: C:\Program Files (x86)\Arduino\libraries\Servo
Using library Servo at version 1.0.2 in folder: C:\Users\Thomas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\Servo
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Thomas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi
exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).

Please Help I loaded the .json and ran it and it loaded.

HELP PLEASE


#9

Did you install the library?


#10

If anyone ever has this problem it means you have the wrong mqtt library. In the future go to my door sensor software video and pay attention to what library I use.