Salandora / OctoPrint-Camera

GNU Affero General Public License v3.0
2 stars 0 forks source link

Flask and Knockout Js #1

Open tanthua opened 7 years ago

tanthua commented 7 years ago

Hi Salandora,

I'm working on a plugin that has the similar idea that you have here. What my plugin does is to have two buttons on Octoprint's tab using jinja2. First button is used to capture the image from mjpg-streamer. Second button is used to run a python script that process the image just captured and output it to the front-end on Octoprint's tab. However, I haven't been able to do that because of the lack knowledge of flask and tornado.

When I run a python script, say test.py, that has flask imported, it always outputs error "Address already in use." And I know the address is in use by OctoPrint. So is there any solution to have flask running on the same port with OctoPrint so that I can trigger it by a button on Jinja2?

Salandora commented 7 years ago

Well I guess you have 2 options here:

  1. Write a plugin that does what the script shall do. Kinda problematic if you want to also supply a video stream.
  2. Let your script attach to another port and set octoprint's snapshot url to this.

But to help you further I would need to know what your script shall do and how everything works together.

tanthua commented 7 years ago

Thanks so much for the response Salandora! I found the idea of wiring button to python script is not feasible due to my knowledge, so I decided to send the command line from octoprint to trigger it. My first command line is very simple: sudo wget http://localhost:8080/?action=snapshot -O /home/pi/webcam/output.jpg to obtain the picture.

Then my second command line would be: sudo python test.py where test.py will include the hardcoded path "/home/pi/webcam/output.jpg" to apply its OpenCV functions to display the dimensions of the image, etc.

It seems working fine for me. But I'd still like to make the GUI of my tab looks friendlier by:

  1. Display the image after the snapshot. I have tried in myplugin_tab.jinja2 : <p>img src = "path"<\p> but it does not seem like working because I know it has to somehow bind data from Knockout.js, which I don't know how.
  2. Display the values obtained from python script. Maybe dimensions of the image, etc. And again, based on what I have read so far, it has to do with data binding along with flask knowledge.

Hope you can have time and give me some hints and example. Thanks so much!