Create a gist now

Instantly share code, notes, and snippets.

@reinvented /amr.py
Last active Aug 29, 2015

TIny script to log data from a Grid Insight AMRUSB-1
#!/usr/bin/env python
import serial, sys
from time import strftime
print "Connecting to AMRUSB-1. Press Control+C to abort."
logfilename = 'amrusb-1-' + strftime("%Y%m%d%H%M%S") + 'log'
f = open(logfilename, 'w')
ser = serial.Serial('/dev/ttyACM0')
while True:
try:
line = ser.readline()
logline = strftime("%Y-%m-%d %H:%M:%S") + "\t" + line
sys.stdout.write(logline)
f.write(logline)
except (KeyboardInterrupt, SystemExit):
f.close()
print "Exiting..."
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment