iIve asked you few weeks ago about solution on my python's scripy problem.
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:
T: 52.80% 23.80 15% 92% N
T: 52.80% 23.80 15% 92% N
T: 52.80% 23.80 15% 92% N
- T - letter is separator between next row
- First number is Humidity
- Second is temperature
- Third is photoresistor
- Next one is soil moisure
- and last one is fan working state (N - not working, Y - working)
I would like to use Python's script with cron to write a text file with results for every single sensor data.
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.
Next I'll use a php script to show data as diagrams on my website.
But the problem is with my python script. 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.
What's wrong with it?
print time.strftime("%Y-%m-%d %H:%M:%S"), items[2], repr(buffer)
to see what exactly you are parsing each time? – Martijn Pieters 2 days ago