Particle flashes red - how do I debug this?


I'm trying to create a Particle library.
I started with the uber-library-example template (which works fine)

I am trying to add a layer on top of the MQTT library.
My early stage library can be found here:

Currently it compiles just fine with

particle flash my-device examples/usage/usage.cpp

When my photon starts up, it just flashes green, blue and then red (SOS)...
How can I debug what went wrong?

The amount of blinks indicated what kind of failure it was which might help narrow things down. Have a look in the docs for the meaning :slight_smile:

1 Like

At that gitlab link isn’t a lot to look at :wink:

1 blink (hard fault) is now public.
I really don’t find the problem… It keeps blinking red (hard fault)

memcpy(id, (char *)ID1, 12);

Where does ID1 come from?

Also, is there any particular reason for not using sprintf() to do the HEX conversion?

Next, any reason to have the MQTT client not as private field of your class?
Or why are you not just deriving from MQTT?

I got the method for getUUID() here: Get the current core ID on the core itself?
And that method works.

Indeed, deriving from MQTT is a good idea. I’m new to C++ :slight_smile:
I’ll look into that. Thanks!

1 Like

I tracked down the error and found out this:
When I call one of the callback functions in on_message, the photon blinks red (hard fault).
When I comment them out, everything works.
Also, calling other functions on the object (like getUUID) work.
What am I doing wrong and why doesn’t the compiler see it?

void Bremo::on_message(char* topic, uint8_t* payload, unsigned int length) //char* topic, byte* payload, unsigned int length // TODO ?
  //TODO switch case topic
  //on_session(); // ERROR HERE
  //on_phase(); // ERROR HERE
  //on_stop(); // ERROR HERE

  Serial.println(getUUID()); // THIS WORKS (NO ERROR)  //TODO remove (just for test)

@kenvernaillen, it all depends on what on_session(), on_phase() and on_stop() do! You could be killing the stack or dividing by zero or a creating a recursive loop. It would help if you posted the code for those.

The code can be found here:

A usage example here:

on_session, on_phase, on_stop are methods that only do a Serial.println(). They are passed to the library from usage.cpp.

@kenvernaillen, the pre-processor maybe doing weird voodoo here. The functions in question are declared after the construction of the Instance object. This would explain why the class function getUUID works but not the others. I suggest putting those function declarations before the instantiation to see if that helps.

@peekay123 still the same issue :disappointed:
When I call the callback functions directly in the Bremo::connect method, they work.
Even when I do

this->on_connect = on_connect;
this->on_session = on_session;
this->on_phase = on_phase;
this->on_stop = on_stop;


The references must be lost somewhere after the connect method.
When I do this in on_message:

Serial.println(on_connect ? "true" : "false");
Serial.println(on_phase ? "true" : "false");
Serial.println(on_stop ? "true" : "false");

it prints “false, false, false”

making the functions global works!
weird that it doesn’t recognize the functions when they are part of the object.

What when you mark them static?

making them static works too.