diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index 2ed0c0c..6997751 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -42,11 +42,20 @@ static void _macros_query_internal(){ } } +void power_devices_clear(){ + for (int i = 0; i < power_devices_count; i++){ + free(power_devices[i]); + } + + power_devices_count = 0; +} + void _power_devices_query_internal(){ String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/machine/device_power/devices"; HTTPClient client; client.useHTTP10(true); client.setTimeout(500); + client.setConnectTimeout(1000); client.begin(url.c_str()); int httpCode = client.GET(); if (httpCode == 200){ @@ -54,11 +63,7 @@ void _power_devices_query_internal(){ deserializeJson(doc, client.getStream()); auto result = doc["result"]["devices"].as(); - for (int i = 0; i < power_devices_count; i++){ - free(power_devices[i]); - } - - power_devices_count = 0; + power_devices_clear(); for (auto i : result){ const char * device_name = i["device"]; diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h index 6d58c25..1000dd3 100644 --- a/CYD-Klipper/src/core/macros_query.h +++ b/CYD-Klipper/src/core/macros_query.h @@ -15,4 +15,5 @@ MACROSQUERY macros_query(); POWERQUERY power_devices_query(); void macros_query_setup(); bool set_power_state(const char* device_name, bool state); -void _power_devices_query_internal(); \ No newline at end of file +void _power_devices_query_internal(); +void power_devices_clear(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 1c35aeb..683bf51 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -36,6 +36,7 @@ bool verify_ip(){ try { Serial.println(url); client.setTimeout(500); + client.setConnectTimeout(1000); client.begin(url.c_str()); httpCode = client.GET(); return httpCode == 200; @@ -227,13 +228,11 @@ void ip_init(){ void ip_ok(){ if (klipper_request_consecutive_fail_count > 5){ - ESP.restart(); - /* The below code doesn't work, fix later freeze_request_thread(); + power_devices_clear(); ip_init(); unfreeze_request_thread(); klipper_request_consecutive_fail_count = 0; lv_msg_send(DATA_PRINTER_STATE, &printer); - */ } } \ No newline at end of file