Low-power "mode":"minimum" example?

Hi All,

Blues newbie here.

I’ve got my cellular notecard working nicely sending environmental data to ubidots while reading the sensors with an esp32 feather.

Now I want to make it very low power for battery operation for sending soil moisture data every 1 hour, otherwise sleep or idle to keep power use low on my lipo.

Can someone direct me to a good example that shows how to use {“req”:“hub.set”,“mode”:“minimum”}
to put the notecard in a very low power state but then force a sync every 1 hour.

I saw the sleepysensor example, which was informative, but I really want control actions with my esp32 and not rely on the enable pin maneuver used in the sleepysensor example.
I also read this helpful article,
but would love to see the firmware that shows how someone puts this all together for low power monitoring.

Sorry for the noob question, I have perused the forum but could not find a good example for a beginner like me. I likely just didn’t search for the right key words.

Thanks,

Jay

2 Likes

Jay,

Did try other ESP32 code to make the ESP32 in deep sleep mode and use only limited power?

Regards
Rob Oudendijk

BTW… Like the work you do and share with Measurement Lab.

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

2 Likes

Thanks Karl, this is super helpful and just what I needed. Much appreciated! I will duplicate this strategy and report back if I have any issues.

I use another aproach because I don’t want to wake up the notecard at every measurement. So I wake up my ESP32 with an external RTC (DS3231) every x minutes and I send my data every y measurments. So I can for exemple take readings every 10 minutes but send data every day or 12 hours. When switched on, the notecard is by far the most power consuming part. My data are stored on a micro Sd card. So when I want to send the data I read and send only the data written from the last switch on of the notecard. With this technique I can last about 6 month with a 6000 mh battery and a very very long time with a small 1.2W ETFE solar pannel .

3 Likes

If you’re using I2C: I’m using the Adafruit ESP32 Feather V2 for a low power solution. With the V2, you can turn off the I2C power via code using the power control pin setting; then go into deep sleep as mentioned above.

2 Likes