Non capisco dove sbaglio..

Ciao,in un void da quando ho aggiunto il codice con il comando [ ?h ] non mi funziona più il comando [ ?P ].
Il comando ?P,mi permette di conoscere data/ora del rtc.
Il comando ?h,mi permette di conoscere i valore scritti in e2prom degli indirizzi 5,6,7,8.
Non Capisco,dove sbaglio.
Grazie,allego il void del codice.

void RTC_Seriale () {

  // Wait for incoming data on serial port
  if (Serial.available() > 0) {

    // Read the incoming character
    char incoming_char = Serial.read();
    
    // End of line?
    if(incoming_char == '

) {

//
      // Lista Comandi
      //
     
      // ?? Verifica Trasmissione TxRx
      if(serial_buffer[0] == '?' && serial_buffer[1] == '?')
      Serial.println("Trasmissione OK");

// ?V Versione File
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'V')
      Serial.println(VERSION);

// ?P Richiesta Giorno/Data/Ora Attuale
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'P') {       
      DateTime now = RTC.now();
      char time_string[20];
      sprintf(time_string, "Giorno [ %01d ] Data [ %02d/%02d/%d ] Ora [ %02d:%02d:%02d ]",
      now.dayOfTheWeek(),
      now.day(), now.month(), now.year(),
      now.hour(), now.minute(), now.second());
      Serial.println(time_string);
      }

// ?R Rifasamento Data/Ora da Terminale Operatore
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'R') {

String time_string = String(serial_buffer);
      int day = time_string.substring(2, 4).toInt();
      int month = time_string.substring(4, 6).toInt();       
      int year = time_string.substring(6, 10).toInt();
      int hour = time_string.substring(10, 12).toInt();
      int minute = time_string.substring(12, 14).toInt();
      int second = time_string.substring(14, 16).toInt();
      RTC.adjust(DateTime(year, month, day, hour, minute, second));
      Serial.println("RTC Rifasato");
      }

// ?H Imposta Selezione Fasce On / Off da Terminale Operatore
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'H') {

String time_string = String(serial_buffer);
      int hour_on = time_string.substring(2, 4).toInt();
      int minute_on = time_string.substring(4, 6).toInt();       
      int hour_off = time_string.substring(6, 8).toInt();
      int minute_off = time_string.substring(8, 10).toInt();
      address = 5;
      value = hour_on ;
      EEPROM.write(address, value);
      address = 6;
      value = minute_on ;
      EEPROM.write(address, value);
      address = 7;
      value = hour_off ;
      EEPROM.write(address, value);
      address = 8;
      value = minute_off ;
      EEPROM.write(address, value);
      Serial.println("Impostata Selezione Oraria");
      }

//
// Quando aggiungo questo pezzo di codice non funziona il comando ?P
//

// ?h Richiesta Parametri Selezione Fasce On / Off impostati
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'h') {

String time_string = String(serial_buffer);
        int hour_on = time_string.substring(2, 4).toInt();
        int minute_on = time_string.substring(4, 6).toInt();       
        int hour_off = time_string.substring(6, 8).toInt();
        int minute_off = time_string.substring(8, 10).toInt();
        address = 5;
        value = EEPROM.read(address);
        Serial.print ("Ora di Start : ");
        Serial.print (value);
        Serial.println (" ");
        address = 6;
        value = EEPROM.read(address);
        Serial.print ("Minuti di Start : ");
        Serial.print (value);
        Serial.println (" ");
        address = 7;
        value = EEPROM.read(address);
        Serial.print ("Ora di Stop : ");
        Serial.print (value);
        Serial.println (" ");
        address = 8;
        value = EEPROM.read(address);
        Serial.print ("Minuti di Stop : ");
        Serial.print (value);
        Serial.println (" ");
        Serial.println("Parametri Selezione Fasce On / Off impostati");
      }

//////////////////////////////////////////////////////////////////////////////////////////////

// ?r Richiesta Variabili L/S da Terminale Operatore
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'r') {

for (int address = 0; address <= 4; address++) {
      value = EEPROM.read(address);
      Serial.print(F("Step\t = \t"));
      Serial.print( char('a'+address) );
      Serial.print(F("\t ; \t Valore \t = \t"));
      Serial.println(value, DEC);
      delay(100);
      if (address == 4) {
      address = 0;
      Serial.println();
      break;
      }
      }
      }

// ?w Imposta Variabili L/S da Terminale Operatore
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'w') {

String time_string = String(serial_buffer);
int attendiS31 = time_string.substring(2, 3).toInt();
int attendiSdom = time_string.substring(3, 4).toInt();        
int attendiL31 = time_string.substring(4, 5).toInt();
int attendiLdom = time_string.substring(5, 6).toInt();
int read_write = time_string.substring(6, 7).toInt();
address = 0;
value = attendiS31 ;
EEPROM.write(address, value);
address = 1;
value = attendiSdom ;
EEPROM.write(address, value);
address = 2;
value = attendiL31 ;
EEPROM.write(address, value);
address = 3;
value = attendiSdom ;
EEPROM.write(address, value);
address = 4;
value = read_write ;
EEPROM.write(address, value);
Serial.println("Variabili L/S Rifasate");

}

//////////////////////////////////////////////////////////////////////////////////////////////

// Reset the buffer
      buffer_position = 0;
      memset(serial_buffer, 0x00, BUFFER_SIZE);
    }

// Carriage return, do nothing
    else if(incoming_char == '\r');
   
    // Normal character
    else {

// Buffer full, we need to reset it
      if(buffer_position == BUFFER_SIZE - 1) buffer_position = 0;

// Store the character in the buffer and move the index
      serial_buffer[buffer_position] = incoming_char;
      buffer_position++;     
    }
  }   
}

oopss , questo è il void che sto utilizzando,scusate l'errore :

void RTC_Seriale () {

  // Wait for incoming data on serial port
  if (Serial.available() > 0) {

    // Read the incoming character
    char incoming_char = Serial.read();
    
    // End of line?
    if(incoming_char == '

) {

//
      // Lista Comandi
      //
     
      // ?? Verifica Trasmissione TxRx
      if(serial_buffer[0] == '?' && serial_buffer[1] == '?')
      Serial.println("Trasmissione OK");

// ?V Versione File
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'V')
      Serial.println(VERSION);

// ?P Richiesta Giorno/Data/Ora Attuale
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'P') {       
      DateTime now = RTC.now();
      char time_string[20];
      sprintf(time_string, "Giorno [ %01d ] Data [ %02d/%02d/%d ] Ora [ %02d:%02d:%02d ]",
      now.dayOfTheWeek(),
      now.day(), now.month(), now.year(),
      now.hour(), now.minute(), now.second());
      Serial.println(time_string);
      }

// ?R Rifasamento Data/Ora da Terminale Operatore
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'R') {

String time_string = String(serial_buffer);
      int day = time_string.substring(2, 4).toInt();
      int month = time_string.substring(4, 6).toInt();       
      int year = time_string.substring(6, 10).toInt();
      int hour = time_string.substring(10, 12).toInt();
      int minute = time_string.substring(12, 14).toInt();
      int second = time_string.substring(14, 16).toInt();
      RTC.adjust(DateTime(year, month, day, hour, minute, second));
      Serial.println("RTC Rifasato");
      }

// ?H Imposta Selezione Fasce On / Off da Terminale Operatore
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'H') {

String time_string = String(serial_buffer);
      int hour_on = time_string.substring(2, 4).toInt();
      int minute_on = time_string.substring(4, 6).toInt();       
      int hour_off = time_string.substring(6, 8).toInt();
      int minute_off = time_string.substring(8, 10).toInt();
      address = 5;
      value = hour_on ;
      EEPROM.write(address, value);
      address = 6;
      value = minute_on ;
      EEPROM.write(address, value);
      address = 7;
      value = hour_off ;
      EEPROM.write(address, value);
      address = 8;
      value = minute_off ;
      EEPROM.write(address, value);
      Serial.println("Impostata Selezione Oraria");
      }

