Hi, I wanted to know if it is possible to get information from Python and display onto a app made using MIT App Inventor.
Currently the best solution I thought of is to create a web server using python that MIT App Inventor connects based on the video:
"Easy Python tutorial 16: Android-PC communication" from youtube but I don't understand it fully. What would be the best and easiest way to display python data onto a app using MIT App Inventor
The best and easiest way to communicate between any application is http requests as it is very easy to setup, gives modular structure. So if you want to communicate between python code and MIT app inventor you can make a python server which gives data to clients i.e. your MIT app.
Now to explain how to achieve this:
1. In python you can code to start a HTTP server, easiest way to create a http server is to make a flask server which will listen requests on specific endpoints. Endpoints here are URLs, for example: http://localhost/endpointName.
To make a flask server listening HTTP you can refer https://flask.palletsprojects.com/en/1.1.x/
from flask import Flask #import flask
app = Flask(__name__)
@app.route('/') #your first endpoint i.e. "http://localhost/"
def index():
return 'This works' #return data, here data is 'This works' string, you can also return html
Consider you want to send temperature data so you can make flask server serve on "/temperature" endpoint
from flask import Flask
temperature = ['100.0C', '101.02C', '99.99C'] #your data
api = Flask(__name__)
@app.route('/temperature', methods=['GET', 'POST']) #endpoint to get temperature data
def get_temperature_data():
return " ".join(temperature)
#best way is to keep your data organised like json and return json dump string here.
if __name__ == '__main__':
api.run() #start server when run this code
2. Now the second part is to configure MIT app inventor
Since your flask server is listening on http://localhost/temperature when you open this URL in browser you can see your data. So we have to open same URL in MIT app. MIT app inventor provides "Web" component to open urls and get their data.
So you put a web component in your app then use blocks to open http://localhost/temperature URL to get your data.
To open this URL you can use "set", "call" blocks and after "call" block when you receive data in "response content" you can process it in your app which can be done using blocks in "text" section.
To understand more about http you can refer HTTP requests and to send data from app to python flask server you can use HTTP GET and POST requests.
Hi, I wanted to know if it is possible to get information from Python and display...
Hi so I'm currently using MIT App Inventor to create a app and I wanted to know what would be the best way to link it with Python so that when I press a button in the app, a python script will run on my computer (ie something as simple as printing "hello world")
Hi, I am current using flask to run a python web application that currently just allows users to access a video camera on a localhost. As of now, I need to type python main.py to actually run the project and turn on the localhost. What I want to do is, be able to click a button in HTML, through google chrome, and just run the webcam like that. To sum it up, I want to click a simple button and...
Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...
Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...