Files
PlatformIO_ESP32_BluetoothS…/src/main.cpp

51 lines
1.6 KiB
C++
Raw Normal View History

/*
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.
*/
2023-11-10 18:15:57 -06:00
#include <Arduino.h>
#include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino
BluetoothSerial ESP_BT; //Object for Bluetooth
bool isLogging;
2023-11-10 18:15:57 -06:00
void setup() {
Serial.begin(9600); //Start Serial monitor in 9600
ESP_BT.begin("ESP32_Logger"); //Name of your Bluetooth Signal
2023-11-10 18:15:57 -06:00
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;
}
2023-11-10 18:15:57 -06:00
void loop() {
if (ESP_BT.available()) { //Check if we receive anything from Bluetooth
int incoming = ESP_BT.read(); //Read what we recevive
2023-11-10 18:15:57 -06:00
Serial.print("Received:"); Serial.println(incoming);
if (incoming == 49) {
digitalWrite(LED_BUILTIN, HIGH);
isLogging=true;
ESP_BT.println("Logging turned ON");
2023-11-10 18:15:57 -06:00
}
if (incoming == 48) {
digitalWrite(LED_BUILTIN, LOW);
isLogging=false;
ESP_BT.println("Logging turned OFF");
2023-11-10 18:15:57 -06:00
}
if (incoming == 57) {
ESP_BT.println("Free memory: " + String(esp_get_free_heap_size()) + " bytes");
2023-11-10 18:15:57 -06:00
}
if(Serial2.available() && isLogging){
String incomingData = Serial2.readStringUntil('\n');
ESP_BT.println(incomingData);
}
2023-11-10 18:15:57 -06:00
}
delay(100);
2023-11-10 18:15:57 -06:00
}