Max # of Particle.variable()'s

From the online reference:
Up to 20 cloud variables may be registered and each variable name is limited to a maximum of 12 characters.

I have 29 variable instances for a single Photon device (not that I’m complaining).
Are there really limits, and if so, what are they?

1 Like

@ScruffR are you able to help?

Thanks @KyleG

I’m not complaining that there are more, rather I want to know if there’s a detrimental effect (as in there’s a burden on Particle.process() or something along those lines.

1 Like

most people solve the problem by combining several variables into a single JSON string:

Particle.variable("conditions", conditions, STRING);

and build it accordingly:

  char myJSON[255] = "";
  snprintf(myJSON, 255, "{\"current\":{\"conditions\":\"%s\",\"temp\":%d,\"humidity\":%d,\"dewpoint\":%d,\"windDir\":\"%s\",\"windSpeed\":%d}}", observation, int(outdoorTemp), int(relHumidity), int(dewPoint), windDir, windSpeed);
  strcpy(conditions, myJSON);

results in a JSON object easily handled…

{"current":{"conditions":"Overcast","temp":81,"humidity":85,"dewpoint":76,"windDir":"SW","windSpeed":1}}
1 Like

If I recall correctly, it’s a memory thing. Variables take up a bit of memory, which is guaranteed for 20 variables at 12 characters each. It might be possible to use more with shorter names, but memory limits might pop up at a certain point.
Shouldn’t be harmful as far as I’m aware :slight_smile:

3 Likes

Both Photon’s were in “connect” mode this morning and offline… I have a local unit on the desk and an installed unit on premise. The both went down at the same time early this morning ~5:30 AM with hard faults. The code otherwise has been incrementally built and been rock solid reliable for weeks.

I’m thinking there’s something afoot by pushing the variable limits…

If it’s indeed related to the variables… That’s what you get when you push past the limits :wink:
Try reducing them and see if it makes a difference?

I traced my reset issue down to memory resource bleed (don’t init a struct via memset that has string members).

I’ve also had the grace of being able to employ a setup() delay which provides a window to push in a new build should I find my remote photon is having hard fault restarts as a result of a FOTA push…

So, in essence the question still looms…
What or where is the limit and are there downsides?

I have since condensed data results to a json payload @BulldogLowell, as that was my ultimate goal…

In the interim of acquiring analytic data and logic results I’ve had to instantiate several cloud var instances to characterize my sampling and analytics routines remotely as I can’t replicate the process environment on my desk.

Now that I have bullet proofed that operation I’m happily pushing json payloads. I am however using the SparkJson lib vs. direct string building as you illustrated.