Last active
July 9, 2019 17:20
-
-
Save benfasoli/1b7a9970f32ab1e1fc51aa5dd7726d7b to your computer and use it in GitHub Desktop.
GRIMM 1.109 data logging interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# GRIMM data collection script | |
# Ben Fasoli | |
import serial as ser # serial port use | |
import datetime # time stamps (UTC) | |
import re # regular expression matching | |
# Path to serial device ID | |
serialpath = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0' | |
# Path for output csv files, ending in / | |
outpath = '/home/pi/data/' | |
# Serial baud rate | |
baud = 9600 | |
print('GRIMM data logger initializing') | |
print('Contact Ben Fasoli with issues\n') | |
# Initialize serial device | |
s = ser.Serial(serialpath, baud) | |
try: | |
while True: | |
# Initialize buffer | |
buf = [''] | |
while not buf[0].startswith('C'): | |
buf = [s.readline()] | |
tc = datetime.datetime.utcnow() | |
# Read three additional records | |
buf = buf + [s.readline() for x in range(3)] | |
# Coerce buffer to single line | |
buf = ' '.join(buf) | |
buf = buf.replace('\r', '').replace('\n', ' ') | |
buf = re.sub('C.:|c.:|C.;|c.;', '', buf) | |
buf = re.sub('\s+', ',', buf) | |
if buf.endswith(','): buf = buf[0:-1] | |
buf = str(tc) + buf + '\n' | |
# Save to file | |
print(buf) | |
filename = outpath + tc.strftime('%Y-%m-%d.csv') | |
with open(filename, 'a+') as f: | |
f.write(buf) | |
except (KeyboardInterrupt, SystemExit): | |
s.flush() | |
s.close() | |
print('\n\nClosed successfully.\n\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if ! /usr/bin/screen -ls | /bin/grep -q log; then | |
/usr/bin/screen -S logging -dm /home/pi/log.py | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment