# Using Particle App to pass variable values

**URL:** <https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297>\
**Category:** General\
**Created:** [March 13, 2018, 6:03pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297 "2018-03-13T18:03:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chazgolin](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@chazgolin](https://community.particle.io/u/chazgolin)\
**Post date:** [March 13, 2018, 6:03pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/1 "2018-03-13T18:03:53Z")

</div>

Hey all,

Myself and a team of other engineering students are trying to use Photon to collect temperature data from a sensor, and send push notifications when the temperature exceeds certain bounds. We have created successful code, now, we want to be able to set the temperature threshold values through the Particle App.

My initial idea was to create a particle.function that takes the threshold value as a string command, converts it to integer, and then uses it in an infinite while loop that contains our if statement to send push notifications if the value is exceeded. However, when I called the function through Particle, I received an error message, presumably because the function is an infinite loop.

Does anybody have any ideas on how we could send a value to a variable from the Particle App? We are trying not to involve other applications in order to keep our project as simple as possible, but if this isn’t possible, that would be good to know as well.

Thanks,  
Chaz

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 13, 2018, 6:44pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/2 "2018-03-13T18:44:09Z")

</div>

`Particle.function()` is the way to go, but why do you use an infinite `while()` and not just let `loop()` do the looping?  
If you trap the code flow in a prolonged loop you either need to regularly call `Particle.process()` or go with `SYSTEM_THREAD(ENABLED)`. But as already said, avoiding prolonged loops completely would be better practice.

Also the callback function for your `Particle.function()` should return as quickly as possible (and return a useful integer value) to let the cloud know execution was successful.  
So the intended way would be to parse the incoming string, store it in a global variable and then return control to `loop()` to act upon the updated value.

---

<div class="post-metadata">

**Author:** ![chazgolin](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@chazgolin](https://community.particle.io/u/chazgolin)\
**Post date:** [March 20, 2018, 5:56pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/3 "2018-03-20T17:56:52Z")

</div>

![50%20AM](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/5/3/53ddd619a03fc2f5b7e06297029d96f25cf513f1.png) ![10%20AM](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/9/69a18676c8ee4735ebe58dcb09d46e1ee9b9b979.png)  
 ![IMG_3286](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/9/3/931361fe56491f22169ede00ddef016456f49619.PNG)  
Hey ScruffR,

Thanks for your help. We are currently trying to implement the Particle.function, convert the incoming string to float, and assign it the global variable “upperbound”, and then use it within our if statement inside of our loop(). For some reason, the Particle function returns an error when we try to send it a value. Any ideas?

We know that the code for reading the sensor and sending push notifications works, as that was tested desperately. It’s only the Particle function that is giving us errors.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 20, 2018, 6:15pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/4 "2018-03-20T18:15:43Z")

</div>

Before I look at your code, reading screenshots isn’t my favorite task and if I had to actually try out your code, I’d have to type it off (which I won’t do in any case).  
So you could either post the code as text to copy/paste into a test project or you could even provide a shared link to a project snapshot as described here  
[https://docs.particle.io/guide/getting-started/build/photon/#sharing-your-app](https://docs.particle.io/guide/getting-started/build/photon/#sharing-your-app)

---

<div class="post-metadata">

**Author:** ![chazgolin](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@chazgolin](https://community.particle.io/u/chazgolin)\
**Post date:** [March 20, 2018, 6:18pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/5 "2018-03-20T18:18:36Z")

</div>

We actually just figured out that there was a space in the particle function name, and that was causing the error. Our code works! Thanks for your help.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 20, 2018, 6:22pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/6 "2018-03-20T18:22:25Z")

</div>

I’m quite puzzled about that now, since I actually do see some other issue in your code.  
The function signature of `upperBoundF()` is wrong. A `Particle.function()` callback _must_ return an `int` not a `float`.  
[https://docs.particle.io/reference/firmware/photon/#particle-function-](https://docs.particle.io/reference/firmware/photon/#particle-function-)

BTW, you are still using the deprecated syntax for `Particle.variable()`  
[https://docs.particle.io/reference/firmware/photon/#particle-variable-](https://docs.particle.io/reference/firmware/photon/#particle-variable-)

The current syntax does not use the address-of operator (`&`) and no type specifier.

---

<div class="post-metadata">

**Author:** ![chazgolin](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@chazgolin](https://community.particle.io/u/chazgolin)\
**Post date:** [March 20, 2018, 6:29pm UTC](https://community.particle.io/t/using-particle-app-to-pass-variable-values/40297/7 "2018-03-20T18:29:56Z")

</div>

Interesting. We updated our Particle.variable() syntax, thanks for pointing that out.
