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
|
#bar = psi * 14.503773800722
|
||||||
|
|
||||||
with open(filename, "w", 1) as f:
|
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")
|
f.write("time and date, Voltage of depth sensor (V), Depth (m)\n")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -57,7 +57,7 @@ with open(filename, "w", 1) as f:
|
|||||||
roundvolts = round(voltage, 3)
|
roundvolts = round(voltage, 3)
|
||||||
# roundtemp = round(temperatureC, 2)
|
# 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:
|
# if lcd:
|
||||||
# lcd.clear()
|
# lcd.clear()
|
||||||
@ -68,4 +68,4 @@ with open(filename, "w", 1) as f:
|
|||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
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
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from gps import *
|
import gpsd
|
||||||
import time
|
import time
|
||||||
import argparse
|
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
|
interval = int(args.interval) if args.interval else 5
|
||||||
|
|
||||||
with open(filename, "w", 1) as f:
|
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")
|
print(f"Writing GPS output to {filename}, interval {interval} seconds", flush=True)
|
||||||
f.write("GPStime utc,latitude,longitude,speed,sats in view\n")
|
f.write("system_time,gps_time_utc,latitude,longitude,speed,sats_in_view\n")
|
||||||
|
|
||||||
try:
|
while True:
|
||||||
while True:
|
try:
|
||||||
report = gpsd.next()
|
packet = gpsd.get_current()
|
||||||
if report["class"] == "TPV":
|
gps_time_utc = str(packet.time) if packet.mode >= 2 else "-"
|
||||||
GPStime = str(getattr(report,"time",""))
|
lat = str(packet.lat) if packet.mode >= 2 else "0.0"
|
||||||
lat = str(getattr(report,"lat",0.0))
|
lon = str(packet.lon) if packet.mode >= 2 else "0.0"
|
||||||
lon = str(getattr(report,"lon",0.0))
|
speed = str(packet.hspeed) if packet.mode >= 2 else "0.0"
|
||||||
speed = str(getattr(report,"speed","nan"))
|
sats = str(packet.sats)
|
||||||
sats = str(len(gpsd.satellites))
|
system_time = time.strftime("%Y-%m-%dT%H-%M-%S")
|
||||||
|
f.write(f"{system_time},{gps_time_utc},{lat},{lon},{speed},{sats}\n")
|
||||||
f.write(GPStime + "," + lat +"," + lon + "," + speed + "," + sats + "\n")
|
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
||||||
|
print("Exiting GPS recording.", flush=True)
|
||||||
time.sleep(interval)
|
break
|
||||||
|
except Exception as e:
|
||||||
except (KeyboardInterrupt, SystemExit): # when you press ctrl+c
|
print(f"GPS error: {e}", flush=True)
|
||||||
print("Exiting GPS recording.")
|
|
||||||
|
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 \
|
sudo apt-get update && sudo apt-get install -y \
|
||||||
gpsd gpsd-clients
|
gpsd gpsd-clients
|
||||||
|
|
||||||
|
sudo pip install -r /home/pi/hydrophonitor/gps-logger/requirements.txt
|
||||||
|
|
||||||
sudo systemctl stop gpsd.socket
|
sudo systemctl stop gpsd.socket
|
||||||
sudo systemctl disable gpsd.socket
|
sudo systemctl disable gpsd.socket
|
||||||
|
|
||||||
|
@ -7,4 +7,5 @@ sudo raspi-config nonint do_i2c 0
|
|||||||
|
|
||||||
# Install packages
|
# Install packages
|
||||||
sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip
|
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