Paricle.subscribe() in Different class


I am trying to use particle.subscribe in my ActivityLogger class but when I run my code, it doesn’t execute the Particle.subscribe() that I have in my constructor. I am very rusty in c++ and have probably made an obvious mistake. The link below is my current code and the particle.subscribe() is in ActivityLogger.cpp:


Due to the non-deterministic order of execution of constructors you should not use any code in a constructor that relies on the existence of another object (e.g. Particle).

There were even device OS versions where pinMode() was not allowed in a constructor.

The common way to do things like this is to add a xxxx.begin() or xxxx.init() function which will be called after all static objects have been constructed (e.g. in setup()).


Ok thank you, Do you know how I can register a Particle.subscribe event in my ActivityLogger class. I basically just want to have the server returned status code to that subscribe available in that class so that I can determine whether to pop_front() on my send data or not based on the server response.


I added an ActivityLogger.init() function and moved the subscribe into there and called ActivityLogger.init() in setup(), but it is still not executing the subscribe (no Serial.println() output which is inside the subscribe handler)


Maybe take a step back and focus on the one issue at hand by cobbling together a test project that only does that.
Once you get that working as intended you can incorporate that into your bigger project.

However, we still would need to know what device OS version and platform you are targeting (in each individual thread again).


I made a dumb mistake. didn’t prepend the event name with “hook-response” facepalm. Thanks for your help.