Skip to content

Instantly share code, notes, and snippets.

@supermamon
Last active May 3, 2023 22:52
Show Gist options
  • Save supermamon/846c1ab94e96434263459fbab0ac9a48 to your computer and use it in GitHub Desktop.
Save supermamon/846c1ab94e96434263459fbab0ac9a48 to your computer and use it in GitHub Desktop.
Mars Rover Camera for Homebridge

Mars Rover Camera for Homebridge

  1. Get an API key from from https://api.nasa.gov
  2. Download roverpics.sh, fill in the API key.
  3. Run the script once to download the latest pictures.
  4. Schedule the script to run via cron (or any utility that can run scripts on schedule).
  5. Install the Homebridge Camera FFmpeg plugin on Homebridge
  6. Add configuration to stream the latest photos (see config.json)
"platforms": [
{
"platform": "Camera-ffmpeg",
"name": "Camera FFmpeg",
"cameras": [
{
"name": "Curiosity NAVCAM",
"videoConfig": {
"source": "-f image2 -loop 1 -s 720x480 -pix_fmt yuvj422p -i /homebridge/cams/curiosity-NAVCAM-curr.jpg"
}
},
{
"name": "Curiosity FHAZ",
"videoConfig": {
"source": "-f image2 -loop 1 -s 720x480 -pix_fmt yuvj422p -i /homebridge/cams/curiosity-FHAZ-curr.jpg"
}
},
{
"name": "Curiosity RHAZ",
"videoConfig": {
"source": "-f image2 -loop 1 -s 720x480 -pix_fmt yuvj422p -i /homebridge/cams/curiosity-RHAZ-curr.jpg"
}
}
]
}
]
#!/bin/bash
# get your API key from https://api.nasa.gov
API_KEY=nasa-api-key
ROVER=curiosity
sol=$(curl -s "https://api.nasa.gov/mars-photos/api/v1/manifests/$ROVER?api_key=$API_KEY" | jq -r '.photo_manifest.max_sol')
function download_rover_pic() {
rover=$1
sol=$2
cam=$3
dir=$4
data=$(curl -s "https://api.nasa.gov/mars-photos/api/v1/rovers/$rover/photos?sol=$sol&api_key=$API_KEY&camera=$cam")
pic_curr=$(echo $data | jq -r '.photos[-1].img_src')
curl -s $pic_curr -o "$dir/$rover-$cam-curr.jpg"
}
download_rover_pic $ROVER $sol NAVCAM /homebridge/cams
download_rover_pic $ROVER $sol FHAZ /homebridge/cams
download_rover_pic $ROVER $sol RHAZ /homebridge/cams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment