Help with Photon reading serial data from external mcu

Hi there!

I am sending a string of 42 characters using the serial1 to the Photon RX pin.
Currently, I’m using code that was working OK with Blynk library.
Because I want to switch to Electron I decided to try UBIDOTS for my dashboard.
But for testing the code I’m keeping with Photon.
The point is that part of the code that I was using with Blynk was working OK but currently does not work at all.
The piece of code I am referring to is waiting for receiving the header of the string which is an " A", and when that happens, set a flag, next run a function that using serial1.read() stores the char received at char Temp[42] array.
Here is the string to be received.: A78.04%81.09%80.20%36.75%78.40%111.13%78.35%81.66%
That code doesn’t work at all and the external MCU is sending correctly the string which I can verify using a serial to USB converter to RealTerm.
Here is the code:
Thanks for any help

void lookForIni();
void waitForString();

int Aflag;
char Temp[42]={'\0'};  
char data;
 
void lookForIni() {
   
 int i=0;  
 
 /* String expected fro pin RX on the photon */
 /*  A78.04%81.09%80.20%36.75%78.40%111.13%78.35%81.66%  */ 

//Keep reading "data" until find 'A', then set Aflag=1
    while ( data !='A')  // check for A
        {   
            if (i>1500)
                 { i=0;  break;}

          data =  Serial1.read();
      
           if(data='A')
                {Aflag=1;   break ;  }
           
            else{Aflag=0;      }
           
            i++;
         }
}


void waitForString()
{
  // Tenp[i] store the string received for external MCU 
 
int i=0;

while ( Serial1.available()>0  && i<42 )
     {   
      if (Aflag!=1)
       { break;}
         
         while(1) // carga el LBS[] array
         {
             data =  Serial1.read();
             Serial1.print(data);  
             
                if (data!='A')
      //------------------------------------          
              {  Temp[i] = data;

                i++;

                if (i>42)
                {Aflag=0; break;}
                
              }
       //------------------------------------         
          }
   }     
}


/****************************************
 * Main Functions
 ****************************************/

void setup() {
  Serial1.begin(57600);
}

void loop() {

void lookForIni();
void waitForString();  

}

@Meson777 I edited your code to remove a lot of white space to make it more readable. In your loop() you declare your functions again. Review the void part so that the functions that were pre-declared are actually called.

@peekay123 thanks, please can you expand your answer .
Thanks again.

1 Like

@Meson777

void loop() {
void lookForIni();
void waitForString();  
} 

Should be:

void loop() {
   lookForIni();
   waitForString();  
}
1 Like

@peekay123

Yeesssss!!! Sometimes you get dizzy and can not find a cow in your own garden
Thank you very much.

1 Like