Hi everyone.
I am missing something super simple.
I am trying to pull a variable from my heroku app to my Photon. I set up a webhook to the heroku URL using GET (I do not need to send any data) called SERVICEBUTTON1. My issue is that I do not understand how to get/use the response in my .ino code.
I have tried:
Particle.subscribe(“servicebutton1”, handler, MY_DEVICES);
Particle.subscribe doesnt seem to fire for me at all. I do not see any event triggering in my console.
and…
Particle.publish(“servicebutton1”, “25”, PRIVATE);
This works and I see the correct response from Heroku in the console. However, I have no idea how to use the data. Also, this sends data “25” in this case… which I do not need to do.
Any advice is appreciated…
My full code:
const int checkinterval = 20000;
unsigned long currenttime = 0;
unsigned long previoustime = 0;
int redPin = D0;
int greenPin = D1;
int bluePin = D2;
int redPin2 = D3;
int greenPin2 = D4;
int bluePin2 = D5;
void setup(){
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(bluePin2, OUTPUT);
}
void loop() {
currenttime = millis();
if (currenttime - previoustime >= checkinterval) {
// setColor(255, 0, 0, 1);
// delay(1000);
// setColor(255, 0, 0, 2);
// delay(1000);
// setColor(0, 255, 0, 1);
// delay(1000);
// setColor(0, 255, 0, 2);
// delay(1000);
Particle.publish("servicebutton1", "25", PRIVATE);
Particle.subscribe("servicebutton1", handler, MY_DEVICES);
previoustime = currenttime;
}
}
void handler(const char *event, const char *data) {
Particle.publish("triggerlight1 function called");
//if(data == "Water 1 Status: 0"){
setColor(255, 0, 0, 1);
//}else{
//setColor(0, 255, 0, 1);
//}
}
void setColor(int red, int green, int blue, int lightnumber){
if(lightnumber == 1){
digitalWrite(redPin, 255 - red);
digitalWrite(greenPin, 255 - green);
digitalWrite(bluePin, 255 - blue);
}else{
digitalWrite(redPin2, 255 - red);
digitalWrite(greenPin2, 255 - green);
digitalWrite(bluePin2, 255 - blue);
}
}