Add command line argument parsing for python scripts
This commit is contained in:
parent
4171882bd3
commit
f41f6ee2ca
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
import board
|
import board
|
||||||
import time
|
import time
|
||||||
import busio
|
import busio
|
||||||
@ -8,6 +9,12 @@ from adafruit_ads1x15.analog_in import AnalogIn
|
|||||||
from time import sleep, strftime
|
from time import sleep, strftime
|
||||||
from rpi_lcd import LCD
|
from rpi_lcd import LCD
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='GPS Logger')
|
||||||
|
parser.add_argument('-o', '--output', help='Output file', required=True)
|
||||||
|
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lcd = LCD(bus=2)
|
lcd = LCD(bus=2)
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -22,16 +29,15 @@ ads = ADS.ADS1015(i2c)
|
|||||||
# Create single-ended input on channel 0
|
# Create single-ended input on channel 0
|
||||||
# tmp36 = AnalogIn(ads, ADS.P0)
|
# tmp36 = AnalogIn(ads, ADS.P0)
|
||||||
|
|
||||||
# Attempting to create a single-ended input on channel 1
|
# Create a single-ended input on channel 1
|
||||||
depthS = AnalogIn(ads, ADS.P1)
|
depthS = AnalogIn(ads, ADS.P1)
|
||||||
|
|
||||||
# Subtract the offset from the sensor voltage
|
# Subtract the offset from the sensor voltage
|
||||||
# and convert chan.voltage * (1 degree C / 0.01V) = Degrees Celcius
|
# and convert chan.voltage * (1 degree C / 0.01V) = Degrees Celcius
|
||||||
# temperatureC = (tmp36.voltage - 0.5) / 0.01
|
# temperatureC = (tmp36.voltage - 0.5) / 0.01
|
||||||
|
|
||||||
# Open the file to write down the results
|
# File to write down the results
|
||||||
timestr = time.strftime("%Y-%m-%dT%H-%M-%S")
|
filename = args.output + time.strftime("%Y-%m-%dT%H-%M-%S") + "_depth_data.csv"
|
||||||
filename = "/home/shared/hydrophonitor/data/depth/" + timestr + "_depth_data.csv"
|
|
||||||
|
|
||||||
#depthM = ((depthS.voltage * 31.848) - 22.93)
|
#depthM = ((depthS.voltage * 31.848) - 22.93)
|
||||||
|
|
||||||
@ -58,5 +64,8 @@ with open(filename, "w", 1) as f:
|
|||||||
lcd.text((str(roundvolts) + " V ") + (str(rounddepth) + " m"), 1)
|
lcd.text((str(roundvolts) + " V ") + (str(rounddepth) + " m"), 1)
|
||||||
f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + ",")
|
f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + ",")
|
||||||
f.write(str(roundvolts) + "," + str(rounddepth) + "\n")
|
f.write(str(roundvolts) + "," + str(rounddepth) + "\n")
|
||||||
|
|
||||||
time.sleep(3)
|
if args.interval:
|
||||||
|
time.sleep(int(args.interval))
|
||||||
|
else:
|
||||||
|
time.sleep(5)
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from gps import *
|
from gps import *
|
||||||
from time import sleep, strftime
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
filename = "/home/shared/logger-raspi-setup/data/gps/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv"
|
parser = argparse.ArgumentParser(description='GPS Logger')
|
||||||
# filename = "/mnt/myssd/GPS_Data" + timestr +".csv"
|
parser.add_argument('-o', '--output', help='Output file', required=True)
|
||||||
|
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
filename = args.output + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv"
|
||||||
|
|
||||||
with open(filename, "w", 1) as f:
|
with open(filename, "w", 1) as f:
|
||||||
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
|
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
|
||||||
@ -21,8 +27,11 @@ with open(filename, "w", 1) as f:
|
|||||||
sats = str(len(gpsd.satellites))
|
sats = str(len(gpsd.satellites))
|
||||||
|
|
||||||
f.write(GPStime + "," + lat +"," + lon + "," + speed + "," + sats + "\n")
|
f.write(GPStime + "," + lat +"," + lon + "," + speed + "," + sats + "\n")
|
||||||
|
|
||||||
time.sleep(5)
|
if args.interval:
|
||||||
|
time.sleep(int(args.interval))
|
||||||
|
else:
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
||||||
print("Done.\nExiting.")
|
print("Done.\nExiting.")
|
||||||
|
Loading…
Reference in New Issue
Block a user