Disable Serial Monitor Warning or Error Messages

I am working with ESP32 BLE on a board with an ESP32-C3-WROOM-02 chip, I use the card to send data from a sensor that I have connected via serial communication (TX and RX), the problem I have is that when I connect more than 1 device to the server sends an error message to the serial monitor, when sending that message it corrupts the data that I am receiving through the serial port, I want to know if I can disable these messages or I can change it so that it sends them through a simulated serial port (serial software) , I cannot connect my sensor to a simulated port since my card is specially designed to occupy the TX and RX directly, if I wanted to change them I would have to redesign my entire card. I hope you can help me.

I tried to reduce the data that I send so that it doesn't send so many notify, but it didn't solve the problem and I really don't care if I connected well, the only thing I want is for my server to send the data so that it doesn't have any device connected or has 3 connected

What is the server? The PC connected to the serial interface? Part of your code?

It might get clear if you post your code, we probably need that anyway to help you.

I guess you need esp_log_level_set() but without the code that's a rather wild guess.

The server is my ESP32, and it is connected to a sensor through the TX/RX pins,

I share my code

#include <Arduino.h>
#include "SensorWattsLib.h"
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>

SensorWatts sw; //Crea el objeto sensor watts sw

class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      BLEDevice::startAdvertising();
    };
};

BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
#define SERVICE_UUID        "c00fa1d8-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "c00fa3f4-36e1-4688-b7f5-ea07361b26a8"


void bleInit(){
  BLEDevice::init("SensorWatts 09");
  

  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  BLEService *pService = pServer->createService(SERVICE_UUID);
  pCharacteristic = pService->createCharacteristic(
                      CHARACTERISTIC_UUID,
                      BLECharacteristic::PROPERTY_NOTIFY 
                    );

  pService->start();

  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(false);
  pAdvertising->setMinPreferred(0x0);
  BLEDevice::startAdvertising();

}

void setup() {

	sw.EnerAct = 0;
	sw.EnerReact = 0;
	Serial.begin(9600);//Terminal
	sw.tiempo_transc = millis();
	

	bleInit();

}

void loop() {

unsigned long cumillis = millis();

int seg = (millis() / 1000);

if (cumillis - sw.tiempo_transc >= sw.intervalo_medicion){

	sw.ComandoMediciones();// Llama a la funcion/metodo ComandoMediciones
	pCharacteristic->setValue((String(sw.Voltrms)+","+String(sw.FrecHz)).c_str());
	pCharacteristic->notify();
	delay(20);
	pCharacteristic->setValue((sw.fac+","+sw.rlc).c_str());
	pCharacteristic->notify();
	delay(20);
	pCharacteristic->setValue((String(sw.Irms)+","+String(sw.PotAct)).c_str());
	pCharacteristic->notify();
	delay(20);
	pCharacteristic->setValue((String(sw.QReact)+","+String(sw.SAprt)).c_str());
	pCharacteristic->notify();
	delay(20);
	pCharacteristic->setValue((String(sw.EnerAct)+","+String(sw.EnerReact)).c_str());
	pCharacteristic->notify();
	delay(20);
	pCharacteristic->setValue(String(seg).c_str());
	pCharacteristic->notify();
	delay(20);
   
	sw.tiempo_transc = cumillis;

}
  
}

Important code information:

  • SensorWattsLib is a library created by me, to send a byte command to the sensor and receive data from the sensor in another byte command, and separate them according to the information that each one is, this exchange of information is done every 1 second.

  • I send the data in packages of 2 since I am going to receive this information that I sent in an android app and it does not read the entire message if I send it in a single string of characters, so I separate it into packages of 2 data, except the last one that sends itself

You mean a BLE server! That is a providing services of a slave device, so connecting more than one master is an error condition, that's probably why you get error messages in the serial monitor. You can control that by the mentioned esp_log_level_set() command but you might want to fix that anyway.

If you are trying to use the Serial monitor at the same time as the sensor and the sensor is occupying the Serial Rx an Tx pins, you may be able to map the serial headed for the monitor to some different pins and connect to the monitor using a ttl/usb converter.

No. OPs problem is that the BLE library code uses the ESP log architecture to provide feedback. Some conditions are categorized as errors and errors are printed to the Serial interface by default. By setting the log level to log nothing he can avoid the serial messages but he has to catch the side effects of the errors anyway. So setting the log level removes the symptom but doesn't solve the problem.

This link would indicate that the debug output can be directed to Serial2
https://mischianti.org/2020/09/20/esp32-manage-multiple-serial-and-logging-for-debugging-3/

Serial2.begin(9600);
Serial2.setDebugOutput(true);

Here's the code from the Arduino core for Hardware Serial

void HardwareSerial::setDebugOutput(bool en)
{
    if(_uart == 0) {
        return;
    }
    if(en) {
        uartSetDebug(_uart);
    } else {
        if(uartGetDebug() == _uart_nr) {
            uartSetDebug(NULL);
        }
    }
}

The ESP documentation for the logging library
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/log.html#logging-library

refers to the use of esp_log_set_vprintf() which can be used to redirect output.

Set function used to output log entries.

By default, log output goes to UART0. This function can be used to redirect log output to some other destination, such as file or network. Returns the original log handler, which may be necessary to return output to the previous destination.

Thanks for the answers,
I tried disabling the warnings with esp_log_level_set(), and if it works it allows me to connect up to 4 devices simultaneously, but when I connect 5 it doesn't let me and I lose the measured data again.

Now I am going to deal with the Nimble library, since I have another sensor that uses that library with the esp32 and in the sensor app if more than 5 devices can be connected.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.