Skip to content

Commit f900dd2

Browse files
committed
Replace usage of Serial.print() with ESP_LOGI()
There is a potential bug with the Arduino serial library in combination with tickless sleep, i.e. automatic light sleep mode. see: espressif/arduino-esp32#8122
1 parent e550309 commit f900dd2

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

eloc610LowPowerPartition/src/main.cpp

+27-28
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ void wait_for_button_push()
324324
//Battery::GetInstance().getVoltage();
325325
boolean sentElocStatus=false;
326326
int loopcounter=0;
327-
Serial.println( "waiting for button or bluetooth");
328-
Serial.println( "voltage is "+String(Battery::GetInstance().getVoltage()));
327+
ESP_LOGI(TAG, "waiting for button or bluetooth");
328+
ESP_LOGI(TAG, "voltage is %.3f", Battery::GetInstance().getVoltage());
329329

330330

331331
int64_t timein= getSystemTimeMS();
@@ -335,17 +335,17 @@ void wait_for_button_push()
335335
int leddelay;
336336
String serialIN;
337337

338-
Serial.println(" two following are heap size, total and max alloc ");
339-
Serial.println(ESP.getFreeHeap());
340-
Serial.println(ESP.getMaxAllocHeap());
338+
ESP_LOGI(TAG, " two following are heap size, total and max alloc ");
339+
ESP_LOGI(TAG, " %u", ESP.getFreeHeap());
340+
ESP_LOGI(TAG, " %u", ESP.getMaxAllocHeap());
341341
//mountSDCard();
342342
//freeSpace();
343343

