//@@ -0,0 +1,39 @@
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

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

BluetoothSerial SerialBT;

uint8_t address[6]  = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33};
String MACadd = "AA:BB:CC:11:22:33";
//uint8_t address[6]  = {0x10, 0x52, 0x1C, 0x5D, 0x61, 0x66};
//String MACadd = "10:52:1C:5D:61:66";


//String MACadd = "9B:D3:71:F5:E9:57";   ///
String name = "OBDII";
//String name = "HC-05";


int Sekunde=0;
unsigned long previousMillis = 0;        // 
const long interval = 2000;           // Intervall (milliseconds)
unsigned long currentMillis=0;




char *pin = "1234"; //<- standard pin would be provided by default

void setup() {
  Serial.begin(115200);
  //SerialBT.setPin(pin);
  SerialBT.begin("ESP32WROOM_MINI", true); //z.Z. D1 MINI
  //SerialBT.setPin(pin);//???
  Serial.println("The device started in master mode, make sure remote BT device is on!");
  //delay(2000);
  //Das Gerät wurde im Master-Modus gestartet, stellen Sie sicher, 
  //dass das Remote-BT-Gerät eingeschaltet ist!
  SerialBT.connect(address); 
  //SerialBT.connect(name);//???

  
}
uint8_t a =0;
void loop() {


  currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    
     SerialBT.write(a);   //jede sec
     Serial.println(a);
    a++; 
    if (a==100){a=0;}
  }

  
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}