diff --git a/depth-logger/record-depth.py b/depth-logger/record-depth.py index bdfb9da..b801707 100644 --- a/depth-logger/record-depth.py +++ b/depth-logger/record-depth.py @@ -46,7 +46,7 @@ interval = int(args.interval) if args.interval else 5 #bar = psi * 14.503773800722 with open(filename, "w", 1) as f: - print(f"Writing pressure/depth output to {filename}, interval {interval} seconds") + print(f"Writing pressure/depth output to {filename}, interval {interval} seconds", flush=True) f.write("time and date, Voltage of depth sensor (V), Depth (m)\n") try: @@ -57,7 +57,7 @@ with open(filename, "w", 1) as f: roundvolts = round(voltage, 3) # roundtemp = round(temperatureC, 2) - print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m")) + print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m"), flush=True) # if lcd: # lcd.clear() @@ -68,4 +68,4 @@ with open(filename, "w", 1) as f: time.sleep(interval) except (KeyboardInterrupt, SystemExit): # when you press ctrl+c - print("Exiting depth recording.") + print("Exiting depth recording.", flush=True) diff --git a/depth-logger/requirements.txt b/depth-logger/requirements.txt new file mode 100644 index 0000000..1a18997 --- /dev/null +++ b/depth-logger/requirements.txt @@ -0,0 +1,2 @@ +Adafruit-Blinka==8.5.0 +adafruit-circuitpython-ads1x15==2.2.21 \ No newline at end of file diff --git a/gps-logger/record-gps.py b/gps-logger/record-gps.py index e7b179d..97b2a54 100644 --- a/gps-logger/record-gps.py +++ b/gps-logger/record-gps.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -from gps import * +import gpsd import time import argparse @@ -15,24 +15,25 @@ filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.c interval = int(args.interval) if args.interval else 5 with open(filename, "w", 1) as f: - gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) + gpsd.connect() - print(f"Writing GPS output to {filename}, interval {interval} seconds") - f.write("GPStime utc,latitude,longitude,speed,sats in view\n") + print(f"Writing GPS output to {filename}, interval {interval} seconds", flush=True) + f.write("system_time,gps_time_utc,latitude,longitude,speed,sats_in_view\n") - try: - while True: - report = gpsd.next() - if report["class"] == "TPV": - GPStime = str(getattr(report,"time","")) - lat = str(getattr(report,"lat",0.0)) - lon = str(getattr(report,"lon",0.0)) - speed = str(getattr(report,"speed","nan")) - sats = str(len(gpsd.satellites)) - - f.write(GPStime + "," + lat +"," + lon + "," + speed + "," + sats + "\n") - - time.sleep(interval) - - except (KeyboardInterrupt, SystemExit): # when you press ctrl+c - print("Exiting GPS recording.") + while True: + try: + packet = gpsd.get_current() + gps_time_utc = str(packet.time) if packet.mode >= 2 else "-" + lat = str(packet.lat) if packet.mode >= 2 else "0.0" + lon = str(packet.lon) if packet.mode >= 2 else "0.0" + speed = str(packet.hspeed) if packet.mode >= 2 else "0.0" + sats = str(packet.sats) + system_time = time.strftime("%Y-%m-%dT%H-%M-%S") + f.write(f"{system_time},{gps_time_utc},{lat},{lon},{speed},{sats}\n") + except (KeyboardInterrupt, SystemExit): # when you press ctrl+c + print("Exiting GPS recording.", flush=True) + break + except Exception as e: + print(f"GPS error: {e}", flush=True) + + time.sleep(interval) diff --git a/gps-logger/requirements.txt b/gps-logger/requirements.txt new file mode 100644 index 0000000..2a628b2 --- /dev/null +++ b/gps-logger/requirements.txt @@ -0,0 +1 @@ +gpsd-py3==0.3.0 \ No newline at end of file diff --git a/scripts/setup-gps.sh b/scripts/setup-gps.sh index 50babcf..81258d9 100755 --- a/scripts/setup-gps.sh +++ b/scripts/setup-gps.sh @@ -5,6 +5,8 @@ echo "Setting up GPS recording" sudo apt-get update && sudo apt-get install -y \ gpsd gpsd-clients +sudo pip install -r /home/pi/hydrophonitor/gps-logger/requirements.txt + sudo systemctl stop gpsd.socket sudo systemctl disable gpsd.socket diff --git a/scripts/setup-pressure-depth.sh b/scripts/setup-pressure-depth.sh index d5fba10..eeacb8e 100644 --- a/scripts/setup-pressure-depth.sh +++ b/scripts/setup-pressure-depth.sh @@ -7,4 +7,5 @@ sudo raspi-config nonint do_i2c 0 # Install packages sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip -sudo pip3 install Adafruit-Blinka adafruit-circuitpython-ads1x15 + +sudo pip install -r /home/pi/hydrophonitor/depth-logger/requirements.txt