344344
while (!gotrecord)
345345
{
346346
//Battery::GetInstance().getVoltage();
347347
//gotrecord=false;
348-
//Serial.println( "waiting for buttonpress");
348+
//ESP_LOGI(TAG, "waiting for buttonpress");
349349
//btwrite("Waiting for record button");
350350
if (SerialBT.connected()) {
351351
if (!gSentSettings) {
@@ -380,7 +380,7 @@ void wait_for_button_push()
380380
if (SerialBT.available()) {
381381
// handle case for sending initial default setup to app
382382
serialIN=SerialBT.readString();
383-
//Serial.println(serialIN);
383+
//ESP_LOGI(TAG, serialIN);
384384
//if (serialIN.startsWith("settingsRequest")) {
385385
// btwrite("#"+String(gSampleRate)+"#"+String(gSecondsPerFile)+"#"+gLocation);
386386
//}
@@ -392,7 +392,7 @@ void wait_for_button_push()
392392
}
393393

394394
if (serialIN.startsWith( "_setClk_")) {
395-
Serial.println("setClk starting");
395+
ESP_LOGI(TAG, "setClk starting");
396396
//string will look like _setClk_G__120____32456732728 //if google, 12 mins since last phone sync
397397
// or _setClk_P__0____43267832648 //if phone, 0 min since last phone sync
398398

@@ -401,15 +401,16 @@ void wait_for_button_push()
401401
everything.trim();
402402
String seconds = everything.substring(0,10); //was 18
403403
String milliseconds=everything.substring(10,everything.length());
404-
Serial.println("timestamp in from android GMT "+everything +" sec: "+seconds + " millisec: "+milliseconds);
404+
String tmp = "timestamp in from android GMT "+everything +" sec: "+seconds + " millisec: "+milliseconds;
405+
ESP_LOGI(TAG, "%s", tmp.c_str());
405406
String minutesSinceSync=serialIN.substring(11,serialIN.indexOf("___"));
406407
gSyncPhoneOrGoogle=serialIN.substring(8,9);
407-
//Serial.println(minutesSinceSync);
408-
// Serial.println("GorP: "+GorP);
408+
//ESP_LOGI(TAG, minutesSinceSync);
409+
// ESP_LOGI(TAG, "GorP: "+GorP);
409410
//delay(8000);
410-
// Serial.println(test);
411-
//Serial.println(seconds);
412-
//Serial.println(milliseconds);
411+
// ESP_LOGI(TAG, test);
412+
//ESP_LOGI(TAG, seconds);
413+
//ESP_LOGI(TAG, milliseconds);
413414
milliseconds.trim();
414415
if (milliseconds.length()<2) milliseconds="0";
415416
timeObject.setTime(atol(seconds.c_str())+(TIMEZONE_OFFSET*60L*60L), (atol(milliseconds.c_str()))*1000 );
@@ -424,10 +425,10 @@ void wait_for_button_push()
424425
int64_t time_us = ( (int64_t)tv_now.tv_sec * 1000000L) + (int64_t)tv_now.tv_usec;
425426
time_us=time_us/1000;
426427

427-
//Serial.println("atol(minutesSinceSync.c_str()) *60L*1000L "+String(atol(minutesSinceSync.c_str()) *60L*1000L));
428+
//ESP_LOGI(TAG, "atol(minutesSinceSync.c_str()) *60L*1000L "+String(atol(minutesSinceSync.c_str()) *60L*1000L));
428429
gLastSystemTimeUpdate=getTimeFromTimeObjectMS() -( atol(minutesSinceSync.c_str()) *60L*1000L);
429430
timein= getSystemTimeMS();
430-
//Serial.println("timestamp in from android GMT "+everything +" sec: "+seconds + " millisec: "+milliseconds);
431+
//ESP_LOGI(TAG, "timestamp in from android GMT "+everything +" sec: "+seconds + " millisec: "+milliseconds);
431432
//ESP_LOGI("d", "new timestamp from new sys time (local time) %lld", time_us ); //this is 7 hours too slow!
432433
//ESP_LOGI("d","new timestamp from timeobJect (local time) %lld",gLastSystemTimeUpdate);
433434

@@ -438,7 +439,7 @@ void wait_for_button_push()
438439
sentElocStatus=true;
439440
sendElocStatus();
440441
}
441-
Serial.println("setClk ending");
442+
ESP_LOGI(TAG, "setClk ending");
442443
}
443444

444445

@@ -450,7 +451,7 @@ void wait_for_button_push()
450451
gLocationCode.trim();
451452
gLocationAccuracy= serialIN.substring(serialIN.indexOf("#")+1,serialIN.length() );
452453
gLocationAccuracy.trim();
453-
Serial.println("loc: "+gLocationCode+" acc "+gLocationAccuracy);
454+
ESP_LOGI(TAG, "loc: %s acc %s", gLocationCode.c_str(), gLocationAccuracy.c_str());
454455

455456
File file = SPIFFS.open("/gps.txt", FILE_WRITE);
456457
file.println(gLocationCode);
@@ -885,10 +886,10 @@ bool folderExists(const char* folder)
885886
struct stat sb;
886887

887888
if (stat(folder, &sb) == 0 && S_ISDIR(sb.st_mode)) {
888-
Serial.println("yes");
889+
ESP_LOGI(TAG, "yes");
889890
return true;
890891
} else {
891-
Serial.println("no");
892+
ESP_LOGI(TAG, "no");
892893
return false;
893894
}
894895
return false;
@@ -901,7 +902,7 @@ String readNodeName() {
901902
// if (a==2) {a=1;}
902903
if(!(SPIFFS.exists("/nodename.txt"))){
903904

904-
Serial.println("No nodename set. Returning ELOC_NONAME");
905+
ESP_LOGI(TAG, "No nodename set. Returning ELOC_NONAME");
905906
return("ELOC_NONAME");
906907

907908

@@ -915,7 +916,7 @@ String readNodeName() {
915916
String temp = file2.readString();
916917
temp.trim();
917918
file2.close();
918-
Serial.println("node name: "+temp);
919+
ESP_LOGI(TAG, "node name: %s", temp.c_str());
919920
return(temp);
920921
//return("");
921922

@@ -1100,9 +1101,8 @@ void app_main(void)
11001101
ESP_LOGI(TAG, "\n\n---------VERSION %s\n\n", VERSIONTAG);
11011102
initArduino();
11021103
ESP_LOGI(TAG, "initArduino done");
1103-
Serial.begin(115200);
11041104

1105-
Serial.println("\nSETUP--start\n");
1105+
ESP_LOGI(TAG, "\nSETUP--start\n");
11061106

11071107
changeBootPartition(); // so if reboots, always boot into the bluetooth partition
11081108

@@ -1185,7 +1185,7 @@ printMemory();
11851185

11861186

11871187
if(!SPIFFS.begin(true, "/spiffs")){
1188-
Serial.println("An Error has occurred while mounting SPIFFS");
1188+
ESP_LOGI(TAG, "An Error has occurred while mounting SPIFFS");
11891189
//return;
11901190
}
11911191
delay(50);
@@ -1194,9 +1194,9 @@ delay(50);
11941194
SerialBT.begin(readNodeName(),false);
11951195
delay(100);
11961196
if (SerialBT.isReady()) {
1197-
Serial.println("SerialBT is ready ------------------------------------------------------ ");
1197+
ESP_LOGI(TAG, "SerialBT is ready ------------------------------------------------------ ");
11981198
} else {
1199-
Serial.println("SerialBT is NOT ready --------------------------------------------------- ");
1199+
ESP_LOGI(TAG, "SerialBT is NOT ready --------------------------------------------------- ");
12001200
}
12011201

12021202

@@ -1236,7 +1236,6 @@ ESP_ERROR_CHECK(gpio_isr_handler_add(GPIO_BUTTON, buttonISR, (void *)OTHER_GPIO_
12361236
.min_freq_mhz = gMinFrequencyMHZ,
12371237
.light_sleep_enable = gEnableLightSleep
12381238
};
1239-
Serial.flush();
12401239
esp_pm_configure(&cfg);
12411240

12421241

0 commit comments

Comments
 (0)