[英]Python reading from Arduino script still not working
iIve asked you few weeks ago about solution on my python's scripy problem. iIve几周前曾问过您有关我的Python问题的解决方案。
I just started my project again, and still got a problem. 我刚刚再次开始我的项目,但仍然遇到问题。
My Arduino is working fine, command sudo screen /dev/ttyACM0 is working perfect, and I'm getting: 我的Arduino运行正常,命令sudo屏幕/ dev / ttyACM0运行正常,我得到:
T: 52.80% 23.80 15% 92% N
T: 52.80% 23.80 15% 92% N
T: 52.80% 23.80 15% 92% N
I would like to use Python's script with cron to write a text file with results for every single sensor data. 我想将Python的脚本与cron一起使用,以编写一个文本文件,其中包含每个传感器数据的结果。
For example I'll use cron to save 4 text files (temp.txt, humi.txt, soil.txt, photo.txt) every 5 minutes, 30 minutes, 1 hour, 3 hours, 12 hours, 24 hours. 例如,我将使用cron每5分钟,30分钟,1小时,3小时,12小时,24小时保存4个文本文件(temp.txt,humi.txt,soil.txt,photo.txt)。
Next I'll use a php script to show data as diagrams on my website. 接下来,我将使用php脚本在网站上以图表形式显示数据。
But the problem is with my python script. 但是问题出在我的python脚本上。 I've got a solution here, and at the moment I'm using the following script (temperature's example):
我在这里有一个解决方案,此刻,我正在使用以下脚本(温度示例):
#!/usr/bin/python
import serial
import time
buffer = bytes()
ser = serial.Serial('/dev/ttyACM0',9600, timeout=10)
while buffer.count('T:') < 2:
buffer += ser.read(30)
ser.close();
# Now we have at least one complete datum. Isolate it.
start = buffer.index('T:')
end = buffer.index('T:', start+1)
items = buffer[start:end].strip().split()
print time.strftime("%Y-%m-%d %H:%M:%S"), items[2]
But in my text file I've got incorrect info, which looks like: 但是在我的文本文件中,我得到了不正确的信息,看起来像:
2013-05-10 19:47:01 12%
2013-05-10 19:48:01
2013-05-10 19:49:01 N
2013-05-10 19:50:01 24.10
2013-05-10 19:51:01 24.10
2013-05-10 19:52:01 7%
2013-05-10 19:53:01 24.10
but it should be 2013-05-10 19:47:01 24.10
all the time. 但应该一直都是
2013-05-10 19:47:01 24.10
。
What's wrong with it? 它出什么问题了?
I suspect that instead of 我怀疑不是
items = buffer[start:end].strip().split()
you want 你要
items = buffer[start:end].split().strip()
or maybe 或者可能
items = buffer[start:end].split()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.