Skip to content

Commit

Permalink
Fixed basic remote telemetry system
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Jan 5, 2025
1 parent 714daea commit 20b7a73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dashcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ def dashcam_normal(device):
"spd": current_location[2],
"head": current_location[4]
}
send_telemetry(data)
utils.send_telemetry(telemetry_data)


# ===================
Expand Down
12 changes: 8 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def process_timing(action, identifier):
print(e)
print("cv2 is required because the `developer>frame_count_method` value is set to 'manual' or 'opencv'")

# TODO: Check if Base64 is needed (remote telemetry is enabled).
import base64



if (config["general"]["interface_directory"] != ""): # Check to see if the interface directory is enabled.
Expand Down Expand Up @@ -878,8 +881,9 @@ def count_frames(video):
return video_frame_count

# This function is called for every frame, and uploads dash-cam telemetry information at regular intervals.
last_telementry_sent = 0 # This holds the timestamp of the last time telemetry was sent.
last_telemetry_sent = 0 # This holds the timestamp of the last time telemetry was sent.
def send_telemetry(data):
global last_telemetry_sent
# data = {
# "image": {
# "main": [OpenCV image],
Expand All @@ -896,19 +900,19 @@ def send_telemetry(data):
# }
# }
if (time.time() - last_telemetry_sent >= 10): # Check to see if it has been at least 10 seconds since the last telemetry update.
for (device in data["image"]):
for device in data["image"]:
original_height, original_width = data["image"][device].shape[:2]
target_height = 720
scale_factor = target_height / original_height
new_width = int(original_width * scale_factor)

data["image"][device] = cv2.resize(data["image"][device], (new_width, target_height)) # Resize the frame to the target size.
retval, buffer = cv2.imencode('.jpg', data["image"][device])
data["image"][device] = base64.b64encode(buffer)
data["image"][device] = base64.b64encode(buffer).decode("utf-8")
last_telemetry_sent = time.time()

submission = json.dumps(data) # Convert the image information into a string.
request = requests.post("http://localhost/portal/ingest.php", data={"identifier": "ebdbaf0781f03d54422b1321", "data": submission}, timeout=8) # TODO: Add configuration options.
request = requests.post("http://192.168.0.137/portal/ingest.php", data={"identifier": "ebdbaf0781f03d54422b1321", "data": submission}, timeout=8) # TODO: Add configuration options.



Expand Down

0 comments on commit 20b7a73

Please sign in to comment.