jneilliii / OctoPrint-BedReady

11 stars 3 forks source link

Test image does not update in popup. #24

Open 3D-Lasers-Lab opened 5 months ago

3D-Lasers-Lab commented 5 months ago

image When doing multiple tests the test image never updates. See in the picture I attached how the match percent is out of range but the two images are basically the same. Steps to recreate: Take snapshot set reference image save Test reference Move the camera so the image will be different Test reference

the match percentage will change but the test image will be the same

3D-Lasers-Lab commented 5 months ago

This also happens when sending @bedready

3D-Lasers-Lab commented 5 months ago

Has to do with the fact the image is cached by the browser, I'm going to keep looking into this, see if I can find a solution.

3D-Lasers-Lab commented 5 months ago

This might also have to do with it being a previous version of octopi and not a current version if they are serving the images with the no caching tag in the recent versions

jneilliii commented 5 months ago

This is surely because of caching. Usually the easiest approach to get around this is adding a timestamp querystring to the end of the image URL. Maybe if we include that in the return response from the check_bed function that would do it.

https://github.com/jneilliii/OctoPrint-BedReady/blob/c004a9b9ff912fa0d560bb13aa859374406fb8b2/octoprint_bedready/__init__.py#L169

something like

 timestamp = datetime.datetime.now()
 return {"bed_clear": similarity > match_percentage, "test_image": f"{COMPARISON_FILENAME}?{timestamp:%Y%m%d%H%M%S}, "reference_image": reference, "similarity": round(similarity, 4)} 
jneilliii commented 5 months ago

Other option would be to append the timestamp on the js side here.

https://github.com/jneilliii/OctoPrint-BedReady/blob/c004a9b9ff912fa0d560bb13aa859374406fb8b2/octoprint_bedready/static/js/bedready.js#L130

const test_url = 'plugin/bedready/images/' + response.test_image + '?' + Date.now(); 
3D-Lasers-Lab commented 5 months ago

I did find this stack overflow post earlier https://stackoverflow.com/questions/1077041/refresh-image-with-a-new-one-at-the-same-url that had the same suggestion that you provided for js. I did try that but it does not seem to work. One thing that I did notice was that the address of the image in the html did not change, this is my first time working in js so not exactly sure how it should work. image

I did just try your python suggestion and that worked perfectly :) Thanks

I did change it a bit but I changed it to import time timestampurl = COMPARISON_FILENAME+"?t="+str(time.time()) return {"bed_clear": similarity > match_percentage, "test_image": timestampurl, "reference_image": reference, "similarity": round(similarity, 4)}

not sure how to format on github

3D-Lasers-Lab commented 5 months ago

Also huge thanks to you, I did finish modifying the plugin to support masking (I put it in the open issue where somebody requested it) and spent the day browsing forums and documentation and I swear over half of the forum posts had your name somewhere in them. I couldn't have finished my modifications without your help and the help that you have contributed to all over the different forums.