I am using a script that takes the arduino serial and writes it to an out.dat file. The scripts works fine when run after boot, however when I added the script to
/etc/rc.local it runs the script, but does not record the information
#!/usr/bin/python # get lines of text from serial port, save them to a file from __future__ import print_function import serial, io import datetime addr = '/dev/ttyACM0' # serial port to read data from baud = 9600 # baud rate for serial port fname = 'gps-log'+datetime.datetime.now().strftime("%m-%d-%Y %H-%M-%S")+'.dat' # log file to save data in fmode = 'a' # log file mode = append with serial.Serial(addr,9600) as pt, open(fname,fmode) as outf: spb = io.TextIOWrapper(io.BufferedRWPair(pt,pt,1), encoding='ascii', errors='ignore', newline='\r',line_buffering=True) spb.readline() # throw away first line; likely to start mid-sentence (incomplete) while (1): x = spb.readline() # read one line of text from serial port print (x,end='') # echo line of text on-screen outf.write(x) # write line of text to file outf.flush() # make sure it actually gets written out
Note, it is supposed to create a new file named after the date and time. When I boot to command line, it prints the serial, so I know the program has executed. However, when I power down there is no .dat file to be found.