'Canon ccapi contents` returns 100 images only

I am using Canon ccapi to download the last image taken. I am trying to find it by getting the list of all the photos from contents request and then download the last one

http://<camera-ip>:8080/ccapi/ver100/contents/sd/100CANON

but actually it returns the first 100 cameras only, although there are 100 cameras inside 100CANON folder. Is there any parameter to pass to contents request? Is there any normal documentation that describes behavior of each request avaliable?



Solution 1:[1]

In summary, what you want is /ccapi/ver100/event/polling?continue=off, and poll that to find the latest file added under addedcontents. Python info below, but if you're working with a more basic URL setup, just refresh your query shortly after hitting the shutter.

Canon CCAPI documentation is for some reason nonexistent. I found a helpful open source library to scour the endpoints here: Canomate.

The repo has this python file with a function called pollForNewFilesOnCamera. Here's a dumbed down version of that function for a python script.

# returns the number of seconds that have elapsed since
# the specified anchor time. if the anchor time is None
# then this routine returns the current time, which
# the caller can use for a subsequent call to get elapsed
# time. time values are floats
#
def secondsElapsed(timeAnchor):
    timeCurrent = time.time()
    if timeAnchor == None:
        return timeCurrent
    return timeCurrent - timeAnchor

#
# Waits for camera to indicate new file(s) are available on the camera (ie, a photo or video has
# been taken since the last time the camera was polled).
# @param maxWaitTimeSecs - Maximum time to wait for new file(s) before giving up. If this value is
# zero then the camera will only be polled once
# @return  An array of CCAPI URLs to the new file(s) or None if no new files were indicated
#
def pollForNewFilesOnCamera(maxWaitTimeSecs=10, pollIntervalSecs=0.5):
    timeStart = secondsElapsed(None)
    while True:
        updates = requests.get(config.BASE_URL+endpoint_new_files)
        data = updates.json()
        if 'addedcontents' in data:
            print(data['addedcontents'])  # sample return value: 'http://192.168.1.142:8080/ccapi/ver100/contents/sd/100CANON/IMG_0327.JPG'
        if maxWaitTimeSecs == 0 or secondsElapsed(timeStart) >= maxWaitTimeSecs:
            return None
        print("Delaying {:.2f} on poll for new files".format(pollIntervalSecs))
        time.sleep(pollIntervalSecs)

pollForNewFilesOnCamera()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ekatz