4
4
*/
5
5
6
6
#include " Yeelight.h" // Yeelight support
7
- #include " MySystem.h" // System-level definitions
8
-
9
- using namespace ds ;
7
+ #include < ESP8266WiFi.h> // Wi-Fi support
10
8
11
9
// Yeelight protocol; see https://www.yeelight.com/en_US/developer
12
10
const char *YL_MSG_TOGGLE = " {\" id\" :1,\" method\" :\" toggle\" ,\" params\" :[]}\r\n " ;
@@ -52,36 +50,36 @@ int YBulb::Flip(WiFiClient &wfc) const {
52
50
53
51
// Print bulb status in HTML
54
52
// TODO: synergy between two functions?
55
- void YBulb::printStatusHTML () const {
56
- System::web_page += " <li>id(" ;
57
- System::web_page += id;
58
- System::web_page += " ), ip(" ;
59
- System::web_page += ip;
60
- System::web_page += " ), name(" ;
61
- System::web_page += name;
62
- System::web_page += " ), model(" ;
63
- System::web_page += model;
64
- System::web_page += " )</li>" ;
53
+ void YBulb::printStatusHTML (String& str ) const {
54
+ str += " <li>id(" ;
55
+ str += id;
56
+ str += " ), ip(" ;
57
+ str += ip;
58
+ str += " ), name(" ;
59
+ str += name;
60
+ str += " ), model(" ;
61
+ str += model;
62
+ str += " )</li>" ;
65
63
}
66
64
67
65
// Print bulb configuration controls in HTML
68
- void YBulb::printConfHTML (uint8_t num) const {
69
- System::web_page += " <input type=\" checkbox\" name=\" bulb\" value=\" " ;
70
- System::web_page += num;
71
- System::web_page += " \" " ;
66
+ void YBulb::printConfHTML (String& str, uint8_t num) const {
67
+ str += " <input type=\" checkbox\" name=\" bulb\" value=\" " ;
68
+ str += num;
69
+ str += " \" " ;
72
70
if (active)
73
- System::web_page += " checked" ;
74
- System::web_page += " /> " ;
75
- System::web_page += ip;
76
- System::web_page += " id(" ;
77
- System::web_page += id;
78
- System::web_page += " ) name(" ;
79
- System::web_page += name;
80
- System::web_page += " ) model(" ;
81
- System::web_page += model;
82
- System::web_page += " ) power(" ;
83
- System::web_page += power ? " <b>on</b>" : " off" ;
84
- System::web_page += " )<br/>" ;
71
+ str += " checked" ;
72
+ str += " /> " ;
73
+ str += ip;
74
+ str += " id(" ;
75
+ str += id;
76
+ str += " ) name(" ;
77
+ str += name;
78
+ str += " ) model(" ;
79
+ str += model;
80
+ str += " ) power(" ;
81
+ str += power ? " <b>on</b>" : " off" ;
82
+ str += " )<br/>" ;
85
83
}
86
84
87
85
@@ -128,7 +126,6 @@ YBulb *YDiscovery::receive() {
128
126
while (isInProgress ()) {
129
127
int len = udp.parsePacket ();
130
128
if (len > 0 ) {
131
- System::log->printf (TIMED (" Received %d bytes from %s, port %d\n " ), len, udp.remoteIP ().toString ().c_str (), udp.remotePort ());
132
129
len = udp.read (discovery_reply, sizeof (discovery_reply));
133
130
if (len > 0 ) {
134
131
discovery_reply[len] = 0 ;
@@ -150,23 +147,16 @@ YBulb *YDiscovery::receive() {
150
147
port = strtok (nullptr , " :" );
151
148
if (host && port) {
152
149
new_bulb = new YBulb (token, host, atoi (port));
153
- } else
154
- System::log->printf (TIMED (" Bad address; ignoring 1 bulb\n " ));
150
+ }
155
151
} else if (!strncmp (token, " model: " , 7 )) {
156
- if (strtok (token, " " ) && new_bulb) {
152
+ if (strtok (token, " " ) && new_bulb)
157
153
new_bulb->SetModel (strtok (nullptr , " " ));
158
- System::log->printf (TIMED (" Bulb model: %s\n " ), new_bulb->GetModel ());
159
- }
160
154
} else if (!strncmp (token, " name: " , 6 )) {
161
- if (strtok (token, " " ) && new_bulb) {
162
- new_bulb->SetName (strtok (nullptr , " " ));
163
- System::log->printf (TIMED (" Bulb name: %s\n " ), new_bulb->GetName ()); // Currently, Yeelights always seem to return an empty name here :(
164
- }
155
+ if (strtok (token, " " ) && new_bulb)
156
+ new_bulb->SetName (strtok (nullptr , " " )); // Currently, Yeelights always seem to return an empty name here :(
165
157
} else if (!strncmp (token, " power: " , 7 )) {
166
- if (strtok (token, " " ) && new_bulb) {
158
+ if (strtok (token, " " ) && new_bulb)
167
159
new_bulb->SetPower (strcmp (strtok (nullptr , " " ), " off" ));
168
- System::log->printf (TIMED (" Bulb power: %s\n " ), new_bulb->GetPower () ? " on" : " off" );
169
- }
170
160
}
171
161
token = strtok_r (nullptr , " \r\n " , &line_ctx);
172
162
}
0 commit comments