Jay,
Here are some snippets of code we use with an ESP32-S3 in Arduino that demon start how we a) have the device sleep in lower power mode, b) wake up every hour, take readings and transmit data. We also support DFU to update device firmware.
In the setup function, we call this code to configure the Notecard in minimum mode:
bool enableSync() {
J * req = notecard.newRequest("hub.set");
JAddStringToObject(req, "product", productUID);
JAddStringToObject(req, "mode", "minimum");
J * resp = notecard.requestAndResponse(req);
bool success = !notecard.responseError(resp);
JDelete(resp);
// Disable Notecard Flashing MCU, but allow DFU
// preparatory downloading from Notehub to Notecard DFU
if (J *req = notecard.newRequest("card.dfu")) { //DFU
JAddStringToObject(req, "name", "esp32"); //DFU
JAddBoolToObject(req, "off", true); //DFU
notecard.sendRequest(req); //DFU
}
return success; //DFU
}
In the loop function, we take our readings and then start Notecard sync with this code:
void startSync() {
J * req = notecard.newRequest("hub.sync");
JAddBoolToObject(req, "allow", true);
notecard.sendRequest(req);
}
We then monitor the syncing process until complete, though the ESP32 is sometimes put in low power state and the Notecard finishes the sync.
We then query DFU status, if we detect that firmware has completely downloaded into Notecard, we call our performDFU routine, which switches the Notecard mode to continuous, installs the firmware and reboots the system.
dfu_status_t dfu_ready = queryDFUStatus(); //DFU
if ((dfu_ready == dfu_status_t:: DFUdownloading) || (dfu_ready == dfu_status_t:: DFUready)) {
performDFU();
}
goToSleep();
The gotoSleep function, calculates the remaining time to the top of the hour, then calls:
void deepSleep(int seconds) {
J * req = NoteNewRequest("card.attn");
JAddStringToObject(req, "mode", "arm,sleep,auxgpio");
JAddNumberToObject(req, "seconds", seconds);
notecard.sendRequest(req);
}
This puts Notecard to sleep for the specificied number of seconds. (Though if Notecard is still syncing, it will finish syncing).
Then we turn off on power in on our ESP32, and put ESP32 in deep sleep mode with:
esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
esp_deep_sleep_start();
At the top of the hour, the Notecard wakes up the ESP32 and the cycle repeats.
I hope this helps.
Karl