# Particle.subscribe unique device ID not returning correct values

**URL:** <https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422>\
**Category:** Firmware\
**Created:** [December 20, 2015, 6:39pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422 "2015-12-20T18:39:23Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![joedonn](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@joedonn](https://community.particle.io/u/joedonn)\
**Post date:** [December 20, 2015, 6:39pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/1 "2015-12-20T18:39:23Z")

</div>

I’m using the following command and the values returned are not correct when using the device ID :

Particle.subscribe(“Humidity”, myHandler1, “2d002…xx…3230”);

The values returned are somewhat random integers. Examples:

Time:1:52,  
Soil Humidity1:29.00

Time:2:2,  
Soil Humidity1:50.00

Time:2:22,  
Soil Humidity1:50.00

While using:

Particle.subscribe(“Humidity”, myHandler1, MY\_DEVICES);

does return the correct value from the unique device (my only device with the event “Humidity”):

Time:9:56,  
Soil Humidity1:55.82

Is my use in the 1st example correct or am I missing a parameter?

Thanks!

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [December 21, 2015, 1:15am UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/2 "2015-12-21T01:15:52Z")

</div>

Seems ok… though you might want to post the handler code so that we can see what’s going on

---

<div class="post-metadata">

**Author:** ![joedonn](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@joedonn](https://community.particle.io/u/joedonn)\
**Post date:** [December 21, 2015, 2:23am UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/3 "2015-12-21T02:23:10Z")

</div>

Here is the relevant code. As I mentioned previously, when I use the MY\_DEVICES parameter vs the device ID, the data is correct. When using MY\_DEVICES, I need to have unique output variables for each subscription (which I am tying to avoid). I want to subscribe to the Humidity variable in a per device, per handler basis.

```auto
#include "stdlib.h"
#include "TimeAlarms/TimeAlarms.h"
#include "elapsedMillis/elapsedMillis.h"

// Define names for the Digital pins On the Photon D0, D1
// These data pins link to Relay board pins IN1, IN2

#define RELAY1 D0                        
#define RELAY2 D1                       

//Set the timer for the void loop function
elapsedMillis timeElapsed; //declare global if you don't want it reset every time loop runs
unsigned int interval = 3600000; //This is the delay in ms. 3,600,000=1hr

// Declare the variables
float totalPrecip;
float totalPrecipMin = 5.08; //Values are reported in mm, 5.08 is .2in.
float soil_humidity = 80; //This is the soil moisture minimum
int relay_duration = 420000; //Duration in ms. 420,000=7mins
float humidity_a1 = 100; //Initially sets humidity at 100% so relays do not switch on when no value exists for humidity
float humidity_a2 = 100;

//Define the Handlers
void myHandler1(const char *event, const char *data)
{
humidity_a1 = atof (data);
}

void myHandler2(const char *event, const char *data)
{
humidity_a2 = atof (data);
}

void setup()
{   
 
  Time.zone(-8);
  
  // create the alarms 
  Alarm.alarmRepeat(5,30,0, MorningAlarm); // 5:30am every day

  // Listen for the hook response
  Particle.subscribe("hook-response/CLD_precipitation", gotWeatherData, MY_DEVICES);

// Initialize the Photon data pins for OUTPUT
  pinMode(RELAY1, OUTPUT);       
  pinMode(RELAY2, OUTPUT);

  Particle.subscribe("Humidity", myHandler1, "123456789ABCDEF");
  Particle.subscribe("Humidity", myHandler2, "ABCDEF123456789");

  digitalWrite(RELAY1,HIGH); // Turns Relay Off
  digitalWrite(RELAY2,HIGH); // Turns Relay Off
  
  Serial.begin(9600);
  Serial.println("Hello");
}
 
void loop(){
  if (timeElapsed > interval)
  {
  Serial.print("Time:");
  Serial.print(Time.hour());
  Serial.print(":");
  Serial.print(Time.minute());
  Serial.println(",");
  Serial.print("Soil Humidity1:");
  Serial.println(humidity_a1);
  Serial.print("Soil Humidity2:");
  Serial.println(humidity_a2);
  Serial.println("Requesting Precipitation!");
  Particle.publish("CLD_precipitation");
  timeElapsed = 0;
  }
  Alarm.delay(1000);
}

```

When using the CLI: particle subscribe Humidity 123456789ABCDEF ,the correct data is returned as well.

Any help is appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [December 21, 2015, 5:32am UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/4 "2015-12-21T05:32:44Z")

</div>

Just to try… can you use 2 unique event name like:

```auto
Particle.subscribe("Humidity1", myHandler1, "123456789ABCDEF");
Particle.subscribe("Humidity2", myHandler2, "ABCDEF123456789");

```

and see if the problem persists?

---

<div class="post-metadata">

**Author:** ![joedonn](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@joedonn](https://community.particle.io/u/joedonn)\
**Post date:** [December 22, 2015, 3:19am UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/5 "2015-12-22T03:19:37Z")

</div>

> [@kennethlimcp](#):
>
> Particle.subscribe("Humidity1", myHandler1, "123456789ABCDEF");  
> Particle.subscribe("Humidity2", myHandler2, "ABCDEF123456789");

Does not work, although, the below works.

Particle.subscribe("Humidity1", myHandler1, MY\_DEVICES);  
Particle.subscribe("Humidity2", myHandler2, MY\_DEVICES);

I am performing a copy/paste on the ID numbers, so there are not typos and when I run it in the CLI (particle subscribe Humidity 123456789ABCDEF), the correct values are returned. I guess a workaround is that I'll manage variables in my code and mini deployment, but I believe that is going to make overall device management much more difficult.

---

<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:** [December 22, 2015, 3:40am UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/6 "2015-12-22T03:40:52Z")

</div>

I think we should ping @Dave here and see if the deviceID subscribe endpoint is working in the cloud yet. I seem to recall this was delayed before and I don’t know the state now.

---

<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:** [December 22, 2015, 8:37am UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/7 "2015-12-22T08:37:30Z")

</div>

Could you also show the `Particle.publish()` commands the should trigger the subscriptions?  
There is a still open issue

> <https://github.com/particle-iot/firmware/issues/645>

---

<div class="post-metadata">

**Author:** ![joedonn](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@joedonn](https://community.particle.io/u/joedonn)\
**Post date:** [December 22, 2015, 4:19pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/8 "2015-12-22T16:19:40Z")

</div>

Here are the publish commands:

Sensor1:  
Particle.publish(“Humidity1”, String(humidity), 60, PRIVATE);

Sensor2:  
Particle.publish(“Humidity2”, String(humidity), 60, PRIVATE);

---

<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:** [December 22, 2015, 6:07pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/9 "2015-12-22T18:07:43Z")

</div>

These are issued from two different devices (not two sensors on one Particle device), right?

As mentioned in the linked issue and in more detail in the closed [issue #371](https://github.com/spark/firmware/issues/371) you could try to publish publicly (just to test) - it used to work (counter-intuitively) that way with 0.4.5 and I guess it hasn’t really changed since.  
Hopefully it will be with 0.4.9 (0.4.8 seems to only be internal/develop).

---

<div class="post-metadata">

**Author:** ![joedonn](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@joedonn](https://community.particle.io/u/joedonn)\
**Post date:** [December 22, 2015, 6:09pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/10 "2015-12-22T18:09:24Z")

</div>

Yes. Two different particle devices. I’ll try to publish publicly and I’ll let you know if that works. Thanks!

---

<div class="post-metadata">

**Author:** ![joedonn](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@joedonn](https://community.particle.io/u/joedonn)\
**Post date:** [December 22, 2015, 6:28pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/11 "2015-12-22T18:28:12Z")

</div>

It appears to work when published publicly. Thanks!

---

<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:** [December 22, 2015, 6:51pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/12 "2015-12-22T18:51:35Z")

</div>

Yup, as I thought - still no change 😩, but we can still hope for 0.4.9+ 😉

---

<div class="post-metadata">

**Author:** ![Muskie](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/muskie/32/4044_2.png) [@Muskie](https://community.particle.io/u/Muskie)\
**Post date:** [December 22, 2015, 9:08pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/13 "2015-12-22T21:08:45Z")

</div>

Get or get not, there is no hope.

---

<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:** [December 22, 2015, 10:06pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/14 "2015-12-22T22:06:53Z")

</div>

The issue is milestoned for 0.4.9 (since 0.4.8 will not go public 😉 )

---

<div class="post-metadata">

**Author:** ![blownupp](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/blownupp/32/7872_2.png) [@blownupp](https://community.particle.io/u/blownupp)\
**Post date:** [December 24, 2015, 8:28pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/15 "2015-12-24T20:28:38Z")

</div>

Hello,

So just to clarify that I understand this issue correctly; if I want to Particle.subscribe() to a unique device\_id, I want to Particle.publish() that event as PUBLIC instead of PRIVATE ?

Thank you!

EDIT: Also, if I Particle.publish(“myvar”, myDat, PUBLIC) and subscribe to “myvar” on the same Photon, will I essentially be creating a recursive event, or will it ignore publish events coming from itself?

Basically, I have 2 photons that will be publishing a touch event with color data and subscribing to each others event - should I just use 2 seperate, unique “myvar” with different names or will the Photon ignore publish’s from it self?

---

<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:** [December 24, 2015, 9:29pm UTC](https://community.particle.io/t/particle-subscribe-unique-device-id-not-returning-correct-values/18422/16 "2015-12-24T21:29:56Z")

</div>

This behaviour that you have to publish publicly to subsribe to a device ID is not intended and should get corrected.

About a possible “recursion”: If you intend to publish from a subscribe handler you should add some info about the origin to either `even` or `data` and check in the handler to prevent this situation.
