@@ -348,12 +348,16 @@ void setup() {
348348 }
349349
350350 /* * Start [setup_esp] */
351- modem.modemWake (); // NOTE: This will also set up the modem
352- modemSerial.begin (115200 );
353- modem.gsmModem .sendAT (GF (" +UART_DEF=9600,8,1,0,0" ));
354- modem.gsmModem .waitResponse ();
355- modemSerial.end ();
356- modemSerial.begin (9600 );
351+ for (int8_t ntries = 5 ; ntries; ntries--) {
352+ // This will also verify communication and set up the modem
353+ if (modem.modemWake ()) break ;
354+ // if that didn't work, try changing baud rate
355+ modemSerial.begin (115200 );
356+ modem.gsmModem .sendAT (GF (" +UART_DEF=9600,8,1,0,0" ));
357+ modem.gsmModem .waitResponse ();
358+ modemSerial.end ();
359+ modemSerial.begin (9600 );
360+ }
357361 /* * End [setup_esp] */
358362
359363
@@ -365,10 +369,9 @@ void setup() {
365369 }
366370
367371 // Create the log file, adding the default header to it
368- // Do this last so we have the best chance of getting the time correct and
369- // all sensor names correct
370- // Writing to the SD card can be power intensive, so if we're skipping
371- // the sensor setup we'll skip this too.
372+ // Do this last so we have the best chance of getting the time correct
373+ // and all sensor names correct Writing to the SD card can be power
374+ // intensive, so if we're skipping the sensor setup we'll skip this too.
372375 if (getBatteryVoltage () > 3.4 ) {
373376 Serial.println (F (" Setting up file on SD card" ));
374377 dataLogger.turnOnSDcard (
0 commit comments