# Help understanding push data versus polling

**URL:** <https://community.particle.io/t/help-understanding-push-data-versus-polling/6474>\
**Category:** Getting Started\
**Created:** [August 19, 2014, 4:07pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474 "2014-08-19T16:07:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![scsc\_tech](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@scsc\_tech](https://community.particle.io/u/scsc_tech)\
**Post date:** [August 19, 2014, 4:07pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/1 "2014-08-19T16:07:17Z")

</div>

I am writing a game based on @BDub's pinewood derby code

> **[Stopwatch for Pinewood Derby](https://community.particle.io/t/stopwatch-for-pinewood-derby/3486/17)**
>
> Ok! 1:41am… Pinewood Derby code keeping me up! These interrupts and timing really don’t work like they should. I had to get in there are TAKE OVER!!! When I get some sleep I’ll explain WHY I had to do what I did. EDIT: I updated the header...

What I am wanting to do is control it via a webpage. I easily figured out how to trigger the round by calling a cloud function via POST. I can also get the time variables at the end of the round by using GET.

I dont know when the round ends, it could end at any point. My question is, how can I get it to **push** the end of the round data to the webpage instead of having to constantly **poll** it with GET?

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [August 19, 2014, 4:10pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/2 "2014-08-19T16:10:41Z")

</div>

I think Spark.publish() would be ideal here. You don’t really even need the data to be published, just an event that says “I’m done and you can read my variables now!”.

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [August 19, 2014, 4:17pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/3 "2014-08-19T16:17:29Z")

</div>

Well @bko, you beat me to it. I was going to link to your tutorials anyhow, so I guess that doesn’t matter much 😉  
If you’re publishing anyhow, why wouldn’t you use that data directly. Seems to be an unnecessary step to me to say:“hey, I’ve got a live update containing data, let’s actively poll for that same data.” If you’re sending that stuff over the web, you might as well just use it. This however only hold true if the data is small enough to fit within a publish. If you’re polling a lot of variables, the “notify to poll” seems reasonable.

---

<div class="post-metadata">

**Author:** ![scsc\_tech](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@scsc\_tech](https://community.particle.io/u/scsc_tech)\
**Post date:** [August 19, 2014, 4:22pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/4 "2014-08-19T16:22:28Z")

</div>

ooh @bko has tutorials? I wanna see!

yes, publishing the results themselves makes sense versus as a trigger to poll

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [August 19, 2014, 4:28pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/5 "2014-08-19T16:28:29Z")

</div>

Hi @scsc_tech

There are a lot of tutorials here in the forum:

[https://community.spark.io/category/project-share/tutorials](https://community.spark.io/category/project-share/tutorials)

I wrote several on publishing and getting and setting variables.

I mentioned that you wouldn’t **have** to publish the actual data just to avoid more code changes since you are starting from code that uses variables. Publishing the data works great!

---

<div class="post-metadata">

**Author:** ![scsc\_tech](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@scsc\_tech](https://community.particle.io/u/scsc_tech)\
**Post date:** [August 19, 2014, 4:43pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/6 "2014-08-19T16:43:11Z")

</div>

Thanks! to publish the double I would have to use `sprintf` in some fashion to convert it to a string correct? Im new to it

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [August 19, 2014, 4:50pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/7 "2014-08-19T16:50:59Z")

</div>

Yes, that’s right, sprintf() or something similar would be required to convert the double value to a char array string.

---

<div class="post-metadata">

**Author:** ![scsc\_tech](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@scsc\_tech](https://community.particle.io/u/scsc_tech)\
**Post date:** [August 19, 2014, 5:12pm UTC](https://community.particle.io/t/help-understanding-push-data-versus-polling/6474/8 "2014-08-19T17:12:22Z")

</div>

Thanks! this was super easy to get working thanks to your tutorial

```
double tempTime1;
char target1Time[10];
sprintf(target1Time, "%f", tempTime1);
Spark.publish("round/target1",target1Time);

```

the call

```
curl -H "Authorization: Bearer [MYAPI]" \
    https://api.spark.io/v1/events/round
```
