diff --git a/server/json_databases/DCUUIA.json b/server/json_databases/DCUUIA.json index eb973c9..1640f97 100644 --- a/server/json_databases/DCUUIA.json +++ b/server/json_databases/DCUUIA.json @@ -1 +1 @@ -{"timestamp": "2024-05-22T02:37:43.559983", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}} \ No newline at end of file +{"timestamp": "2024-05-22T02:59:43.095802", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}} \ No newline at end of file diff --git a/server/server.py b/server/server.py index 5564062..1364796 100644 --- a/server/server.py +++ b/server/server.py @@ -165,6 +165,7 @@ async def get_warnings(): def utm_to_latlon(easting, northing, zone_number=15, zone_letter='R'): return utm.to_latlon(easting, northing, zone_number, zone_letter) +@app.get('/update_positions') def fetch_and_update_positions(): try: # URLs for the rover and IMU data @@ -173,9 +174,11 @@ def fetch_and_update_positions(): # Fetching data rover_response = requests.get(rover_url) + rover_response.raise_for_status() # Ensure we raise an error for bad status codes rover_data = rover_response.json() imu_response = requests.get(imu_url) + imu_response.raise_for_status() # Ensure we raise an error for bad status codes imu_data = imu_response.json() # Getting positions for rover, eva1, and eva2 @@ -187,19 +190,13 @@ def fetch_and_update_positions(): features = [] - # Spoof and convert positions if they are zero for idx, (name, pos) in enumerate(positions.items()): posx, posy = pos["posx"], pos["posy"] - if posx == 0 and posy == 0: - latitude = 29.564802807347508 - longitude = -95.08160677610833 - utm_coords = utm.from_latlon(latitude, longitude) - # posx = utm_coords[0] + random.uniform(-30, 30) - # posy = utm_coords[1] + random.uniform(-30, 30) - # print(f"Spoofed position data for {name}") - - lat, lon = utm_to_latlon(posx, posy, utm_coords[2], utm_coords[3]) + # Assuming a default UTM zone for this example + zone_number = 15 + zone_letter = 'R' + lat, lon = utm_to_latlon(posx, posy, zone_number, zone_letter) feature = { "type": "Feature", @@ -219,11 +216,10 @@ def fetch_and_update_positions(): with open(CURRENT_LOCATIONS_FILE, "w") as f: dump(feature_collection, f) - print(f"Updated CURRENT_LOCATIONS.geojson with new positions for rover, eva1, and eva2") + return (f"Updated CURRENT_LOCATIONS.geojson with new positions for rover, eva1, and eva2") except Exception as e: - print(f"Error fetching or updating positions: {e}") - + return (f"Error fetching or updating positions: {e}") # Save new IP or Key @app.put("/update_config") diff --git a/src/components/Map.js b/src/components/Map.js index 97a0ea9..27c3928 100644 --- a/src/components/Map.js +++ b/src/components/Map.js @@ -100,8 +100,8 @@ const MapboxComponent = ({ zoom = 17 }) => { }; fetchGeoJSON(); - const intervalId = setInterval(fetchGeoJSON, 1000); - return () => clearInterval(intervalId); + const intervalIdGeoJSON = setInterval(fetchGeoJSON, 1000); + return () => clearInterval(intervalIdGeoJSON); }); newMap.on('click', (e) => { @@ -111,6 +111,22 @@ const MapboxComponent = ({ zoom = 17 }) => { } }, [mapBoxAPIKey, zoom]); + useEffect(() => { + const fetchUpdatePositions = async () => { + try { + const response = await fetch("http://localhost:8000/update_positions"); + const data = await response.json(); + console.log("Updated Positions:", data); + } catch (error) { + console.error("Error updating positions:", error); + } + }; + + fetchUpdatePositions(); + const intervalIdUpdatePositions = setInterval(fetchUpdatePositions, 3000); + return () => clearInterval(intervalIdUpdatePositions); + }, []); + const hideModal = () => setModalVisible(false); const handleAddPoint = async ({ name, id, coordinates }) => {