From 11c0197601790ae22ff27fdc79d9d0c221b1406d Mon Sep 17 00:00:00 2001 From: Adolfo Delorenzo Date: Sat, 3 Aug 2024 19:16:20 -0600 Subject: [PATCH] 2024-08-03 - --- modbus_gps_with_reset.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modbus_gps_with_reset.py b/modbus_gps_with_reset.py index b939662..68fa906 100644 --- a/modbus_gps_with_reset.py +++ b/modbus_gps_with_reset.py @@ -31,7 +31,7 @@ modbus_device = '/dev/modbus' mb_address = 1 sensy_boi = minimalmodbus.Instrument(modbus_device, mb_address) -sensy_boi.serial.baudrate = 115200 +sensy_boi.serial.baudrate = 9600 sensy_boi.serial.bytesize = 8 sensy_boi.serial.parity = minimalmodbus.serial.PARITY_NONE sensy_boi.serial.stopbits = 1 @@ -85,16 +85,16 @@ def parse_gps_data(gps_string): if len(parts) < 4: logging.warning(f"Incomplete GPS data: {gps_string}") return None - + try: lat = float(parts[0][:2]) + float(parts[0][2:]) / 60 if parts[1] == 'S': lat = -lat - + lon = float(parts[2][:3]) + float(parts[2][3:]) / 60 if parts[3] == 'W': lon = -lon - + return lat, lon except Exception as e: logging.error(f"Error parsing GPS data: {str(e)}") @@ -102,7 +102,7 @@ def parse_gps_data(gps_string): def write_to_influxdb(lat, lon): timestamp = int(time.time() * 1000000000) # nanosecond precision - + try: gps_point = Point("gps_location") \ .tag("host", myhost) \ @@ -110,7 +110,7 @@ def write_to_influxdb(lat, lon): .field("longitude", lon) \ .field("geolocation", f"{lat},{lon}") \ .time(timestamp) - + write_api.write(bucket=INFLUXDB_BUCKET, record=gps_point) logging.info(f"GPS data written to InfluxDB: Lat: {lat}, Lon: {lon}") except Exception as e: @@ -174,17 +174,17 @@ def reinitialize_devices(): sensy_boi.mode = minimalmodbus.MODE_RTU sensy_boi.clear_buffers_before_each_transaction = True sensy_boi.close_port_after_each_call = True - - gps_ser = serial.Serial(gps_device, 115200) + + gps_ser = serial.Serial(gps_device, 9600) gps_ser.reset_input_buffer() initialize_gps(gps_ser) - + logging.info("Devices reinitialized successfully") except Exception as e: logging.error(f"Failed to reinitialize devices: {str(e)}") # Initialize GPS -gps_ser = serial.Serial(gps_device, 115200) +gps_ser = serial.Serial(gps_device, 9600) gps_ser.reset_input_buffer() initialize_gps(gps_ser)