| 112 | } |
| 113 | |
| 114 | void YeelightController::SetMusicMode() |
| 115 | { |
| 116 | json command; |
| 117 | |
| 118 | char hostname[256]; |
| 119 | char* ip_addr; |
| 120 | struct hostent* host_entry; |
| 121 | |
| 122 | /*-----------------------------------------------------------------*\ |
| 123 | | The Yeelight bulb requires this PC's local IP address for music | |
| 124 | | mode. Get the first IP address of this computer's hostname, or | |
| 125 | | use the one defined | |
| 126 | \*-----------------------------------------------------------------*/ |
| 127 | if(host_ip.empty()) |
| 128 | { |
| 129 | gethostname(hostname, 256); |
| 130 | host_entry = gethostbyname(hostname); |
| 131 | ip_addr = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | ip_addr = &host_ip[0]; |
| 136 | } |
| 137 | |
| 138 | /*-----------------------------------------------------------------*\ |
| 139 | | Fill in the set_rgb command with RGB information. | |
| 140 | | The bulb will not respond to 0, 0, 0, so if all channels are zero,| |
| 141 | | set the state to off. Otherwise, set it to on. | |
| 142 | \*-----------------------------------------------------------------*/ |
| 143 | command["id"] = 1; |
| 144 | command["method"] = "set_music"; |
| 145 | command["params"][0] = 1; |
| 146 | command["params"][1] = ip_addr; |
| 147 | command["params"][2] = music_mode_port; |
| 148 | |
| 149 | /*-----------------------------------------------------------------*\ |
| 150 | | Convert the JSON object to a string and write it | |
| 151 | \*-----------------------------------------------------------------*/ |
| 152 | std::string command_str = command.dump().append("\r\n"); |
| 153 | |
| 154 | port.tcp_client_connect(); |
| 155 | port.tcp_client_write((char *)command_str.c_str(), command_str.length() + 1); |
| 156 | port.tcp_close(); |
| 157 | } |
| 158 | |
| 159 | void YeelightController::SetPower() |
| 160 | { |
nothing calls this directly
no test coverage detected