Console overlap

hey y’all!

I have 4 Borons on my account. I have a function to input parameters to them via a JSON string. I can have the 4 devices consoles open on different tabs on the same browser and see the events of each one properly, so I have an idea when a flash is complete, etc. they are all running the same firmware

However, when I input a parameter with this function, the value I input is assigned to all the devices. Is this a bug on the console, that does not recognize between different tabs? I need to assign different tokens for MQTT communication to each one of them, but when I write to one of them, it overwrites the parameter on the other three.

Any ideas on what is going on?



I'd have to double check myself but I'm pretty sure that Particle.function() calls are specific to the device of which the respective browser tab is tied to (double check the address for the respective device ID).

How do you set the variable in your function and how do you check which value it has on each individual device?

You could try to set a global variable which you also expose via Particle.variable().

thanks @ScruffR !

by the way, I’m using Edge (not chrome, safari, etc.)

I write a JSON string in the function, then the function ingests the string and assigns the value of the object to a global variable.
something like this:
it works pretty good, but I’ve noticed that if I have several device consoles open at the same time on different tabs in the same window, the value gets assigned to all the devices.
I just ran this simple test:
I have 3 devices online with IDs: a23b, ad86, 1015, their consoles open on different tabs. the object ‘Azure string’ is originally empty on all of them
I ran the function on device a23b, assigning a value “abcdefg” on the object "Azure String’. something like this: {“Azure String”: “abcdefg”}
the function then runs two particle.publish: ‘json received’ and ‘json generated’, “JSON received” prints a direct copy of what I wrote in the function to see if it was a valid JSON. “JSON created” builds a new JSON with the values I just added, now assigned to the global variables I will use in the code, plus other additional info related to this variable.

after running this function, I Get the ‘json received’ on the same device a23b, but I receive the ‘json generated’ on the three devices: a23b, ad86 and 1015. they all took the value of the object into their global variables.

this is the issue I’m having… it’s supposed to assign the values to only the device of the console I’m seeing, not all my devices with tabs open.

I’m adding an image with the publishes from the 3 devices. I’m blurring some of the confidential content, but you can see the point.

Any input will be greatly appreciated.

I’m still pretty sure there is something else at play.
I have now tested with three Borons, Edge, three console tabs and this code

int value;

void setup() {
  Particle.function("set", set);
  Particle.variable("value", value);

int set(const char* arg) {
  value = atoi(arg);
  return value;

This behaves exactly as intended. No cross-talking between console tabs and individual devices.

However, with Particle.publish() and possibly a related Particle.subscribe() the behaviour can be explained and would be expected.
I suspect your “other” devices subscribe to "JSON Generated", catch that event and set their local values due to that event and not as a result of the Particle.function() call.

BTW, seeing your event names it appears you are not aware of this
Device OS API | Reference Documentation | Particle

So better don’t use the space after JSON.

1 Like

ah perfect! thanks @ScruffR for your support. Indeed, there was a particle.subscribe which was not needed. I didn’t need a Particle.variable(), I just needed to adjust the code to stop using the subscribe function.

I tested the new code on one of the 3 devices. when ran the particle.function, it created the publish on the other devices (because they still have the subscribe()), but if I ran the function on the other 2 devices, this device with the new code did not publish (no subscribe, no need to publish).

lesson learned!

p.s. thanks for the comment on the event names, I missed that and will correct now.


1 Like

by the way… then what is the reach of the particle.subscribe? for example, these devices are subscribing to the event “JSON Received”… if any other particle IO device, even beyond my product or owned devices, publishes an event with this name, is it going to affect these devices? or does it only work with the devices within my Product?

The docs would be a good place to look for that :wink:

Particularly NOTE 3

I see what you did there! thank you sir, I found it!


1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.