Skip to content

Image Rotation Not Working - Hash Returns Wrong Image #1

@dugdathug

Description

@dugdathug

Problem
When multiple images are placed in the images directory, the e-ink display does not rotate through them. The device skips downloads on every wake cycle after the first, showing only the first image indefinitely.

Root Cause
The /hash endpoint returned the hash of the previously served image instead of the next image to be served. This caused the ESP32's hash comparison to always match after the first download, preventing rotation.

/hash called get_current_image() which returned last_returned (the previous image)
/image_packed called get_next_image() which returned the image at current_index
After first wake: ESP32 stored hash of image #0, server prepared image #1
On second wake: /hash still returned hash of image #0 → match → no download
Solution
Added peek_next_image() method to look ahead at current_index without advancing rotation. Updated /hash endpoint to use this method, ensuring it returns the hash of the image that will be served next.

Changes:

Added ImageRotator.peek_next_image() method (line 240-259)
Updated /hash endpoint to call peek_next_image() instead of get_current_image() (line 456)
Testing
Verified with multiple images in rotation directory - display now cycles through all images on each wake interval.

Here's the new peek_next_image() method that I added to the ImageRotator class in my test:

def peek_next_image(self, device_id: str = DEFAULT_DEVICE_ID) -> str | None:
    """
    Peek at the next image that will be served without advancing rotation.

    Returns:
        str | None: Full path to the next image, or None if no images available
    """
    images = self._scan_directory(device_id)
    if not images:
        return None

    state = self._get_device_state(device_id)
    device_dir = self._get_device_dir(device_id)

    # Handle case where image list changed (files added/removed)
    if state['current_index'] >= len(images):
        state['current_index'] = 0

    image_name = images[state['current_index']]
    return os.path.join(device_dir, image_name)

Location: image_server.py:240-259

Key difference from get_next_image():

Returns the image at current_index but does not increment the index
Does not update last_returned
Does not call _save_state()
This allows the /hash endpoint to preview what the next download will be without affecting the rotation state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions