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) : lamp(addr)
31  {
32  }
33 
34  ~YeelightBulb();
35 
38  bool connect();
39 
42  void sendCommand(String method, Vector<String> params);
43 
44  void on();
45  void off();
46  void setState(bool isOn);
47 
50  void updateState();
53  YeelightBulbState currentState() { return state; }
54 
55  void setBrightness(int percent);
56  void setRGB(byte r, byte g, byte b);
57  void setHSV(int hue, int sat);
58 
59 protected:
60  void ensureOn();
61  bool onResponse(TcpClient& client, char *data, int size);
62  void parsePower(const String& resp);
63 
64 private:
65  IPAddress lamp;
66  uint16_t port = 55443;
67 
68  TcpClient* connection = nullptr;
69  long requestId = 0;
70  long propsId = 0;
71  YeelightBulbState state = eYBS_Unknown;
72 };
73 
74 #endif /* SERVICES_YEELIGHTBULB_H_ */
void sendCommand(String method, Vector< String > params)
Send any command to the lamp.
The string class.
Definition: WString.h:104
Definition: TcpClient.h:40
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:53
Definition: IPAddress.h:37