Fix Hue for ESP32

This commit is contained in:
Stephan Hadinger 2021-04-23 15:21:16 +02:00
parent 171f48c3ac
commit b1ed8f8e0d
2 changed files with 9 additions and 1 deletions

View File

@ -200,21 +200,24 @@ void HueRespondToMSearch(void)
if (PortUdp.beginPacket(udp_remote_ip, udp_remote_port)) { if (PortUdp.beginPacket(udp_remote_ip, udp_remote_port)) {
UnishoxStrings msg(HUE_RESP_MSG); UnishoxStrings msg(HUE_RESP_MSG);
char response[320]; char response[320];
snprintf_P(response, sizeof(response), msg[HUE_RESP_RESPONSE], WiFi.localIP().toString().c_str(), HueBridgeId().c_str()); snprintf_P(response, sizeof(response), msg[HUE_RESP_RESPONSE], NetworkAddress().toString().c_str(), HueBridgeId().c_str());
int len = strlen(response); int len = strlen(response);
String uuid = HueUuid(); String uuid = HueUuid();
snprintf_P(response + len, sizeof(response) - len, msg[HUE_RESP_ST1], uuid.c_str()); snprintf_P(response + len, sizeof(response) - len, msg[HUE_RESP_ST1], uuid.c_str());
PortUdp.write(response); PortUdp.write(response);
PortUdp.endPacket(); PortUdp.endPacket();
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_UPNP "UDP resp=%s"), response);
snprintf_P(response + len, sizeof(response) - len, msg[HUE_RESP_ST2], uuid.c_str(), uuid.c_str()); snprintf_P(response + len, sizeof(response) - len, msg[HUE_RESP_ST2], uuid.c_str(), uuid.c_str());
PortUdp.write(response); PortUdp.write(response);
PortUdp.endPacket(); PortUdp.endPacket();
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_UPNP "UDP resp=%s"), response);
snprintf_P(response + len, sizeof(response) - len, msg[HUE_RESP_ST3], uuid.c_str()); snprintf_P(response + len, sizeof(response) - len, msg[HUE_RESP_ST3], uuid.c_str());
PortUdp.write(response); PortUdp.write(response);
PortUdp.endPacket(); PortUdp.endPacket();
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_UPNP "UDP resp=%s"), response);
snprintf_P(message, sizeof(message), PSTR(D_3_RESPONSE_PACKETS_SENT)); snprintf_P(message, sizeof(message), PSTR(D_3_RESPONSE_PACKETS_SENT));
} else { } else {

View File

@ -239,7 +239,12 @@ void ZigbeeHandleHue(uint16_t shortaddr, uint32_t device_id, String &response) {
if (Webserver->args()) { if (Webserver->args()) {
response = "["; response = "[";
#ifdef ESP82666 // ESP8266 memory is limited, avoid copying and modify in place
JsonParser parser((char*) Webserver->arg((Webserver->args())-1).c_str()); JsonParser parser((char*) Webserver->arg((Webserver->args())-1).c_str());
#else // does not work on ESP32, we need to get a fresh copy of the string
String request_arg = Webserver->arg((Webserver->args())-1);
JsonParser parser((char*) request_arg.c_str());
#endif
JsonParserObject root = parser.getRootObject(); JsonParserObject root = parser.getRootObject();
JsonParserToken hue_on = root[PSTR("on")]; JsonParserToken hue_on = root[PSTR("on")];