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(){
|
void _power_devices_query_internal(){
|
||||||
String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/machine/device_power/devices";
|
String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/machine/device_power/devices";
|
||||||
HTTPClient client;
|
HTTPClient client;
|
||||||
client.useHTTP10(true);
|
client.useHTTP10(true);
|
||||||
client.setTimeout(500);
|
client.setTimeout(500);
|
||||||
|
client.setConnectTimeout(1000);
|
||||||
client.begin(url.c_str());
|
client.begin(url.c_str());
|
||||||
int httpCode = client.GET();
|
int httpCode = client.GET();
|
||||||
if (httpCode == 200){
|
if (httpCode == 200){
|
||||||
@@ -54,11 +63,7 @@ void _power_devices_query_internal(){
|
|||||||
deserializeJson(doc, client.getStream());
|
deserializeJson(doc, client.getStream());
|
||||||
auto result = doc["result"]["devices"].as<JsonArray>();
|
auto result = doc["result"]["devices"].as<JsonArray>();
|
||||||
|
|
||||||
for (int i = 0; i < power_devices_count; i++){
|
power_devices_clear();
|
||||||
free(power_devices[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
power_devices_count = 0;
|
|
||||||
|
|
||||||
for (auto i : result){
|
for (auto i : result){
|
||||||
const char * device_name = i["device"];
|
const char * device_name = i["device"];
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ MACROSQUERY macros_query();
|
|||||||
POWERQUERY power_devices_query();
|
POWERQUERY power_devices_query();
|
||||||
void macros_query_setup();
|
void macros_query_setup();
|
||||||
bool set_power_state(const char* device_name, bool state);
|
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 {
|
try {
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
client.setTimeout(500);
|
client.setTimeout(500);
|
||||||
|
client.setConnectTimeout(1000);
|
||||||
client.begin(url.c_str());
|
client.begin(url.c_str());
|
||||||
httpCode = client.GET();
|
httpCode = client.GET();
|
||||||
return httpCode == 200;
|
return httpCode == 200;
|
||||||
@@ -227,13 +228,11 @@ void ip_init(){
|
|||||||
|
|
||||||
void ip_ok(){
|
void ip_ok(){
|
||||||
if (klipper_request_consecutive_fail_count > 5){
|
if (klipper_request_consecutive_fail_count > 5){
|
||||||
ESP.restart();
|
|
||||||
/* The below code doesn't work, fix later
|
|
||||||
freeze_request_thread();
|
freeze_request_thread();
|
||||||
|
power_devices_clear();
|
||||||
ip_init();
|
ip_init();
|
||||||
unfreeze_request_thread();
|
unfreeze_request_thread();
|
||||||
klipper_request_consecutive_fail_count = 0;
|
klipper_request_consecutive_fail_count = 0;
|
||||||
lv_msg_send(DATA_PRINTER_STATE, &printer);
|
lv_msg_send(DATA_PRINTER_STATE, &printer);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user