/* This is to route the serial logs from a device to serial bluetooth for convenient monitoring. Doit DevKitV1 - Connect Serial port 2 (GPIO17/GPIO16) to the device you want to monitor. On the phone, connect to the ESP32_Logger and use the "Serial Bluetooth Terminal" app to show the logs. */ #include #include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino BluetoothSerial ESP_BT; //Object for Bluetooth bool isLogging; void setup() { Serial.begin(9600); //Start Serial monitor in 9600 ESP_BT.begin("ESP32_Logger"); //Name of your Bluetooth Signal Serial.println("Bluetooth Device is Ready to Pair"); pinMode (LED_BUILTIN, OUTPUT);//Specify that LED pin is output Serial2.begin(9600); // points to Serial port 2 (GPIO17 / GPIO16) isLogging=false; } void loop() { if (ESP_BT.available()) { //Check if we receive anything from Bluetooth int incoming = ESP_BT.read(); //Read what we recevive Serial.print("Received:"); Serial.println(incoming); if (incoming == 49) { digitalWrite(LED_BUILTIN, HIGH); isLogging=true; ESP_BT.println("Logging turned ON"); } if (incoming == 48) { digitalWrite(LED_BUILTIN, LOW); isLogging=false; ESP_BT.println("Logging turned OFF"); } if (incoming == 57) { ESP_BT.println("Free memory: " + String(esp_get_free_heap_size()) + " bytes"); } } // Receive from Remote and send to Bluetooth if(Serial2.available() && isLogging){ ESP_BT.println(Serial2.readStringUntil('\n')); } delay(100); }