Subscription handler not executing

Please forgive my ignorance, I have very little experience with programming in general.

I have a webhook configured to get data from another service whenever called from my photon. When I check the webhook history in the particle console, it appears the calls are successfully going through and returning the expected requested value.

However, I can’t seem to read the values on the photon side. I would expect the handler function to be the place to parse the received data and use it accordingly. Here is the simplest form of the code I can make and I can’t get the handler function to even print to the serial monitor.

void setup(){
  Particle.subscribe("hook-response/event_name", my handler, MY_DEVICES);
}
void loop(){
  delay(60000);
  Particle.publish("event_name", "event_data", PRIVATE);
  Serial.println("Request Triggered");
}
void myHandler(const char *event, const char *data){
  Serial.println("handler executed");
}

My serial monitor just repeats “requires triggered” every minute. Any help would be great, thanks in advance.

Please see updated code in post below.

Would be good to see the exact code you use and also the webhook definition and some screenshots from the console.

I can tell the above code is not what you are actually running since that would not compile.

You are correct, I was on mobile while posting and it wouldn’t let me copy verbatim. Below is the code I’m running exactly.

#define relayPin D1

void setup() {
    
  Serial.begin(9600);
  
  // Subscribe to the integration response event
  Particle.subscribe("hook-response/event-name", myHandler, ALL_DEVICES);
  
  //set relaypin to output
  pinMode(relayPin, OUTPUT);

}

void loop() {
    
  delay(60000);  
  Particle.publish("event-name", "triggered", PRIVATE);
  Serial.printlnf("Request Triggered");
   
}

void myHandler(const char *event, const char *data)
{
  
  Serial.println("Handler executed");

}

Your original code subscribes for MY_DEVICES which is correct since you’re publishing PRIVATE.
But in your running code you are subscribing for ALL_DEVICES which doesn’t fly well with PRIVATE events.

Hence the desperate need to see the original code and not some lookalike.

Quick observation, you haven’t declared the myHandler(); before you do the Particle.subscribe(). Before void setup() enter void myHandler(const char *event, const char *data). Also, delay(60000); in the loop() function is not a good idea - better something like this

global variable
unsigned long updatetime;

in setup()
updatetime = millis();

in loop()

if (millis() - updatetime >= 60000)
{
      updatetime = millis();
      Particle.publish();
      Serial.println("Request Triggered");
}

That's not an issue with .ino files since the Particle preprocessor creates function prototypes where they are missing.
While it is good practice and for .cpp files even compulsory the lack of a prototype doesn't hinder the functionality - it would rather cause a compile time error.

1 Like