diff --git a/Dockerfile b/Dockerfile index c9e13a2..fc55430 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,4 +56,4 @@ LABEL links='{\ }' LABEL requirements="core >= 1.1" -ENTRYPOINT python /app/main.py +ENTRYPOINT ["python", "-u", "/app/main.py"] diff --git a/app/.DS_Store b/app/.DS_Store index ec0a2f8..c8da6c3 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/main.py b/app/main.py index 42c7a3f..0f17dd3 100644 --- a/app/main.py +++ b/app/main.py @@ -23,51 +23,51 @@ def main(): print("main started") while (logging_active == True): # Main loop for logging data print("in while") - try: # Send GET requests to the REST APIs - print("in try") - distance_response = requests.get(distance_url) - gps_response = requests.get(gps_url) - yaw_response = requests.get(yaw_url) - if distance_response.status_code == 200 and gps_response.status_code == 200 and yaw_response.status_code == 200: # Check if the requests were successful - print("data good") - distance_data = distance_response.json()['message'] # Extract the data from the responses - gps_data = gps_response.json()['message'] - yaw_data = yaw_response.json()['message'] - column_labels = ['Unix Timestamp', 'Date', 'Time','Distance (cm)', 'Confidence (%)', 'Yaw (deg)','Latitude', 'Longitude'] - timestamp = int(time.time() * 1000) # Convert current time to milliseconds - dt = datetime.fromtimestamp(timestamp / 1000) # Convert timestamp to datetime object - unix_timestamp = timestamp - timenow = dt.strftime('%H:%M:%S') - date = dt.strftime('%m/%d/%y') - distance = distance_data['current_distance'] - confidence = distance_data['signal_quality'] - yawRad = yaw_data['yaw'] - yawDeg = math.degrees(yawRad) - yaw = round(((yawDeg + 360) % 360),2) - latitude = gps_data['lat'] / 1e7 - longitude = gps_data['lon'] / 1e7 - data = [unix_timestamp, date, timenow, distance, confidence, yaw, latitude, longitude] - with open(log_file, 'a', newline='') as csvfile: # Create or append to the log file and write the data - writer = csv.writer(csvfile) - if csvfile.tell() == 0: # Write the column labels as the header row (only for the first write) - writer.writerow(column_labels) - writer.writerow(data) # Write the data as a new row - row_counter += 1 # Increment the row counter + #try: # Send GET requests to the REST APIs + print("in try") + distance_response = requests.get(distance_url) + gps_response = requests.get(gps_url) + yaw_response = requests.get(yaw_url) + if distance_response.status_code == 200 and gps_response.status_code == 200 and yaw_response.status_code == 200: # Check if the requests were successful + print("data good") + distance_data = distance_response.json()['message'] # Extract the data from the responses + gps_data = gps_response.json()['message'] + yaw_data = yaw_response.json()['message'] + column_labels = ['Unix Timestamp', 'Date', 'Time','Distance (cm)', 'Confidence (%)', 'Yaw (deg)','Latitude', 'Longitude'] + timestamp = int(time.time() * 1000) # Convert current time to milliseconds + dt = datetime.fromtimestamp(timestamp / 1000) # Convert timestamp to datetime object + unix_timestamp = timestamp + timenow = dt.strftime('%H:%M:%S') + date = dt.strftime('%m/%d/%y') + distance = distance_data['current_distance'] + confidence = distance_data['signal_quality'] + yawRad = yaw_data['yaw'] + yawDeg = math.degrees(yawRad) + yaw = round(((yawDeg + 360) % 360),2) + latitude = gps_data['lat'] / 1e7 + longitude = gps_data['lon'] / 1e7 + data = [unix_timestamp, date, timenow, distance, confidence, yaw, latitude, longitude] + with open(log_file, 'a', newline='') as csvfile: # Create or append to the log file and write the data + writer = csv.writer(csvfile) + if csvfile.tell() == 0: # Write the column labels as the header row (only for the first write) + writer.writerow(column_labels) + writer.writerow(data) # Write the data as a new row + row_counter += 1 # Increment the row counter - else: - # Print an error message if any of the requests were unsuccessful - print(f"Error: Ping2 Data - {distance_response.status_code} - {distance_response.reason}") - print(f"Error: GPS Data - {gps_response.status_code} - {gps_response.reason}") - print(f"Error: Attitude Data - {yaw_response.status_code} - {yaw_response.reason}") + else: + # Print an error message if any of the requests were unsuccessful + print(f"Error: Ping2 Data - {distance_response.status_code} - {distance_response.reason}") + print(f"Error: GPS Data - {gps_response.status_code} - {gps_response.reason}") + print(f"Error: Attitude Data - {yaw_response.status_code} - {yaw_response.reason}") - if row_counter % (log_rate * feedback_interval) == 0: - print(f"Rows added to CSV: {row_counter}") - - time.sleep(1 / log_rate) + if row_counter % (log_rate * feedback_interval) == 0: + print(f"Rows added to CSV: {row_counter}") + + time.sleep(1 / log_rate) - except Exception as e: - print(f"An error occurred: {e}") - break + #except Exception as e: + # print(f"An error occurred: {e}") + # break @app.route('/') def home():