//
// Quando aggiungo questo pezzo di codice non funziona il comando ?P
//

// ?h Richiesta Parametri Selezione Fasce On / Off impostati
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'h') {
        address = 5;
        value = EEPROM.read(address);
        Serial.print ("Ora di Start : ");
        Serial.print (value);
        Serial.println (" ");
        address = 6;
        value = EEPROM.read(address);
        Serial.print ("Minuti di Start : ");
        Serial.print (value);
        Serial.println (" ");
        address = 7;
        value = EEPROM.read(address);
        Serial.print ("Ora di Stop : ");
        Serial.print (value);
        Serial.println (" ");
        address = 8;
        value = EEPROM.read(address);
        Serial.print ("Minuti di Stop : ");
        Serial.print (value);
        Serial.println (" ");
        Serial.println("Parametri Selezione Fasce On / Off impostati");
      }

//////////////////////////////////////////////////////////////////////////////////////////////

// ?r Richiesta Variabili L/S da Terminale Operatore
      else if(serial_buffer[0] == '?' && serial_buffer[1] == 'r') {

for (int address = 0; address <= 4; address++) {
      value = EEPROM.read(address);
      Serial.print(F("Step\t = \t"));
      Serial.print( char('a'+address) );
      Serial.print(F("\t ; \t Valore \t = \t"));
      Serial.println(value, DEC);
      delay(100);
      if (address == 4) {
      address = 0;
      Serial.println();
      break;
      }
      }
      }

// ?w Imposta Variabili L/S da Terminale Operatore
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'w') {

String time_string = String(serial_buffer);
int attendiS31 = time_string.substring(2, 3).toInt();
int attendiSdom = time_string.substring(3, 4).toInt();        
int attendiL31 = time_string.substring(4, 5).toInt();
int attendiLdom = time_string.substring(5, 6).toInt();
int read_write = time_string.substring(6, 7).toInt();
address = 0;
value = attendiS31 ;
EEPROM.write(address, value);
address = 1;
value = attendiSdom ;
EEPROM.write(address, value);
address = 2;
value = attendiL31 ;
EEPROM.write(address, value);
address = 3;
value = attendiSdom ;
EEPROM.write(address, value);
address = 4;
value = read_write ;
EEPROM.write(address, value);
Serial.println("Variabili L/S Rifasate");

}

//////////////////////////////////////////////////////////////////////////////////////////////

// Reset the buffer
      buffer_position = 0;
      memset(serial_buffer, 0x00, BUFFER_SIZE);
    }

// Carriage return, do nothing
    else if(incoming_char == '\r');
   
    // Normal character
    else {

// Buffer full, we need to reset it
      if(buffer_position == BUFFER_SIZE - 1) buffer_position = 0;

// Store the character in the buffer and move the index
      serial_buffer[buffer_position] = incoming_char;
      buffer_position++;     
    }
  }   
}

La memoria a quanto sta?

Ciao,ma in che senso ??

Dopo la compilazione, quanto ti appare nell'IDE?

Questo è l'esito della compilazione :

Sketch uses 10,072 bytes (31.2%) of program storage space. Maximum is 32,256 bytes.
Global variables use 699 bytes (34.1%) of dynamic memory, leaving 1,349 bytes for local variables. Maximum is 2,048 bytes.

Va bene. Non sta lì il problema.

Quel pezzo di programma è un po' confuso, ma non mi sembra ti possa dare quel problema
Due cose
Posta programma completo
Spiega il protocollo che usi per comunicare da PC, perché non mi è chiaro

Sembra che legga semplicemente ciò viene battuto sulla tastiera del computer da seriale, tramite la connessione USB...

No
È più complesso, se il carattere ricevuto non è riconosciuto lo salva in un buffer locale
Se viene riconosciuto legge dei dati dal buffer locale
Che quindi il protocollo è determinante
E lo OP lo deve spiegare

E' buona norma "universale" non usare mai caratteri "strani" tipo, appunto, il punto di domanda.
Hai provato con un carattere più NORMALE ?

