Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
YeelightBulb.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  ****/
7 
8 #include "../Wiring/WiringFrameworkDependencies.h"
9 #include "../Wiring/WHashMap.h"
10 #include "../Wiring/WVector.h"
11 #include "../Wiring/WString.h"
12 #include "IPAddress.h"
13 class TcpClient;
14 
15 #ifndef SERVICES_YEELIGHTBULB_H_
16 #define SERVICES_YEELIGHTBULB_H_
17 
18 enum YeelightBulbState
19 {
20  eYBS_Unknown = -1,
21  eYBS_Off = 0,
22  eYBS_On = 1
23 };
24 
28 {
29 public:
30  YeelightBulb(IPAddress addr);
31  ~YeelightBulb();
32 
35  bool connect();
36 
39  void sendCommand(String method, Vector<String> params);
40 
41  void on();
42  void off();
43  void setState(bool isOn);
44 
47  void updateState();
50  YeelightBulbState currentState() { return state; }
51 
52  void setBrightness(int percent);
53  void setRGB(byte r, byte g, byte b);
54  void setHSV(int hue, int sat);
55 
56 protected:
57  void ensureOn();
58  bool onResponse(TcpClient& client, char *data, int size);
59  void parsePower(const String& resp);
60 
61 private:
62  IPAddress lamp;
63  uint16_t port = 55443;
64 
65  TcpClient* connection = nullptr;
66  long requestId = 0;
67  long propsId;
68  YeelightBulbState state = eYBS_Unknown;
69 };
70 
71 #endif /* SERVICES_YEELIGHTBULB_H_ */
void sendCommand(String method, Vector< String > params)
Send any command to the lamp.
Definition: WString.h:42
Definition: TcpClient.h:35
Yeelight wifi bulb controller class.
Definition: YeelightBulb.h:27
void updateState()
Start async reading of current lamp state.
bool connect()
Can be skipped. This method will be called automatically from any action method below.
YeelightBulbState currentState()
Get current lamp state (should be called only after updateState)
Definition: YeelightBulb.h:50
Definition: IPAddress.h:30