I would like to read from the serial of RPi and store the data in a daily folder as a 'csv.' file. I can create a file, write/read to/from csv file and had the serial comm working with putty for now (tried in a different project). In the future, the comm is going to be between pi and a various sensor. Considering everything else is working I am not sure how to create a seperate file automatically for each day. This is what I've done so far;
import serial
import time
import csv
def readLine(port)
rv = ""
while True:
ch = port.read()
rv += ch
if ch == '\r' or ch =='':
return rv
port = serial.Serial("/dev/ttyAMA0", baudrate = 115200, timeout = 10)
while True:
rcv=readLineCR(port)
str1 = time.strftime("%d%m%y")
file = open('directory....')
with open('test.csv', 'w') as fp:
a = csv.writer(fp, delimiter=',')
# data to be tested
data = [[str1,'1234'],[str1,'4321']]
a.writerows(data)
print('csv is created on: ' + str1)
reader = csv.reader(file)
for line in reader:
print(line)
Any help would be appreciated