Ciao,non riesco a postare tutto il programma perchè si trova sul portatile adesso,però ,tutti i comandi mi funzionano ,compreso ?P ma,quando aggiungo il pezzo di codice con il comando ?h,funzionano tutti tranne ?P.
Il protocollo è il seguente ?Lettera$ , leggo i comandi inviati tramite terminale,nel buffer seriale.
booh spero che basti,come primo indizio..

Grazie

Indizio?
Non stiamo mica giocando a Cluedo.
Il protocollo è tuo e lo conosci alla perfezione, quindi ce lo spieghi... Grazie

Scusa,forse ho sbagliato a scrivere indizio,quando da terminale faccio una richiesta alla scheda mi aspetto una risposta nella lista di comandi elencati:
Dal Comando che invio ?P$ ,la risposta è la seguente : Giorno [01] Data [ 03/06/2019 ] Ore [ 12:58:00 ]
quando aggiungo il comando ?h$ ,il comando ?P$ non funziona più,non ho nessuna risposta.

Spero,che Basti,vorrei capire cosa possa dare fastidio nle pezzo di codice aggiunto per non far funzionare più SOLO in comando ?P$

Hai troppi "else if" in cascata senza una indentazione decente e questo ti fa perdere di vista qualche "else" a quale "if" corrisponda.

Inizia mettendo le graffe ad ogni "if" e ad ogni "else", poi indenta (Ctrl-T nell'IDE te lo fa lui), poi separa il controllo di serial_buffer[0] == '?' dal comando serial_buffer[1] (ovvero metti UN if iniziale che controlla se "serial_buffer[0] == '?'" e dentro a questo tutti gli if dove controllare solo serial_buffer[1], oppure direttamente una istruzione "switch") e secondo me è probabile che tu possa capire da solo dove sia il problema... :wink:

Già, mi sa che hai ragione (e anche ragione veduta)

Io, però, ancora non ci arrivo.
Ok per il test serial_buffer[0] == '?' che si può fare una volta sola migliorando la leggibilità generale.
Ok per indentare bene il tutto, che è sempre cosa buona e giusta.
Ok per un errore sugli if che però dovrebbe produrre un errore di compilazione e non l'errore indicato dall'OP (sbaglio?).
L'errore dichiarato dall'OP non lo riesco a giustificare e sarei tentato di metterlo proprio in dubbio.
Mi è sfuggito qualchecccccosa?

maubarzi:
Ok per un errore sugli if che però dovrebbe produrre un errore di compilazione e non l'errore indicato dall'OP (sbaglio?).

No, perché se metti un "else" pensando che sia quello di un certo if() ed invece dalla cascata è un altro, non è un errore di sintassi ma ecco che tutti i controlli successivi vanno a donnine allegre :wink:

L'errore dichiarato dall'OP non lo riesco a giustificare e sarei tentato di metterlo proprio in dubbio.
Mi è sfuggito qualchecccccosa?

Qua ci sfugge a tutti quaccheccosa... :smiley: Sinceramente dovermi mettere io a riformattargli il codice e quindi vedere cove sia l'inghippo non mi va molto, se va all'OP è meglio per noi (perché evitiamo un mal di testa) ma anche per lui (perché impara come si fa debug :wink: ).

Fino a reset the buffer la formattazione si capisce bene, anche adesso dal telefonino; poi c'è una graffa che non capisco che cosa chiuda...

docdoc:
No, perché se metti un "else" pensando che sia quello di un certo if() ed invece dalla cascata è un altro, non è un errore di sintassi ma ecco che tutti i controlli successivi vanno a donnine allegre :wink:

Mi sono messo ad indentare e mi pare corretto, quello che ho rilevato è un ; dove non ci dovrebbe stare, verso la fine.
Però forse mi sfugge a me un dettaglio della sintassi del C, perchè il compilatore pare me lo accetti... ignoranza mia probabilmente.

Alludi al codice postato nel primo post o nel secondo? io ho guardato il secondo.