Options for applications with long term, battery usage

I would like to integrate the P0 or P1 (still to decide on antenna options) into an add-on module for an existing product. Battery supply is 4x AA batteries so working on a worst case of 4x 1000mA supply. We have successfully integrated the Core into the product as a proof of concept but have struggled to get any acceptable power reduction results using the built-in sleep function as it sleeps for 30 seconds or so and then wakes back up again. Code below for info:

Spark.sleep(A1,FALLING);

The sleep is called at the end of the loop() so I would have expected the Core to sleep until A1 goes to 0v. It actually wakes up again around 30 seconds later.

I am guessing that this function needs the bootloader to be upgraded in order to work properly (at least that is what the documentation states) - are there any instructions on how to do this from a Windows PC?

My alternative approach was to simply turn off the Wi-Fi at the end of the loop and only turn it on if the analogRead of A1 was less than 10 (i.e. 0). This approach was thwarted by WiFi.ready() never seeming to return true despite the following code:

WiFi.on();
WiFi.connect();

What appeared to happen was that the loop just continued turning the WiFi immediately back off again, skipping over the Spark.publish that should have happened rather than Spark.publish blocking the code:

WiFi.on();
WiFi.connect();

if(WiFi.ready() == true)
{
   Spark.publish("post_webhook", "{\"value\":\"mydata\"");
   WiFi.off();
}
else
{
   // Do nothing
}

To be honest, even if that worked, the only sleep method that achieves the sleep level necessary is deep sleep but this is a timer based method so not very useful for my application.

It would be good at least to get the internal sleep methods working correctly, so if someone could advise, that would be appreciated!

This might be useful though not official numbers yet: https://github.com/spark/docs/issues/307

Two things.
For Spark.publish() to work you don’t (only) need WiFi.connect() but Spark.connect() (which does WiFi.on() and WiFi.connect() implicitly).
And when using 4AAs in series you don’t get four times the current but four times the voltage.

Thank-you for pointing out Spark.connect();

What I have noticed, is that calling the following code which SHOULD publish to the webhook, doesn’t call the webhook. I would imagine that publish is non-blocking so the code execution continues and the wifi gets disabled before the publish actually completes.

Spark.connect();
Spark.publish("post_webhook", "{\"value\":\"mydata\"");
WiFi.off();

I couldn’t see from the documentation whether Spark.publish returns anything that could be used as a success result that could be tested before WiFi.off() is called.

Is there any realistic risk of destroying the Core/P0/P1 by using an external circuit to power & de-power the Core/P0/P1 thus only utilising it when necessary? I would estimate that during a day, it would only be cycled up to 10 times.

Maybe this thread might help

Under what circumstances would the Core wake ten times a day?


BTW: This code does not wake unless the wake pin goes low on my Core

#define LED_pin D7 

void setup()
{
  pinMode(LED_pin, OUTPUT);

  digitalWrite(LED_pin, HIGH);
  delay(10000);                // give me chance to flash OTA
  digitalWrite(LED_pin, LOW);  // too late
}

void loop()
{
  Spark.sleep(A1,FALLING);
}

Thank-you for the link to the .publish() thread - I had ended up putting a delay in as well.

Under what circumstances would the Core wake ten times a day?

My scenario is that I need to know when a sensor has been triggered. When it is triggered, a message needs to be sent to "the system". That sensor is only likely to be triggered around 10 times a day. Could be more, could be less.

What I would like to know is that if frequent turning off/on of the core/P0/P1 could cause damage to the core/P0/P1.

I wouldn’t see a problem with power-cycling the Core just that rarely.

I’d still go for your first aproach, using sleep().

Although without knowing your setup it’s a bit difficult giving tailor made advice.
How much power would your power-cycle circuitry draw in comparison to any of the Core/P0/P1 sleep modes?
Does your sensor provide the wake-up signal or have you got additional components that would?
Does your sensor require initialisation to work?

Our existing product (the “sensor”) draws <10uA in standby as opposed to 30mA to 38mA for the Spark Core. Deep sleep for the Core is much better at 3.2uA but there is no interrupt for deep sleep. Utilising the wakeup for our existing product as the trigger for powering up the Core/P0/P1 would appear to be an obvious solution.

I'd guess the 30mA are for the mere "WiFiOff-sleep-mode" but the "WakeOnPin-sleep-mode" should do better.
Not as little as deep sleep, but as @kennethlimcp has pointed out it should be < 1mA.

And with the Photon/P1/P0 things will get even better - and maybe sometime the WakeOnPin feature will find its way into the Core too, since the hardware would support it - this could/should be a known issue already, at least there was a thread about it, some time ago.

1 Like