Skip to content

istvanzk/xiaocam_cpy

Repository files navigation

CircuitPython code for time-lapse with XIAO ESP32S3 Sense camera

Exp Lic CircuitPy Ver

Implementation

The code was built for and tested with:

The main implementation to handle WiFi setup, SD card, camera configuration, saving images locally and uploading images to Dropbox. This file needs to be copied to the CIRCUITPY drive as main.py or code.py and will (re)run automatically.

The main configuration file with all the environment variables used. Must include the following environment variables:

# WiFi
CIRCUITPY_WIFI_SSID = "<WiFi SSID>"
CIRCUITPY_WIFI_PASSWORD = "<WiFi password>"

# Time server
ADAFRUIT_AIO_USERNAME = "<Adafruit IO user name>"
ADAFRUIT_AIO_KEY = "<Adafruit IO key/token>"
TIMEZONE = "<Time zone>" # Timezone names from http://worldtimeapi.org/timezones, e.g. Europe/Amsterdam

# Dropbox
DBX_APP_KEY = "<App key>"
DBX_APP_SECRET = "<App secret>"
DBX_REFRESH_TOKEN = "<tokens["oauth_result"].refresh_token>"
DBX_ACCESS_TOKEN = "<tokens["oauth_result"].access_token>"
DBX_EXPIRES_AT = <tokens["oauth_result"].expires_at>

A simple configuration file with camera and time-lapse parameters.

# Camera configuration
camConfig = {...}

# Camera timer configuration
camTimerConfig = {...}

# Local storage configuration (SD card)
camDirConfig = {...}

# Remote storage configuration (Dropbox)
camDbxConfig = {...}
Other implementation details

A set of logging handlers used in the cam_main.

This is a simple API implemenation to get the local time from an internet time server and set the RTC time of the board.

The primary time server used is the Adafruit IO time server. The simplest are the /time requests, which can be used without authenticating. To use the /integration requests you need an Adafruit IO account and IO key. The Adafruit IO username and key need to be inserted in the settings.toml file, as the values for ADAFRUIT_AIO_USERNAME and ADAFRUIT_AIO_KEY variables, respectively, see below.

Another time server which ca be used is the TimeAPI, which does not require authentication either.

A simple RTC shim, which allows running some parts of the code in a CPython environment (development machine).

This is a minimal CircuiPython implementation of the wire protocol for making requests to the Dropbox API V2 server. It is based on the official Dropbox API V2 SDK for Python, Release 95, v12.0.2, June 2024. Several of the original parameters and functionalities have been removed. Error handling is simplified and only the most common errors are handled. The code is not intended to be a full implementation of the Dropbox API.

In order to use the Dropbox API implemented here, you need to have a Dropbox account and set up an App in your Dropbox App Console. Then follow the OAuth flow, which can be run on a development machine (not the XIAO board), to obtain the access_token and refresh_token tokens and the expires_at value. These need to be inserted in the settings.toml file, as the values for the corresponding DBX_* variables. Don't forget to set also all the other DBX_* variables, see below.

The dropbox_cpy.py can be compiled to mpy format to save space.

Dependencies

Testing

There are a few test scripts included in the repo to test independent features:

About

CircuitPython code for time-lapse with XIAO ESP32S3 Sense camera

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages