println

Hello People

I need to print the message of button pressed to my android via bluetooth and im using esp32. so this is the program im using it in arduino. this works fine, but im doing the same in C(eclipse and esp-idf) (my boss said to do so). So I have this one SerialBT object as declaration for bluetooth serial and im curious which function (SerialBT.println("BUTTON 2 ON!"); <<<< ) println calls from the available functions of bluetooth serial such as begin,write, read , etc

#include <BluetoothSerial.h>

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetoot2h is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;
// LED PIN PUSH BUTTON

int ledPin = 18; // choose the pin for the LED
int ledPin2 = 23;
int inPin = 21;   // choose the input pin (for a pushbutton)
int inpin2 = 4;  
int val = 0;     // variable for reading the pin status
int val2 = 0;

void setup() {
  Serial.begin(9600);
  SerialBT.begin("ESP32TEST"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(ledPin2, OUTPUT);
  pinMode(inPin, INPUT);    // declare pushbutton as input
  pinMode(inpin2, INPUT);
}

void loop(){
  val=digitalRead(inPin);
  val2=digitalRead(inpin2);
  Serial.print("inpin status");  Serial.println(val); Serial.println(val2);
  if (val == 1) // check if the input is HIGH (button pressed) 
  {         
    digitalWrite(ledPin, HIGH);  
    SerialBT.println("BUTTON 1 ON!");
    delay(10);
  } 
  else
  {
    digitalWrite(ledPin, LOW);  
    SerialBT.println("BUTTON 1 OFF!");
    delay(10);
  }  
  if (val2 == 1)// check if the input is HIGH (button pressed) 
  {         
    digitalWrite(ledPin2, HIGH);  
    SerialBT.println("BUTTON 2 ON!");   <<<< im curious how this function is called
    delay(10);
  } 
  else
  {
    digitalWrite(ledPin2, LOW);  
    SerialBT.println("BUTTON 2 OFF!");
    delay(10);
  }val=0;val2=0;
}

Thank you

GeorgeCarlo:
so this is the program im using it in arduino. this works fine, but im doing the same in C(eclipse and esp-idf) (my boss said to do so)

That sounds like a huge downgrade, IMHO.

This is an Arduino forum, so you might not get help with ESP-idf.

In C, networking/Bluetooth is usually much harder because there are virtually no abstractions.

In C++, you can just create a BluetoothSerial object that hides all implementation from you, and you just use it as a black box to send and receive data.
Someone already did all the hard work for you. Reinventing the wheel and writing another Bluetooth library is just a waste of time.
(If you're interested in learning how it works under the hood, and if your boss pays you for it, you should do it, of course.)

Unless your boss has a very good reason to use C only, I would try to convince him that using C++ is going to reduce the development time and maintenance cost by a great amount.

If you feel limited by the Arduino environment, you can always try PlatformIO.

If you want to know how the println function works, just look up the source code of the ESP32 Arduino core libraries.

Pieter

The BluetoothSerial class inherits from the Stream class:

class BluetoothSerial: public Stream

The Stream class inherits from the Print class:

class Stream: public Print

The Print class is where the println functions are defined:

The Print class is really cool! All the BluetoothSerial library had to do is define a write function. The Print class uses that to allow you to print any standard data type.