From ab1a615453de86c79d069e162fe6d09487aed316 Mon Sep 17 00:00:00 2001 From: Tony White Date: Tue, 2 Jan 2024 17:02:11 -1000 Subject: [PATCH] fix dockerfile entry point and remove try/except in logging to hunt why it can't create sensordata.csv --- Dockerfile | 2 +- app/.DS_Store | Bin 6148 -> 6148 bytes app/main.py | 84 +++++++++++++++++++++++++------------------------- 3 files changed, 43 insertions(+), 43 deletions(-) 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 ec0a2f892efa571ce9857860772c60312678a022..c8da6c3129139fca48d2939086530b7fc2348174 100644 GIT binary patch delta 48 zcmZoMXfc@JFUrioz`)4BAi%(o$&j2>UR;orlb^KtBlB`bM&`|Tn6z0ZHeA@u&heKY E04wMYTL1t6 delta 254 zcmZoMXfc@JFUrcmz`)4BAi%(o&rrmW!jQ;N!jQOGk$E{|JxGd=p_n0+ArD9*Ni*m% zBm+gt3QCfEN{dU1fa>%Zf*C4-VkJP;xeWRYVL8f7!M 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():