Added receiving the serial logs via Port2
This commit is contained in:
38
src/main.cpp
38
src/main.cpp
@@ -1,41 +1,51 @@
|
|||||||
|
/*
|
||||||
|
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 <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
/*Program to control LED (ON/OFF) from ESP32 using Serial Bluetooth
|
|
||||||
* Thanks to Neil Kolbans for his efoorts in adding the support to Arduino IDE
|
|
||||||
* Turotial on: www.circuitdigest.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino
|
#include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino
|
||||||
BluetoothSerial ESP_BT; //Object for Bluetooth
|
BluetoothSerial ESP_BT; //Object for Bluetooth
|
||||||
|
|
||||||
int incoming;
|
bool isLogging;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600); //Start Serial monitor in 9600
|
Serial.begin(9600); //Start Serial monitor in 9600
|
||||||
ESP_BT.begin("ESP32_LED_Control"); //Name of your Bluetooth Signal
|
ESP_BT.begin("ESP32_Logger"); //Name of your Bluetooth Signal
|
||||||
Serial.println("Bluetooth Device is Ready to Pair");
|
Serial.println("Bluetooth Device is Ready to Pair");
|
||||||
pinMode (LED_BUILTIN, OUTPUT);//Specify that LED pin is output
|
pinMode (LED_BUILTIN, OUTPUT);//Specify that LED pin is output
|
||||||
}
|
|
||||||
|
|
||||||
|
Serial2.begin(9600); // points to Serial port 2 (GPIO17 / GPIO16)
|
||||||
|
|
||||||
|
isLogging=false;
|
||||||
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (ESP_BT.available()) { //Check if we receive anything from Bluetooth
|
if (ESP_BT.available()) { //Check if we receive anything from Bluetooth
|
||||||
incoming = ESP_BT.read(); //Read what we recevive
|
int incoming = ESP_BT.read(); //Read what we recevive
|
||||||
Serial.print("Received:"); Serial.println(incoming);
|
Serial.print("Received:"); Serial.println(incoming);
|
||||||
if (incoming == 49) {
|
if (incoming == 49) {
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
ESP_BT.println("LED turned ON");
|
isLogging=true;
|
||||||
|
ESP_BT.println("Logging turned ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (incoming == 48) {
|
if (incoming == 48) {
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
ESP_BT.println("LED turned OFF");
|
isLogging=false;
|
||||||
|
ESP_BT.println("Logging turned OFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (incoming == 57) {
|
if (incoming == 57) {
|
||||||
ESP_BT.println("[APP] Free memory: " + String(esp_get_free_heap_size()) + " bytes");
|
ESP_BT.println("Free memory: " + String(esp_get_free_heap_size()) + " bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Serial2.available() && isLogging){
|
||||||
|
String incomingData = Serial2.readStringUntil('\n');
|
||||||
|
ESP_BT.println(incomingData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1000);
|
delay(100);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user