Does choosing the different type of cloud functions affect battery life?

Hello everyone,

My name is Bryan, I not very good with firmware but I working on a simple spark core project. The project is to have a DHT22 sensor and I can get the result on my phone.

I looking at either one of the 2 cloud functions to achieve this.

  1. I set up a spark variable and have the function return the temperature reading when it is call upon (via GET)


  1. I have set up a Spark.publish function, when there is a reading, it publish the result and I get the result via Spark.subscribe()

My questions are

  1. which is more efficient?
  2. If I’m planning to run the core a battery, which will be more energy saving?

Thank you pple :smiley:

Hey Bryan,

don’t worry, you don’t have to be a firmware genius to get something nice up and running.
When you say you want to get the results on your phone, how do you plan on doing that? Are you going to build an app, or perhaps use a website? Depending on what you choose, there’ll be different options.

If you’re going to use Spark.variable(), then you have to make sure your Core is always online, or you won’t be able to poll it. This means it has to have WiFi and the controller activated non-stop, so there’s no energy savings there.

Spark.publish() on the other hand will require the exact opposite. You’ll need to have your receiver listening at all times. If that’s an app, the app will need to be on in order to receive the information. The same is true for a website.
With a website however, there is the option to integrate this into the server end, if you have (access to) one. I’m currently using a Node.js setup to capture SSE from my Core with a DHT22, and log that to a database. When I want to see the current values I try go get them straight from my Core, or when it’s asleep, use the latest value from the database.

What it comes down to is the following, either your Core, or your receiver will have to be enabled at all times. The Core if you want to poll data, or the receiver if you want to catch sent events. If you’re planning on running the Core on a battery, you’d be better of with the latter option, since that will allow you to let the Core sleep with intervals. If it publishes once per minute, you could let it sleep in the mean time, conserving energy. This means you’ll need to have a receiver listening continuously.

I’m not really sure what you mean by “which is more effiecient?”, but if that’s referring to possible battery life, then definitely SSEs, since those allow you to sleep.

I hope that was somewhat helpful, but feel free to ask if you’d like more information.


Hi @Moors7

Thank you so much for taking the time for the reply.
This helps me a lot!

For my use case, after reading your reply.
It seems that it would work better with Spark.publish()
because I can use the timer to put the core to sleep (I plan to run on battery :D)
Publishing temp info only at 5min interval.

Again thank you so much.

1 Like