Compare commits
5 Commits
bcc3670aff
...
2c0776bdaa
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c0776bdaa | |||
| da93eaa604 | |||
| 608e07cb92 | |||
| 2ee70861cd | |||
| af556fde58 |
@@ -2,3 +2,5 @@
|
|||||||
`export PYTHONPATH=/home/pi/SmartWave`
|
`export PYTHONPATH=/home/pi/SmartWave`
|
||||||
|
|
||||||
`export PYTHONPATH=/home/ninluc/Documents/school/IoT/smartWave`
|
`export PYTHONPATH=/home/ninluc/Documents/school/IoT/smartWave`
|
||||||
|
|
||||||
|
https://red.smartwave.matthiasg.dev/dashboard
|
||||||
@@ -34,25 +34,22 @@ class GROVEGPS:
|
|||||||
self.longitude = -1.0
|
self.longitude = -1.0
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
"""Reads the latest GGA sentence from serial, thread-safely."""
|
"""Reads the freshest GGA sentence from serial, thread-safely."""
|
||||||
with serial_lock:
|
with serial_lock:
|
||||||
# 1. Flush accumulated stale data in the UART buffer
|
# 1. Flush accumulated stale buffer data
|
||||||
if self.ser.in_waiting > 0:
|
|
||||||
self.ser.reset_input_buffer()
|
self.ser.reset_input_buffer()
|
||||||
|
|
||||||
# 2. Try reading up to 15 lines to catch the freshest GGA sentence
|
# 2. Read through the fresh incoming stream to find a complete GGA line
|
||||||
for _ in range(5):
|
for _ in range(15):
|
||||||
raw_bytes = self.ser.readline()
|
raw_bytes = self.ser.readline()
|
||||||
try:
|
try:
|
||||||
line = raw_bytes.decode('utf-8', errors='ignore').strip()
|
line = raw_bytes.decode('utf-8', errors='ignore').strip()
|
||||||
# log(f"GPS: Read line: {line}")
|
log(f"GPS: Read line: {line}")
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Supports both $GPGGA and modern $GNGGA sentences
|
|
||||||
if (line.startswith('$GPGGA') or line.startswith('$GNGGA')) and calculate_nmea_checksum(line):
|
if (line.startswith('$GPGGA') or line.startswith('$GNGGA')) and calculate_nmea_checksum(line):
|
||||||
if self.parse_gga(line):
|
return self.parse_gga(line)
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def parse_gga(self, line):
|
def parse_gga(self, line):
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def get_temperature_and_humidity():
|
|||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def get_temperature_and_humidity_with_retry(max_retries=4, retry_delay=1.5):
|
def get_temperature_and_humidity_with_retry(max_retries=4, retry_delay=2.5):
|
||||||
"""
|
"""
|
||||||
Reads temperature and humidity with retries.
|
Reads temperature and humidity with retries.
|
||||||
Uses a 1.5s delay between attempts to respect DHT sampling limits.
|
Uses a 1.5s delay between attempts to respect DHT sampling limits.
|
||||||
|
|||||||
Reference in New Issue
Block a user