2024-08-03 -
This commit is contained in:
parent
74a208a647
commit
11c0197601
@ -31,7 +31,7 @@ modbus_device = '/dev/modbus'
|
|||||||
|
|
||||||
mb_address = 1
|
mb_address = 1
|
||||||
sensy_boi = minimalmodbus.Instrument(modbus_device, mb_address)
|
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.bytesize = 8
|
||||||
sensy_boi.serial.parity = minimalmodbus.serial.PARITY_NONE
|
sensy_boi.serial.parity = minimalmodbus.serial.PARITY_NONE
|
||||||
sensy_boi.serial.stopbits = 1
|
sensy_boi.serial.stopbits = 1
|
||||||
@ -85,16 +85,16 @@ def parse_gps_data(gps_string):
|
|||||||
if len(parts) < 4:
|
if len(parts) < 4:
|
||||||
logging.warning(f"Incomplete GPS data: {gps_string}")
|
logging.warning(f"Incomplete GPS data: {gps_string}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lat = float(parts[0][:2]) + float(parts[0][2:]) / 60
|
lat = float(parts[0][:2]) + float(parts[0][2:]) / 60
|
||||||
if parts[1] == 'S':
|
if parts[1] == 'S':
|
||||||
lat = -lat
|
lat = -lat
|
||||||
|
|
||||||
lon = float(parts[2][:3]) + float(parts[2][3:]) / 60
|
lon = float(parts[2][:3]) + float(parts[2][3:]) / 60
|
||||||
if parts[3] == 'W':
|
if parts[3] == 'W':
|
||||||
lon = -lon
|
lon = -lon
|
||||||
|
|
||||||
return lat, lon
|
return lat, lon
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error parsing GPS data: {str(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):
|
def write_to_influxdb(lat, lon):
|
||||||
timestamp = int(time.time() * 1000000000) # nanosecond precision
|
timestamp = int(time.time() * 1000000000) # nanosecond precision
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gps_point = Point("gps_location") \
|
gps_point = Point("gps_location") \
|
||||||
.tag("host", myhost) \
|
.tag("host", myhost) \
|
||||||
@ -110,7 +110,7 @@ def write_to_influxdb(lat, lon):
|
|||||||
.field("longitude", lon) \
|
.field("longitude", lon) \
|
||||||
.field("geolocation", f"{lat},{lon}") \
|
.field("geolocation", f"{lat},{lon}") \
|
||||||
.time(timestamp)
|
.time(timestamp)
|
||||||
|
|
||||||
write_api.write(bucket=INFLUXDB_BUCKET, record=gps_point)
|
write_api.write(bucket=INFLUXDB_BUCKET, record=gps_point)
|
||||||
logging.info(f"GPS data written to InfluxDB: Lat: {lat}, Lon: {lon}")
|
logging.info(f"GPS data written to InfluxDB: Lat: {lat}, Lon: {lon}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -174,17 +174,17 @@ def reinitialize_devices():
|
|||||||
sensy_boi.mode = minimalmodbus.MODE_RTU
|
sensy_boi.mode = minimalmodbus.MODE_RTU
|
||||||
sensy_boi.clear_buffers_before_each_transaction = True
|
sensy_boi.clear_buffers_before_each_transaction = True
|
||||||
sensy_boi.close_port_after_each_call = 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()
|
gps_ser.reset_input_buffer()
|
||||||
initialize_gps(gps_ser)
|
initialize_gps(gps_ser)
|
||||||
|
|
||||||
logging.info("Devices reinitialized successfully")
|
logging.info("Devices reinitialized successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to reinitialize devices: {str(e)}")
|
logging.error(f"Failed to reinitialize devices: {str(e)}")
|
||||||
|
|
||||||
# Initialize GPS
|
# Initialize GPS
|
||||||
gps_ser = serial.Serial(gps_device, 115200)
|
gps_ser = serial.Serial(gps_device, 9600)
|
||||||
gps_ser.reset_input_buffer()
|
gps_ser.reset_input_buffer()
|
||||||
initialize_gps(gps_ser)
|
initialize_gps(gps_ser)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user