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.
#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!