I'm currently building a new plugin for OctoPrint running on Rasberry Pi 3. What I want it to do is to have a HTML front-end tab that contains two buttons. Then the first button should be able to trigger a command line to capture the image from mjpg-stremaer, and another button to run a python script with imported OpenCV that will do edge detection and output to the front-end the image after process.
From OctoPrint, it uses jinja2 template for front-end and KnockOut.js for view model. This is where I got stuck because I have no clue how to do next due to my limited knowledge about web application.
After online search, I found that either flask or tornado is mentioned a lot. I tried using flask
as recommended after online search but it ran into the
Error 98: "Address already in use"
issue because OctoPrint is running on it. So, my question is if there is a way to do such things? In other words, is there a way to click on HTML buttons to trigger python and command line in the Raspberry Pi without having the port or socket issue?
The python code got from flask
, which will be the python code with OpenCV imported and do image processing:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
The HTML code using jinja2
, currently using the button to display date and time, but will trigger the python code above and a command line:
<html>
<body>
<h1>Java Script</h1>
<button type="button" onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html>
And my command line to capture picture from mpjg-streamer is:
wget http://localhost:8080/?action=snapshot -O output.jpg
If possible, please provide me an example with explanation for it and also introduction about server and client side concepts? Thanks. My apology if there is any false usage of terminology here.