0

This might be a simple architecture question but I can't figure it out.

What I have:

Basically I have two apps running locally on my Raspberry pi:

  • One C++ app (Voicecommand) that allows me to execute commands from my microphone and run various python scripts. On certain keywords, I can run a python script to open the browser or do anything.
  • One simple Flask app, with a couple of basic views

What I want:

When I say a keyword (e.g. weather), I want my local Flask app to return the weather (already have the function and view for this), ideally in small frame without reloading the whole page.

What I thought about:

I thought about having my local app making JS calls within the browser but couldn't really figure out how. Best thing I could think of was an equivalent of Applescript to inject the JS call in the browser... From then, I could easily make an ajax call to my weather view and return the result without refreshing the page. I also thought about using something like React or Angular, or connecting the two apps but I'm not 100% sure on how.

1 Answer 1

1

This is somewhat tricky because you want to update a client based on some event on the server, where normally the interaction is all one way (i.e. client makes a request, server responds, that's it).

What I would do is set up some sort of two way protocol, such as WebSockets. One decent library for Flask is Flask-SocketIO. You can then have your Python scripts from the C++ app hit an endpoint in your Flask app, and that endpoint can emit() a message to the client. On the client side, you can receive these events and update your views accordingly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.