Photon hard fault when using functions

Hi folks,

I’m using the Particle Photon in a simple project of an IoT Scale conect to a firebase database. The prototype was working fine until some weird happen. After a local internet fault my Photon stopped to work and a red led started to blink in the Photon and the device simply resets. It was the SOS code with the indication of “hard fault” (one blink between 2 SOS signals).

To solve this issue I started to debug the software (that was working before…) and I have to put the code for some functions that I’ve created inside the program. This, apparently solved the problem, but I’d like to use the functions to organize the code.

I suspect could be the device OS upgrade to the 2.0 version, or some problem related to the memory, but I’m very intrigued with this issue. Below a piece of code I’m using:

void loop(){
//Verifica se houve mudança no valor medido
medida = (scale.get_units(10));

// Evita envio de medidas negativas - verificar fator de calibração para tentar 
resolver esta questão

if((medida > medida_anterior+0.2 || medida < medida_anterior - 0.2 ) && (timerFlag == true)){
    atualizar_Medida = true;


if (atualizar_Medida == true){
    medida_anterior = medida;
    lcd->setCursor(6 ,0 );
    lcd->setCursor(4 ,1 );
    lcd->setCursor(10 ,1);
    atualizar_Medida = false;
    //Evita publicação na nuvem em  duplicata
    if (pubFlag == true){
            //publicar_na_nuvem(); <===**This is the function that I have to comment**
          **<=== Here starts the function body I have to insert... ====>**
        String timeStamp = Time.timeStr();
            timeStamp = Time.format("%d/%m/%y %H:%M:%S");	
        String scaleID = System.deviceID();

            String Data="{\"scaleID\":\""+ scaleID +"\",";              
                Particle.publish("medidas", Data, PUBLIC);                 
                    //DEBUG_PRINT("Publicou na nuvem");
                   **<<---Here ends the function code >>>**
            pubFlag = false;


// Repete o loop a cada 1s
int startTime = millis();
if(millis()-startTime >= 1000){
timerFlag = true;
pubFlag = true;
timerFlag = false;

Someone have some idea of the problem and a best solution?

Thanks in advance :wink:

Hi guys,

It looks I got to solve the problem. I simply put a missing “return 0;” at the end of the functions I’ve created and the hard fault disapeared. :upside_down_face:

Now the code is running smoothy again,