Set subscribe handler data as global

Hi ScruffR! Thank you very much for your writing the code. I've tested it and I have no stack overflow, i will try to implement parts of it (unifying function and publish) into my code

  • Why do you use const int instead of int to declare pins?
  • I see that you used log.info/log.warn instead of serial.print! I'll implement that to my code so it looks neater :slight_smile:
  • I've also removed dailysparktimer and used your float hh timer instead.
  • I noticed that you used wrote char msg[16] = "", strncpy(msg, "Dark", sizeof(msg)); and Particle.publish("C8_ambience", msg);
    How is this different from Particle.publish("C8_ambience", "Dark", PRIVATE);? Is the one you wrote, is a char and the one with "Dark" a string that gets converted to char (Since ambience_handler (const char *event, const char *data) )?
  • Whats the difference between having a function prototype and function declaration? Does having a function prototype help to improve code speed?

I just realised i used strings in my ambience handler!! I noticed in your code you wrote the below.

void c8_Handler(const char *event, const char *data){
  Log.trace("%s: <%s>", event, data);
  if(!LITERALCMP(data, "Dark")) {

I;m trying to understand const and strings. If I replace if(ambience_status=="Dark") with if(data=="Dark"), my code still verified, however whatever is inside the if statement does not execute. I tried if(data = "Dark") and whatever inside the if statement works. Why is this so?

I was wondering if writing serialprint&publish once based on LDR state every 5 seconds would allow photon to be more efficient;

I'm about halfway done with my project, though I'm still facing stack overflow issue with my own code.

I managed to get the fingerprint scanner widget button on blynk working with this:

void fingerprint_scanner(){
    if (digitalRead(button) == LOW){
        Particle.publish("door_status_D8", "DOOR UNLOCKED");
    }
    else{ // HIGH
        Particle.publish("door_status_D8", "door locked");
    }
}

BLYNK_WRITE(V4){       // widget btn state opposite of physical btn state  
    if(param.asInt()){ // HIGH , param.asInt() gets value from pin V4
        Particle.publish("door_status_D8", "door locked");
    }
    else{              // LOW
        Particle.publish("door_status_D8", "DOOR UNLOCKED");
    }
}