This is a little of a newb question but I am trying to write a program in Django which controls an arduino from a django site though a serial connection. As an ardunio has a 'feature' which resets it when a new serial connection is made it means that it can't constantly just send the single command every time the page is loaded. So I am wondering:
这是一个新问题,但我正在尝试在Django中编写一个程序,它通过串行连接控制django站点的arduino。由于ardunio具有一个“功能”,当新的串行连接建立时它会重置它,这意味着每次加载页面时它都不能一直发送单个命令。所以我想知道:
I have already written the python program which controls the arduino over the serial port with no problems.
我已经编写了python程序,它可以在串口上控制arduino而不会出现问题。
Is it possible to run a python script in the background (i.e. it stays active and keeps the serial connection active) of a django app/site and if so how to communicate with that running process via django so I can have pages with buttons which then pass a value to that background process?
是否可以在django app / site的后台运行python脚本(即它保持活动并保持串行连接处于活动状态),如果是,如何通过django与该运行进程进行通信,这样我就可以拥有带按钮的页面了将值传递给该后台进程?
1 个解决方案
#1
1
Django-celery is great for background task processing. It sounds like you could just make your arduino code a celery task. That makes things really easy - the task has full access to your django models, and the django process can kick off a task anytime.
Django-celery非常适合后台任务处理。听起来你可以让你的arduino代码成为芹菜任务。这让事情变得非常简单 - 任务可以完全访问你的django模型,而django进程可以随时启动任务。
Plus celery is a great Swiss Army knife tool that you can use anytime you need something that takes longer than a request and response cycle.
加上芹菜是一种很棒的瑞士军刀工具,您可以随时使用需要比请求和响应周期更长的东西。
This looked like a good ref to me:
这看起来对我很好:
I'd probably suggest using redis as a broker these days, b/c you can use redis as your cache too.
我可能建议现在使用redis作为经纪人,b / c你也可以使用redis作为你的缓存。
#1
1
Django-celery is great for background task processing. It sounds like you could just make your arduino code a celery task. That makes things really easy - the task has full access to your django models, and the django process can kick off a task anytime.
Django-celery非常适合后台任务处理。听起来你可以让你的arduino代码成为芹菜任务。这让事情变得非常简单 - 任务可以完全访问你的django模型,而django进程可以随时启动任务。
Plus celery is a great Swiss Army knife tool that you can use anytime you need something that takes longer than a request and response cycle.
加上芹菜是一种很棒的瑞士军刀工具,您可以随时使用需要比请求和响应周期更长的东西。
This looked like a good ref to me:
这看起来对我很好:
I'd probably suggest using redis as a broker these days, b/c you can use redis as your cache too.
我可能建议现在使用redis作为经纪人,b / c你也可以使用redis作为你的缓存。