0

I am busy writing a simple program in python which takes information from the serial port and displays a graph of this to the user. (It is basically a energy meter connected to the serial port and the python program should display the voltage, current and power curves.)

However, I would really like to make this program accessible from the internet (ie: one open's a web browser on the remote computer, types in the host pc's ip address and some port and you are confronted with the voltage, current and power curves)

I am very new to python and the whole object oriented programing language. Most of my programing was done in C# in the past.

Is there a relatively easy way to 'port' a python program to some form of web accessible program/script. Possibly by using it in conjunction with a Apache server running on the host machine?

Any help with this would be much appreciated. Even if it just points me in the right direction.

Thanks so much.

EDIT: I have now been playing around with CGI and Apache and I see that it is possible to execute .py files in Apache as cgi-binaries. However, when I attempted to execute my complete python program (containing a Qt form and many push buttons and combo boxes) the page just kept on loading forever, until it displayed a server timeout. Is this because I am using CGI and not FastCGI? or is it not possible to 'port' Qt framework to HTML? Should I rather create a new GUI framework out of HTML code?

Thanks so much.

4

4 回答 4

2

最简单的方法(不影响机器的安全性)是让 python 脚本读取串行数据并使用matplotlib每分钟创建几个图形,并将它们写入 Web 服务器可以找到它们的地方,例如 PNG 文件。

然后您需要创建一个网页来显示图表。为安全起见,最好将其设为引用脚本制作的 PNG 文件的静态页面。也许放入一些 javastript 让页面定期刷新

最后但并非最不重要的是,您需要一个网络服务器。我建议使用nginx来提供这样的静态内容。

于 2012-09-23T12:57:31.627 回答
1

有很多基于 Python 的 Web 开发框架,例如 Django:https ://www.djangoproject.com 。您可以使用 Django 在 Python 中开发一个网站,然后从其中一个视图中调用您的脚本。您可以使用 Apache 部署您的 Django 项目:https ://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/

于 2012-09-23T12:35:53.533 回答
0

最简单的解决方案似乎是 CGI http://docs.python.org/library/cgi.html和 WSGI http://docs.python.org/library/wsgiref.html

但是,在这两种情况下,我都提醒您,Web 应用程序以其安全问题而闻名。当您是初学者时,您通常会打开许多​​安全漏洞,甚至不会注意到它……但互联网上的坏人会注意到。我建议至少使用用户名/密码保护页面。

于 2012-09-23T12:43:19.013 回答
-1

如果您可以在 Google App Engine 中运行 Python,为什么还要运行和维护自己的网络服务器。它简单、免费且几乎 100% 可靠。Google 负责网络服务器,您只需构建一个 Python 应用程序。串口客户端可以将数据发送到您的 App 引擎应用程序。

这是一个帮助您入门的教程:http: //aleatory.clientsideweb.net/2012/08/16/financial-charts-app-engine-tutorial-web-scraping/

这是向 App 引擎发送数据的 Python 示例:http: //aleatory.clientsideweb.net/2012/08/16/financial-charts-app-engine-tutorial-web-scraping/

于 2012-09-23T13:39:49.823 回答