The code was built for and tested with:
- Seeed Studio XIAO ESP32S3 Sense
- Adafruit CircuitPython 9.2.7. To install CircuitPython, follow the Installing CircuitPython on ESP32 instructions.
- mpy-cross-*-9.2.7-32*
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.
- Adafruit CircuitPython 9.2.7+ for XIAO ESPP32S3 Sense
- To install follow the Installing CircuitPython on ESP32
- For command line esptool, in boot mode (replace the port with yours):
esptool.py --chip esp32s3 --port /dev/tty.usbmodem14401 erase_flash esptool.py --port /dev/tty.usbmodem14401 write_flash -z 0x0 adafruit-circuitpython-seeed_xiao_esp32_s3_sense-en_GB-9.2.7.bin
- Official Adafruit libraries (in /lib):
There are a few test scripts included in the repo to test independent features:
- cam_test.py for camera configuration and image file saving to SD card
- dbx_test.py for Dropbox access
- wifitime_test.py for WiFi connectivity and Time Server access