Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TX
- #include "BluetoothSerial.h"
- BluetoothSerial SerialBT;
- String MACadd = "EC:64:C9:91:1F:8A";///address of the Receiver ESP32
- uint8_t address[6] = {0xEC, 0x64, 0xC9, 0x91, 0x1F, 0x8A};///address of the Receiver ESP32 in HEX
- bool connected;
- void setup() {
- Serial.begin(115200);
- SerialBT.begin("ESP32test", true);
- Serial.println("The device started in master mode, make sure remote BT device is on!");
- // connect(address) is fast (upto 10 secs max), connect(name) is slow (upto 30 secs max) as it needs
- // to resolve name to address first, but it allows to connect to different devices with the same name.
- // Set CoreDebugLevel to Info to view devices bluetooth address and device names
- connected = SerialBT.connect(address);
- if(connected) {
- Serial.println("Connected Succesfully!");
- } else {
- while(!SerialBT.connected(10000)) {
- Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
- }
- }
- // disconnect() may take upto 10 secs max
- if (SerialBT.disconnect()) {
- Serial.println("Disconnected Succesfully!");
- }
- // this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
- SerialBT.connect();
- }
- void loop() {
- uint8_t send_data[6];
- send_data[0]='H';
- send_data[1]='E';
- send_data[2]='L';
- send_data[3]='L';
- send_data[4]='O';
- send_data[5]='.';
- SerialBT.write(send_data,6);//send_data, 6);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment