mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Properly fix #45
This commit is contained in:
@@ -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<JsonArray>();
|
||||
|
||||
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"];
|
||||
|
||||
@@ -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();
|
||||
void _power_devices_query_internal();
|
||||
void power_devices_clear();
|
||||
@@ -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);
|
||||
*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user