From 2b87817ba2612eb4c26c4aa06c6ee90d655cfaec Mon Sep 17 00:00:00 2001 From: lost-hope Date: Sun, 19 Feb 2023 09:08:40 +0100 Subject: [PATCH] enabled IP Change and updated the Readme --- .../usermod_v2_klipper_percentage/readme.md | 17 ++++++++- .../usermod_v2_klipper_percentage.h | 35 ++++++++++++------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/usermods/usermod_v2_klipper_percentage/readme.md b/usermods/usermod_v2_klipper_percentage/readme.md index 551382565..a1581cf21 100644 --- a/usermods/usermod_v2_klipper_percentage/readme.md +++ b/usermods/usermod_v2_klipper_percentage/readme.md @@ -1,5 +1,7 @@ # Klipper Percentage Usermod This usermod polls the Klipper API every 10s for the progressvalue. +The leds are then filled with a solid color according to that progress percentage. +the solid color is the secondary color of the segment. A corresponding curl command would be: ``` @@ -12,9 +14,22 @@ You can also use the WLBD bot in the Discord by simply extending an exsisting bu ``` [env:esp32klipper] extends = env:esp32dev -build_flags = -D USERMOD_KLIPPER_PERCENTAGE +build_flags = ${common.build_flags_esp32} -D USERMOD_KLIPPER_PERCENTAGE ``` +## Settings + +### Enabled: +Checkbox to enable or disable the overlay + +### Klipper IP: +IP adress of your Klipper instance you want to poll. ESP has to be restarted after change + +### Direction : +0 = normal + +1 = reversed + ----- Author: diff --git a/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h b/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h index 82d762757..0bd798d5c 100644 --- a/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h +++ b/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h @@ -22,7 +22,7 @@ private: // is this the most compact way to do http get and put it in arduinojson object??? // would like async response ... ??? client.setTimeout(10000); - if (!client.connect("192.168.25.209", 80)) + if (!client.connect(ip.c_str(), 80)) { strcat(errorMessage, PSTR("Connection failed")); } @@ -30,7 +30,7 @@ private: { // Send HTTP request client.println(F("GET /printer/objects/query?virtual_sdcard=progress HTTP/1.0")); - client.println(F("Host: 192.168.25.209")); + client.println("Host: " + ip); client.println(F("Connection: close")); if (client.println() == 0) { @@ -86,12 +86,17 @@ public: strcat(errorMessage, error.c_str()); } printPercent = (int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100); - //DEBUG_PRINTLN(errorMessage); - DEBUG_PRINT("Percent: " ); + + DEBUG_PRINT("Percent: "); DEBUG_PRINTLN((int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100)); - DEBUG_PRINT("LEDs: " ); + DEBUG_PRINT("LEDs: "); DEBUG_PRINTLN(strip.getLengthTotal() * printPercent / 100); } + else + { + DEBUG_PRINTLN(errorMessage); + DEBUG_PRINTLN(ip); + } lastTime = millis(); } } @@ -103,7 +108,6 @@ public: top["Enabled"] = enabled; top["Klipper IP"] = ip; top["Direction"] = direction; - } bool readFromConfig(JsonObject &root) @@ -125,6 +129,7 @@ public: * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. * Below it is shown how this could be used for e.g. a light sensor */ + /* TODO: NOT WORKING YET void addToJsonInfo(JsonObject &root) { JsonObject user = root["u"]; @@ -144,6 +149,7 @@ public: infoArr.add(uiDomString); } + void addToJsonState(JsonObject &root) { JsonObject usermod = root[FPSTR(_name)]; @@ -153,15 +159,18 @@ public: } usermod["on"] = enabled; } - void readFromJsonState(JsonObject& root) + void readFromJsonState(JsonObject &root) + { + JsonObject usermod = root[FPSTR(_name)]; + if (!usermod.isNull()) { - JsonObject usermod = root[FPSTR(_name)]; - if (!usermod.isNull()) { - if (usermod[FPSTR(_enabled)].is()) { - enabled = usermod[FPSTR(_enabled)].as(); - } + if (usermod[FPSTR(_enabled)].is()) + { + enabled = usermod[FPSTR(_enabled)].as(); } } + } + */ /* * handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors. @@ -198,5 +207,5 @@ public: return USERMOD_ID_KLIPPER; } }; -const char klipper_percentage::_name[] PROGMEM = "Klipper Percentage"; +const char klipper_percentage::_name[] PROGMEM = "Klipper_Percentage"; const char klipper_percentage::_enabled[] PROGMEM = "enabled"; \ No newline at end of file