I'm trying to build a webserver using Apache and I want to establish two-way of communication between my python application and webserver where I can listen for requests from apache and return data back, in the same time I want the client to interact only with the webserver.
In my python program I'm using python python-twisted and pymodbus (MODBUS-TCPIP) to get some data from a PLC.
I have already configured a websocket in python using
from autobahn.twisted.websocket import WebSocketServerProtocol, \
WebSocketServerFactory
I'm thinking to configure a intermediate web which will be initiated upon http request of the main website and open websocket connection with python and start receiving data, where the clients (browsers) can still request data using jquery.
I don't know if this is the right way to go. Do you guys have better way to pass data variable between python and apache back and forth?
If I understood correctly, you want to make PLC data accessible on a web page.
The right way to develop a web application in Python is to use a web framework like Django, or (if you want something lighter) bottle
With this, you can develop a web page where you connect to your PLC over Modbus, query some values, disconnect and return a response with data as json.
But I think, this is not the best architecture because if you have several people accessing your web page, it will cause several connections to your PLC and you may have poor performance for your web app.
I think you had better develop a modbus program which is reading the data from the PLC and store it into a database. Then your web app just gets the data from the database.
I hope it helps
Related
I’ve got a standard client-server set-up with ReScript (ReasonML) on the front-end and a Python server on the back-end.
The user is running a separate process on localhost:2000 that I’m connecting to from the browser (UI). I can send requests to their server and receive responses.
Now I need to issue those requests from my back-end server, but cannot do so directly. I’m assuming I need some way of doing it through the browser, which can talk to localhost on the user’s computer.
What are some conceptual ways to implement this (ideally with GraphQL)? Do I need to have a subscription or web sockets or something else?
Are there any specific libraries you can recommend for this (perhaps as examples from other programming languages)?
I think the easiest solution with GraphQL would be to use Subscriptions indeed, the most common Rescript GraphQL clients already have such a feature, at least ReasonRelay, Reason Apollo Hooks and Reason-URQL have it.
I have the bulk of my web application in React (front-end) and Node (server), and am trying to use Python for certain computations. My intent is to send data from my Node application to a Python web service in JSON format, do the calculations in my Python web service, and send the data back to my Node application.
Flask looks like a good option, but I do not intend to have any front-end usage for my Python web service. Would appreciate any thoughts on how to do this.
In terms of thoughts:
1) You can build a REST interface to your python code using Flask. Make REST calls from your nodejs.
2) You have to decide if your client will wait synchronously for the result. If it takes a relatively long time you can use a web hook as a callback for the result.
I am trying to create a script that acts as a local web-service. I am making an inventory management for my own materials and I would like a python script to host a small server or something where I can type in the IP address, or possibly a command, in my web-browser and it will load the data.
My inventory is stored in a CSV file which, when connected to, the script would parse the csv to an html file and then run a server along with some javascript to make it more responsive.
How would I interface this python module to do all of that? I've never done any direct server programming. I've only done node.js, and then client-side web programming in regards to the internet.
For dealing wit raspberry pi and servers I will suggest Flask, which is Python lightweight web framework. Development in it is very fast. Some reading you can find here (in generally this blog is very good and exhaustive tutorial for Flask):
http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux-even-on-the-raspberry-pi
In fact you can run some lighthweight single file solution also with pyramid. look at:
http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/single_file_tasks/single_file_tasks.html
I need a sort of consultation. I am building a web app in django(hosted in heroku) which need to communicate with 100 of embedded devices(writing in C++/C). The embedded devices send data(50kb) to the web app and the web app present this information in a form of graphs.
My concern is , is it wise to build a python polling system(Socket communication) in the server side ?
Or is it Error-prone and I should use services like CloudMQTT?
Thank you in advance for your answers.
Unless you wanna have another project on your hands, it'd be best to use a dedicated library.
This isn't python specific, but I feel like you could achieve your goal relatively easy with a simple ajax request.
Check out The WebSocket API.
EDIT:
Upon further reading I found the Python port of websockets
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.