Switch python to use gpsd-pip3 module, flush print outputs immediately, add requirements.txt
This commit is contained in:
parent
89701ca893
commit
1a7bd8c21b
@ -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)
|
||||
|
2
depth-logger/requirements.txt
Normal file
2
depth-logger/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Adafruit-Blinka==8.5.0
|
||||
adafruit-circuitpython-ads1x15==2.2.21
|
@ -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)
|
||||
|
1
gps-logger/requirements.txt
Normal file
1
gps-logger/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
gpsd-py3==0.3.0
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user