I am building a car server with Raspberry Pi 3.
I am reading the speed variable from serial ports using Python.
This variable continuously changes as the car speed changes.
I want to display that value live, in a HTML file.
How can I do this?
I tried creating a text file from the Python script which constantly overwrites a speed.txt and prints on the HTML but as I read it is not secure and fast enough for monitoring.
Your Html page must be dynamic and communicate with a web server.
You have 2 options for updating the car speed :
use XHR and read the speed periodically from the web server
use websocket and let the server push the latest speed to your page.
You can use a framework like Flask for both options
Related
I have a elaborate Python script that does some image processing (opencv) and hardware management (sensors and motors) on a Raspberry Pi 4.
I'd like to have a web-page (hosted locally on the Pi) that people can go to by typing an address and getting an interactive UI to manage the script.
My question is about the web-page part: I am a complete noob in web development. What would be the easiest, fastest way to:
Prepare a webpage without coding
Host that page locally and give people access to it
Make the Python script output results to that page and be able to receive UI requests from the page (like buttons, data etc.)
Thank you.
I am trying to create a web interface to display some data that is being extracted live from a piece of hardware.
I have already written a program using pyQt that extracts data every second. I was wondering if it is possible to simultaneously push this data to a web interface with Python.
I want the webpage to not continuously refresh as data is coming in every second. Charts are essential, I have to have the ability to plot the data that is being pushed.
Can anyone suggest me how I would go about doing this?
Probably the most conventional way to go about this would be to write some server-side code to communicate with the device, and save responses (all of them? the most recent n?) to a database. You'd expose this to a REST API, which you'd then call at a specified interval using AJAX from the browser.
I have a python script that collects data on some virtual machines. I want to display this data in a webpage.The web page must be dynamic since the script will run continuously and the data must be updated every time the script runs. I possibly want this data displayed in a table but I am not sure what direction to go?
You could use Apache or another web server. Set up an HTML web page with javascript. I recommend using jQuery as it makes making ajax calls so much easier. Have your javascript/ajax/jquery call your python script every x minutes/seconds.
Ensure your apache server is setup to run CGI scripts and ensure they are set with read and execute permissions.
I'll briefly explain what I'm trying to achieve: We have a lot of servers behind ipvsadm VIPs (LVS load balancing) and we regularly move servers in/out of VIPs manually. To reduce risk (junior ops make mistakes...) I'd like to abstract it to a web interface.
I have a Python daemon which repeatedly runs "ipvsadm -l" to get a list of servers and statistics, then creates JSON from this output. What I'd now like to do is server this JSON, and have a web interface that can pass commands. For example, selecting a server in a web UI and pressing remove triggers an ipvsadm -d <server>... command. I'd also like the web UI to update every 10 seconds or so with the statistics from the list command.
My current Python daemon just outputs to a file. Should I somehow have this daemon also be a web server and serve its file and accept POST requests with command identifiers/arguments? Or a second daemon for the web UI? My only front end experience is with basic Bootstrap and jQuery usually backed by Laravel, so I'm not sure if there's a better way of doing this with sockets and some fancy JS modern-ism.
If there is a more appropriate place for this post, please move it if possible or let me know where to re-post.
You don't need fancy js application. To take the path of least resistance, I would create some extra application - if you like python, I recommend flask for this job. If you prefer php, then how about slim?
In your web application, if you want to make it fast and easy, you can even implement ajax mechanism fetching results based on interval to refresh servers' data every 10 seconds. You will fetch it from json served by independent, already existing deamon.
Running commands clicked on Web UI can be done by your web application.
Your web application is something extra and I find it nice to be separated from deamon which fetch data about servers and save it as json. Anytime you can turn off the page, but all statistics will be still fetching and available for console users in json format.
I'm looking for a bit of web development advice. I'm fairly new to the area but I'm sure there are some gurus out there willing to part with some wisdom.
Objective: I'm interested in controlling a Python application on my computer from my personal web hosted site. I know, this question has been asked several times before but in each case the requirements were a bit different from my own. To reduce the length of this post I'll summarize my objective in a few bullet points:
Personal site is hosted by a web hosting company
Site uses HTML, PHP, MySQL, Python and JavaScript, the majority of everything is coded by me from the ground up
An application that is coded in Python will run on a PC within my home and will communicate with an Arduino board
The app will receive commands from the internet to control actuation via the Arduino, and will transmit sensor data back to the site (such as temperature)
Looking for the communication to be bi-directional, fast and secure
Securing the connection between site and Python app would be most ideal
I'm not looking to connect to the Python application directly, the web server must serve as the 'middle man'
So far I've considered HTTP Post and HTML forms, using sockets (Python app would run as a web server), an IRC bot and reading/writing to a text file stored on the web server.
I was also hoping to have a way to communicate with the Python app without needing to refresh the webpage, perhaps using AJAX or JavaScipt? Maybe with Flash?
Is there something I'm not considering? I feel like I'm missing something. Thanks in advance for the advice!
Just thinking out loud for how I would start out with this. First, regarding the website itself, you can just use what's easiest to you, or to the environment you're in. For example, a basic PHP page will do just fine, but if you can get a site running in Python as well, I'd prefer using the same language all over.
That said, I'm not sure why you would need to use a hosted website? Given that you're already forced to have a externally accessible PC at home for the communication, why not run a webserver on that directly (Apache, Nginx, or even something like CherryPy should do)? That webserver can then communicate with the python process that is running to control your Arduino (by using e.g. Python's xmlrpclib). If you would run things via the hosting company, you would still need some process that can handle external requests securely... something a webserver is quite good at. Just running it yourself gives you all the freedom you want, and simplifies things by lessening the number of components in your solution.
The updates on your site I'd keep quite basic: commands you want to run can be handled in the request handlers of the webserver by just calling the relevant (xmlrpclib) calls. Dynamically updating the page is best done by some AJAX calls I reckon. Based on your story, these updates are easily put in a JSON object, suitable for periodically updating only the relevant segments of your page.