Hi!
I'd like to create a library to use a class that controls the Yeelight Smart lights. I've got the code that sends the commands working so that is not an issue. Then I created the class within the main sketch and it worked perfectly.
Finally, when I try to move the class to a new library I can't get it to compile. I've been trying all kind of things I've seen online for hours but nothing seems to work!
I'm using the ESP8266-ESP12E.
The error message is:
Arduino: 1.8.1 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"
sketch\Toggle_Example_library.ino.cpp.o:(.text.setup+0x38): undefined reference to `Yeelight::begin(IPAddress, int)'
sketch\Toggle_Example_library.ino.cpp.o: In function `setup':
\\LS421DEE21\Javier\Arduino\Yeelight\Toggle_Example_library/Toggle_Example_library.ino:28: undefined reference to `Yeelight::begin(IPAddress, int)'
\\LS421DEE21\Javier\Arduino\Yeelight\Toggle_Example_library/Toggle_Example_library.ino:30: undefined reference to `Yeelight::toggle()'
sketch\Toggle_Example_library.ino.cpp.o: In function `loop':
\\LS421DEE21\Javier\Arduino\Yeelight\Toggle_Example_library/Toggle_Example_library.ino:33: undefined reference to `Yeelight::toggle()'
sketch\Toggle_Example_library.ino.cpp.o: In function `~Yeelight':
C:\Users\nadal\Documents\Arduino\libraries\Yeelight/Yeelight.h:14: undefined reference to `Yeelight::Yeelight()'
sketch\Toggle_Example_library.ino.cpp.o: In function `__static_initialization_and_destruction_0':
\\LS421DEE21\Javier\Arduino\Yeelight\Toggle_Example_library/Toggle_Example_library.ino:10: undefined reference to `Yeelight::Yeelight()'
collect2.exe: error: ld returned 1 exit status
The Sketch code is:
#include <Yeelight.h>
#include <ESP8266WiFi.h>
const char* ssid = "********";
const char* password = "********";
const int bulb_port = 55443;
IPAddress staticIP(**********);
IPAddress gateway(************);
IPAddress subnet(*************);
IPAddress Living_1(************);
Yeelight bulb;
void setup() {
pinMode(4,INPUT);
Serial.begin(115200);
while (!Serial) {
// wait Serial port initialization
}
WiFi.config(staticIP, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Started!");
bulb.begin(Living_1);
}
void loop() {
if (digitalRead(4)==HIGH){
bulb.toggle();
delay(200);
}
else { delay(50);}
}
The header Yeelight.h:
#ifndef Yeelight_h
#define Yeelight_h
#include "ESP8266WiFi.h"
#include "Arduino.h"
class Yeelight
{
public:
Yeelight();
void begin(IPAddress lightIP, int lightPort = 55443); //Port is optional as this is the default
void toggle();
private:
WiFiClient _client;
IPAddress _lightIP; //IP of the light to control with this instance
int _lightPort;//Port of the light to control with this instance
const String s="{\"id\":1,\"method\":\"";
const String t="\",\"params\":[";
const String u="]}\r\n";
};
#endif
The code Yeelight.ccp:
#include "Yeelight.h"
#include "ESP8266WiFi.h"
#include "Arduino.h"
Yeelight::Yeelight()
{
}
void Yeelight::begin(IPAddress lightIP, int lightPort)
{
_lightIP = lightIP;
_lightPort = lightPort;
}
void Yeelight::toggle()
{
_client.connect(_lightIP,_lightPort);
_client.print(s+"toggle"+t+u);
}
Any help will be much appreciated!
Thank you!