From b740ba99912489bf9f4b900fbda984161afc9675 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 27 Jul 2025 15:10:11 -0700 Subject: [PATCH] back-end ustreamer, GPS, timelapse, and photo-refresh site working --- defaults/main.yaml | 12 ++++ .../Dockerfile | 0 .../package.json | 0 .../server.js | 0 files/image_refresh_php/getImage.php | 22 ++++++ files/image_refresh_php/index.php | 17 +++++ files/python_gps/app.py | 54 +++++++++++++++ tasks/gps_service.yaml | 65 +++++++++++++++++ tasks/kiosk.yaml | 10 --- tasks/main.yaml | 17 +++-- tasks/photo_refresh copy.yaml | 59 ++++++++++++++++ tasks/photo_refresh.yaml | 50 +++++++------- tasks/timelapse.yaml | 39 ++++++----- tasks/ustreamer.yaml | 8 +-- templates/create_timelapse.sh.j2 | 2 +- templates/docker-compose-php.yaml.j2 | 12 ++++ templates/gps_service.service-python.j2 | 16 +++++ templates/gps_service.service.j2 | 14 ++++ templates/gps_service.sh.j2 | 15 ++++ templates/record_snapshots.sh.j2 | 57 ++++++++------- templates/timelapse.service.j2 | 4 +- templates/timelapse_service.sh.j2 | 69 ++++++++++++++++--- 22 files changed, 443 insertions(+), 99 deletions(-) rename files/{image_refresh => image_refresh_node}/Dockerfile (100%) rename files/{image_refresh => image_refresh_node}/package.json (100%) rename files/{image_refresh => image_refresh_node}/server.js (100%) create mode 100644 files/image_refresh_php/getImage.php create mode 100644 files/image_refresh_php/index.php create mode 100644 files/python_gps/app.py create mode 100644 tasks/gps_service.yaml create mode 100644 tasks/photo_refresh copy.yaml create mode 100644 templates/docker-compose-php.yaml.j2 create mode 100644 templates/gps_service.service-python.j2 create mode 100644 templates/gps_service.service.j2 create mode 100644 templates/gps_service.sh.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml index beca6c9..271848b 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -17,6 +17,14 @@ packages: - wayland-utils - xscreensaver +# chrome kiosk variables +kiosk_service_templates: + - chrome_resolution: "720,405" + chrome_website: "http://127.0.0.1:7123/stream" + service_name: chrome_webcam + - chrome_resolution: "720,595" + chrome_website: "http://127.0.0.1:3000" + service_name: chrome_timelapse_control # this will be the parent folder where the photos will be stored @@ -27,6 +35,10 @@ packages: ## /dev/sda1 939G 28K 892G 1% /opt/carputer working_folder: "/opt/carputer/timelapse" +# other folder variables +gps_service_directory: "/opt/cosmos/gps_service" +photo_refresh_folder: "/opt/cosmos/photo_refresh" + # ustreamer variables video_device: "/dev/video0" resolution: "1920x1080" diff --git a/files/image_refresh/Dockerfile b/files/image_refresh_node/Dockerfile similarity index 100% rename from files/image_refresh/Dockerfile rename to files/image_refresh_node/Dockerfile diff --git a/files/image_refresh/package.json b/files/image_refresh_node/package.json similarity index 100% rename from files/image_refresh/package.json rename to files/image_refresh_node/package.json diff --git a/files/image_refresh/server.js b/files/image_refresh_node/server.js similarity index 100% rename from files/image_refresh/server.js rename to files/image_refresh_node/server.js diff --git a/files/image_refresh_php/getImage.php b/files/image_refresh_php/getImage.php new file mode 100644 index 0000000..7ad2677 --- /dev/null +++ b/files/image_refresh_php/getImage.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/files/image_refresh_php/index.php b/files/image_refresh_php/index.php new file mode 100644 index 0000000..dbbc749 --- /dev/null +++ b/files/image_refresh_php/index.php @@ -0,0 +1,17 @@ + + + + +Dynamic Image Update + + + + Refreshed Image + + + \ No newline at end of file diff --git a/files/python_gps/app.py b/files/python_gps/app.py new file mode 100644 index 0000000..ef7e09b --- /dev/null +++ b/files/python_gps/app.py @@ -0,0 +1,54 @@ +from flask import Flask, jsonify +import gps +import threading +import time + +app = Flask(__name__) + +# GPS data container +current_gps_data = { + "latitude": None, + "longitude": None, + "altitude": None, + "speed": None, + "timestamp": None +} + +# Global gps session object +session = gps.gps(mode=gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE) + +def gps_monitor(): + global current_gps_data + while True: + try: + # Wait for new data from the GPS device + report = session.next() + if report['class'] == 'TPV': + current_gps_data = { + "latitude": report.get('lat', None), + "longitude": report.get('lon', None), + "altitude": report.get('alt', None), + "speed": report.get('speed', None), + "timestamp": report.get('time', None) + } + except gps.GPSException as e: + print(f"GPS Error: {e}") + except KeyError as e: + print(f"Missing Key: {e}") + time.sleep(1) + +@app.route('/gps', methods=['GET']) +def get_gps_data(): + """API endpoint to fetch current GPS data""" + if None in current_gps_data.values(): + return jsonify({"error": "No GPS data available yet"}), 404 + return jsonify(current_gps_data) + +if __name__ == '__main__': + # Start GPS monitoring in a separate thread + gps_thread = threading.Thread(target=gps_monitor) + gps_thread.daemon = True # This makes the thread exit when the program does + gps_thread.start() + + # Run the Flask web service + app.run(host='0.0.0.0', port=5000) diff --git a/tasks/gps_service.yaml b/tasks/gps_service.yaml new file mode 100644 index 0000000..9f376d9 --- /dev/null +++ b/tasks/gps_service.yaml @@ -0,0 +1,65 @@ +--- + +# Create service Folder +- name: gps_service - create photo_refresh folder + file: + path: "{{ gps_service_directory }}" + state: directory + mode: '0755' + owner: root + group: root + +# install packages +- name: gps_service - Install Packages + apt: + name: + - gpsd + - gpsd-clients + state: present + register: apt_result + ignore_errors: true + +- name: gps_service - Enable and start gpsd system service + become: true + systemd: + daemon_reload: yes + state: started + enabled: yes + name: gpsd + +# this should never fail if things are plugged in correctly +- name: gps_service - check for GPS device + shell: ls /dev/ttyACM0 + register: check_gps_device + +- name: gps_service - show device + debug: + msg: "Device Found: {{ check_gps_device.stdout_lines[0] }}" + +- name: gps_service - copy service script + template: + src: gps_service.sh.j2 + dest: "{{ gps_service_directory }}/gps_service.sh" + mode: 0755 + +# Create gps_service python service +- name: gps_service - create service file + # vars: + template: + src: gps_service.service.j2 + dest: /etc/systemd/system/gps_service.service + mode: 0644 + +# daemon reload +- name: gps_service - daemon reload + systemd: + daemon_reload: yes + +# Enable and start +- name: gps_service - enable and start api + systemd: + name: gps_service.service + state: started + enabled: yes + +... \ No newline at end of file diff --git a/tasks/kiosk.yaml b/tasks/kiosk.yaml index ace19f1..07b8549 100644 --- a/tasks/kiosk.yaml +++ b/tasks/kiosk.yaml @@ -14,16 +14,6 @@ group: cosmos mode: '0700' -- name: set kiosk template vars - set_fact: - kiosk_service_templates: - - chrome_resolution: "720,405" - chrome_website: "http://127.0.0.1:7123/stream" - service_name: chrome_webcam - - chrome_resolution: "720,595" - chrome_website: "http://127.0.0.1:3000" - service_name: chrome_timelapse_control - - name: configure kiosks block: diff --git a/tasks/main.yaml b/tasks/main.yaml index e2eccde..b522d14 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -11,10 +11,17 @@ ### Top Cam Feed Kiosk ### Bottom Service Control Panel -- name: Carputer Early Tasks - include_tasks: - - ustreamer.yaml - - timelapse.yaml - - photo_refresh.yaml +#- name: Install ustreamer +# include_tasks: ustreamer.yaml +# +#- name: Install gps_service +# include_tasks: gps_service.yaml +# +#- name: install timelapse service +# include_tasks: timelapse.yaml +# +#- name: Install photo refresh site +# include_tasks: photo_refresh.yaml + ... \ No newline at end of file diff --git a/tasks/photo_refresh copy.yaml b/tasks/photo_refresh copy.yaml new file mode 100644 index 0000000..507004a --- /dev/null +++ b/tasks/photo_refresh copy.yaml @@ -0,0 +1,59 @@ +--- + + +- name: photo_refresh - set folder variable + set_fact: + docker_source: "/opt/cosmos/photo_refresh" + +# Create docker Folder +- name: photo_refresh - create photo_refresh folder + file: + path: "{{ docker_source }}" + state: directory + mode: '0755' + owner: timelapse + group: timelapse + + +- name: photo_refresh - copy files for docker container + copy: + src: "image_refresh_php/" + dest: "{{ docker_source }}/" + mode: 0755 + owner: root + group: root + +- name: photo_refresh - Build image + shell: "docker build -t photo_refresh {{ docker_source }}/." + +# docker_image: +# name: photo_refresh # Name of the Docker image +# source: build +# build: +# path: "{{ docker_source }}" # Path to the directory containing your Dockerfile +# state: present +# tag: latest + + +############################################### +# Start photo_refresh +############################################### + +- name: start photo_refresh + block: + + - name: photo_refresh - template config + template: + src: docker-compose-node.yaml.j2 + dest: "{{ docker_source }}/docker-compose.yaml" + mode: 0644 + + - name: photo_refresh - Start container at 0.0.0.0:3000 + shell: "docker-compose -f {{ docker_source }}/docker-compose.yaml up -d" + register: local_index_output + - debug: | + msg="{{ local_index_output.stdout_lines }}" + msg="{{ local_index_output.stderr_lines }}" + + +... \ No newline at end of file diff --git a/tasks/photo_refresh.yaml b/tasks/photo_refresh.yaml index b41b11c..5a793a7 100644 --- a/tasks/photo_refresh.yaml +++ b/tasks/photo_refresh.yaml @@ -1,31 +1,33 @@ --- -- name: photo_refresh - set folder variable - set_fact: - - docker_source: "/opt/cosmos/photo_refresh" - - # Create docker Folder -- name: lldp - python - create api folder +- name: photo_refresh - create photo_refresh folder file: - path: "{{ docker_source }}" + path: "{{ photo_refresh_folder }}" state: directory - mode: '0755' + mode: '0755' + owner: root + group: root + - name: photo_refresh - copy files for docker container copy: - src: "image_refresh" - dest: "{{ docker_source }}" - recursive: yes + src: "image_refresh_php/" + dest: "{{ photo_refresh_folder }}/html" + mode: 0755 + owner: root + group: root -- name: photo_refresh - Build image - docker_image: - name: photo_refresh # Name of the Docker image - source: build - build: - path: "{{ docker_source }}" # Path to the directory containing your Dockerfile - state: present - tag: latest +# - name: photo_refresh - Build image +# shell: "docker build -t photo_refresh {{ photo_refresh_folder }}/." + +# docker_image: +# name: photo_refresh # Name of the Docker image +# source: build +# build: +# path: "{{ photo_refresh_folder }}" # Path to the directory containing your Dockerfile +# state: present +# tag: latest ############################################### @@ -35,14 +37,14 @@ - name: start photo_refresh block: - - name: photo_refresh - Copy config + - name: photo_refresh - template config template: - source: docker-compose-node.yaml.j2 - dest: "{{ docker_source }}docker-compose.yaml" + src: docker-compose-php.yaml.j2 + dest: "{{ photo_refresh_folder }}/docker-compose.yaml" mode: 0644 - - name: photo_refresh - Start container at 0.0.0.0:3000 - shell: "docker-compose -f {{ docker_source }}/docker-compose.yaml up -d" + - name: photo_refresh - Start container at 0.0.0.0:8080 + shell: "docker-compose -f {{ photo_refresh_folder }}/docker-compose.yaml up -d" register: local_index_output - debug: | msg="{{ local_index_output.stdout_lines }}" diff --git a/tasks/timelapse.yaml b/tasks/timelapse.yaml index 0f7bd7f..ed91a8a 100644 --- a/tasks/timelapse.yaml +++ b/tasks/timelapse.yaml @@ -1,13 +1,24 @@ --- +# install packages +- name: photo_refresh - Install Packages + apt: + name: + - bc + - ffmpeg + - imagemagick + state: present + register: apt_result + ignore_errors: true + # Create working Folder -- name: lldp - python - create api folder +- name: timelapse - create working folder file: path: "{{ working_folder }}" state: directory mode: '0755' -- name: set template vars +- name: timelapse - set template vars set_fact: # timelapse related scripts timelapse_script_templates: @@ -18,23 +29,16 @@ - src: create_timelapse.sh.j2 dest: "{{ working_folder }}/create_timelapse.sh" -- name: Create user - user: - name: "timelapse" - state: present - shell: /bin/bash - groups: video - -- name: template scripts +- name: timelapse - template scripts template: src: "{{ item.src }}" dest: "{{ item.dest }}" - loop: "{{ timelapse_script_templates }}" - owner: timelapse - group: timelapse + owner: root + group: root mode: 0755 + loop: "{{ timelapse_script_templates }}" -- name: template service file +- name: timelapse - template service file template: src: timelapse.service.j2 dest: /etc/systemd/system/timelapse.service @@ -42,12 +46,11 @@ group: root mode: 0644 -- name: Enable and start service +- name: timelapse - daemon reload become: true systemd: daemon_reload: yes - state: started - enabled: yes - name: timelapse + state: stopped + name: timelapse.service ... \ No newline at end of file diff --git a/tasks/ustreamer.yaml b/tasks/ustreamer.yaml index a394c6b..3bfb93a 100644 --- a/tasks/ustreamer.yaml +++ b/tasks/ustreamer.yaml @@ -1,6 +1,6 @@ --- -- name: Install Packages +- name: ustreamer - Install Packages apt: name: - ustreamer @@ -8,14 +8,14 @@ register: apt_result ignore_errors: true -- name: Create user +- name: ustreamer - Create user user: name: "ustreamer" state: present shell: /bin/bash groups: video -- name: create service file +- name: ustreamer - create service file template: src: ustreamer.service.j2 dest: /etc/systemd/system/ustreamer.service @@ -23,7 +23,7 @@ group: root mode: 0644 -- name: Enable and start service +- name: ustreamer - Enable and start service become: true systemd: daemon_reload: yes diff --git a/templates/create_timelapse.sh.j2 b/templates/create_timelapse.sh.j2 index 2f7400c..3b6e665 100644 --- a/templates/create_timelapse.sh.j2 +++ b/templates/create_timelapse.sh.j2 @@ -5,6 +5,6 @@ rm $WORKING_DIR/run sleep 5 # create timelapse -ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \ +/bin/ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \ -vf "scale=1920x1080" -vcodec libx264 /$WORKING_DIR/00-timelapse.mp4 diff --git a/templates/docker-compose-php.yaml.j2 b/templates/docker-compose-php.yaml.j2 new file mode 100644 index 0000000..4bcf205 --- /dev/null +++ b/templates/docker-compose-php.yaml.j2 @@ -0,0 +1,12 @@ +services: + + photo_refresh: + container_name: photo_refresh + image: php:8.0-apache + ports: + - 8080:80 + volumes: + - ./html:/var/www/html/ + - {{ working_folder }}/small_thumbs:/var/www/html/capture + network_mode: bridge + restart: always diff --git a/templates/gps_service.service-python.j2 b/templates/gps_service.service-python.j2 new file mode 100644 index 0000000..a3d6d1d --- /dev/null +++ b/templates/gps_service.service-python.j2 @@ -0,0 +1,16 @@ +[Unit] +Description=GPS Monitoring Service +After=network.target + +[Service] +Type=simple +WorkingDirectory={{ gps_service_directory }} +ExecStart={{ gps_service_directory }}/venv/bin/python3 {{ gps_service_directory }}/app.py +Restart=always +User=root +Group=root +Environment="PATH={{ gps_service_directory }}/venv/bin" +Environment="VIRTUAL_ENV={{ gps_service_directory }}/venv" + +[Install] +WantedBy=multi-user.target diff --git a/templates/gps_service.service.j2 b/templates/gps_service.service.j2 new file mode 100644 index 0000000..8ce841d --- /dev/null +++ b/templates/gps_service.service.j2 @@ -0,0 +1,14 @@ +[Unit] +Description=GPS Monitoring Service +After=network.target + +[Service] +Type=simple +WorkingDirectory={{ gps_service_directory }} +ExecStart={{ gps_service_directory }}/gps_service.sh +Restart=always +User=root +Group=root + +[Install] +WantedBy=multi-user.target diff --git a/templates/gps_service.sh.j2 b/templates/gps_service.sh.j2 new file mode 100644 index 0000000..c5d49bf --- /dev/null +++ b/templates/gps_service.sh.j2 @@ -0,0 +1,15 @@ +#!/bin/bash +i=1 +while [ $i ] +do + GPS_DATA=$(gpspipe -w -n 5) + LON=$(echo $GPS_DATA | jq .lon | grep -v null | tail -n 1) + LAT=$(echo $GPS_DATA | jq .lat | grep -v null | tail -n 1) + SPEED=$(echo $GPS_DATA | jq .speed | grep -v null | tail -n 1) + echo lat:$LAT > {{ gps_service_directory }}/gps_data + echo lon:$LON >> {{ gps_service_directory }}/gps_data + echo speed:$SPEED >> {{ gps_service_directory }}/gps_data + chmod 755 {{ gps_service_directory }}/gps_data + sleep 1 +done + diff --git a/templates/record_snapshots.sh.j2 b/templates/record_snapshots.sh.j2 index 9415cde..4bd1b9f 100644 --- a/templates/record_snapshots.sh.j2 +++ b/templates/record_snapshots.sh.j2 @@ -1,12 +1,4 @@ #!/bin/bash -# no need to do this math forever -input_width=1920 -input_height=1080 -output_width=1340 -output_height=580 -# Calculate the ratio for trimming the top part -trim_ratio=$(echo "scale=4; $output_height / $output_width * $input_width" | bc) - # this saves a snapshot of the camera every second or so depending on how long all the other crap takes # let's hope the vars make it otherwise imma need to parse a bollocksing file @@ -23,10 +15,37 @@ do # This variable is for the timestamp TIME=$(date +%c) + # Save the initial image in a temp file + convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \ + -fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-temp1.jpg + + # Add the second annotation to the temp file + convert $WORKING_DIR/$FILENAME-temp1.jpg -gravity SouthEast -pointsize 44 \ + -fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-temp2.jpg + + # Append the two images and save the final result + convert $WORKING_DIR/$FILENAME-temp2.jpg -append $WORKING_DIR/$FILENAME.jpg + + # Optionally, remove intermediate files if you don't need them + rm $WORKING_DIR/$FILENAME-temp1.jpg $WORKING_DIR/$FILENAME-temp2.jpg + + # this big boi should add both the timestamp and the coordinates - convert $WORKING_DIR/$FILENAME.jpg \( +clone -gravity NorthWest -pointsize 22 -fill yellow -annotate +30+30 "$TIME" \) \ - \( +clone -gravity NorthEast -pointsize 22 -fill yellow -annotate +30+30 "$COORDINATES" \) \ - -append $WORKING_DIR/$FILENAME.jpg + #convert $WORKING_DIR/$FILENAME.jpg \( +clone -gravity NorthWest -pointsize 44 -fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-time.jpg\) \ + #\( +clone -gravity NorthEast -pointsize 44 -fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-final.jpg\) + #-append $WORKING_DIR/$FILENAME.jpg + + # This should add the current time to the image and save it + #convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \ + #-fill yellow -annotate +30+30 $TIME $WORKING_DIR/$FILENAME-temp.jpg + # Delete original + #rm $WORKING_DIR/$FILENAME.jpg + + # This should add the current latlon to the image and save it + #convert $WORKING_DIR/$FILENAME-temp.jpg -gravity SouthEast -pointsize 44 \ + #-fill yellow -annotate +30+30 $COORDINATES $WORKING_DIR/$FILENAME-final.jpg + # Delete temp + #rm $WORKING_DIR/$FILENAME-temp.jpg # This is for the tiny pic # I'll make one every 5 seconds @@ -34,7 +53,7 @@ do # Calculate the height to trim based on the aspect ratios of the input and output images if (( $i % 5 == 0 )); then NOW=$(date +%Y%m%d%H%M%S) - convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop x$trim_ratio +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg + convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop 1920x830+0+260 +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg fi sleep 1 @@ -42,17 +61,3 @@ do ((i++)) done - - -# old one-at-a-time rubbish -# # This should add the current time to the image and save it -# convert $WORKING_DIR/$FILENAME.jpg -gravity NorthWest -pointsize 22 \ -# -fill yellow -annotate +30+30 $TIME $WORKING_DIR/$FILENAME-temp.jpg -# # Delete original -# rm $WORKING_DIR/$FILENAME.jpg -# -# # This should add the current latlon to the image and save it -# convert $WORKING_DIR/$FILENAME-temp.jpg -gravity NorthEast -pointsize 22 \ -# -fill yellow -annotate +30+30 $COORDINATES $WORKING_DIR/$FILENAME.jpg -# # Delete temp -# rm $WORKING_DIR/$FILENAME-temp.jpg \ No newline at end of file diff --git a/templates/timelapse.service.j2 b/templates/timelapse.service.j2 index 7f98f37..5d9ceb6 100644 --- a/templates/timelapse.service.j2 +++ b/templates/timelapse.service.j2 @@ -5,8 +5,8 @@ After=network.target [Service] ExecStart=/opt/carputer/timelapse/timelapse_service.sh Restart=always -User=timelapse -Group=timelapse +User=root +Group=root [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/templates/timelapse_service.sh.j2 b/templates/timelapse_service.sh.j2 index cd802c5..c2cdc01 100644 --- a/templates/timelapse_service.sh.j2 +++ b/templates/timelapse_service.sh.j2 @@ -1,4 +1,5 @@ #!/bin/bash +trap "source {{ working_folder }}/create_timelapse.sh &" SIGINT SIGTERM # initialize all the variables # basic things @@ -18,13 +19,63 @@ echo Timelapse Initiated at $BEGIN >> $WORKING_DIR/info.txt echo Shuttlecraft Galileo located at $CITY, $STATE $ZIPCODE >> $WORKING_DIR/info.txt echo $DISPLAY_NAME >> $WORKING_DIR/info.txt -# Set the run file and fork the loop -touch $WORKING_DIR/run -source {{ working_folder }}/record_snapshots.sh & +# timelapse creation helpers +echo "To create timelapse, here's the ffpmeg script" >> $WORKING_DIR/info.txt +echo "/bin/ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \\" >> $WORKING_DIR/info.txt +echo "-vf "scale=1920x1080" -vcodec libx264 /$WORKING_DIR/00-timelapse.mp4" >> $WORKING_DIR/info.txt +# there should be a script that can do them all +echo "/bin/ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \\" >> {{ working_folder }}/generate_timelapses.sh +echo "-vf "scale=1920x1080" -vcodec libx264 /$WORKING_DIR/00-timelapse.mp4" >> {{ working_folder }}/generate_timelapses.sh + +# capture time +i=1 +while [ $i ] +do + FILENAME=$(printf "img-%05d" "$i") + # old API based latlon + #LATLON=$(curl -s http://10.18.1.1:8184/where_is?api_key={{ tesla_api_key }} ) + #LON=$(echo $LATLON | jq .lon) + #LAT=$(echo $LATLON | jq .lat) + LAT=$(cat {{ gps_service_directory }}/gps_data | grep lat | cut -d ":" -f 2 | awk '{printf("%.5f\n", $1)}') + LON=$(cat {{ gps_service_directory }}/gps_data | grep lon | cut -d ":" -f 2 | awk '{printf("%.5f\n", $1)}') + SPEED_KPH=$(cat {{ gps_service_directory }}/gps_data | grep speed | cut -d ":" -f 2) + if [ $SPEED_KPH -lt 1 ]; then + SPEED_MPH=$(echo "scale=3; $SPEEK_KPH * 0.62" | bc) + else + SPEED_MPH=0 + fi + COORDINATES="$LAT, $LON, $SPEED_MPH mph" + curl http://127.0.0.1:7123/snapshot --output $WORKING_DIR/$FILENAME.jpg + + # This variable is for the timestamp + TIME=$(date +%c) + + # Save the initial image in a temp file + convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \ + -fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-temp1.jpg + + # Add the second annotation to the temp file + convert $WORKING_DIR/$FILENAME-temp1.jpg -gravity SouthEast -pointsize 44 \ + -fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-temp2.jpg + + # Append the two images and save the final result + convert $WORKING_DIR/$FILENAME-temp2.jpg -append $WORKING_DIR/$FILENAME.jpg + + # Optionally, remove intermediate files if you don't need them + rm $WORKING_DIR/$FILENAME-temp1.jpg $WORKING_DIR/$FILENAME-temp2.jpg + + # This is for the tiny pic + # I'll make one every 5 seconds + # I have 1340x580. i think i will truncate the top + # Calculate the height to trim based on the aspect ratios of the input and output images + if (( $i % 5 == 0 )); then + NOW=$(date +%Y%m%d%H%M%S) + convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop 1920x830+0+260 +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg + fi + + sleep 1 + + ((i++)) + +done -# set the trap and wait -trap "source {{ working_folder }}/create_timelapse.sh &" SIGINT SIGTERM -while true; do - echo "Running..." - sleep 1 -done \ No newline at end of file