safwan092

TX Bluetooth ESP32

Mar 6th, 2025
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. //TX
  2. #include "BluetoothSerial.h"
  3.  
  4. BluetoothSerial SerialBT;
  5.  
  6. String MACadd = "EC:64:C9:91:1F:8A";///address of the Receiver ESP32
  7. uint8_t address[6] = {0xEC, 0x64, 0xC9, 0x91, 0x1F, 0x8A};///address of the Receiver ESP32 in HEX
  8. bool connected;
  9.  
  10. void setup() {
  11. Serial.begin(115200);
  12. SerialBT.begin("ESP32test", true);
  13. Serial.println("The device started in master mode, make sure remote BT device is on!");
  14.  
  15. // connect(address) is fast (upto 10 secs max), connect(name) is slow (upto 30 secs max) as it needs
  16. // to resolve name to address first, but it allows to connect to different devices with the same name.
  17. // Set CoreDebugLevel to Info to view devices bluetooth address and device names
  18. connected = SerialBT.connect(address);
  19.  
  20. if(connected) {
  21. Serial.println("Connected Succesfully!");
  22. } else {
  23. while(!SerialBT.connected(10000)) {
  24. Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
  25. }
  26. }
  27. // disconnect() may take upto 10 secs max
  28. if (SerialBT.disconnect()) {
  29. Serial.println("Disconnected Succesfully!");
  30. }
  31. // this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
  32. SerialBT.connect();
  33. }
  34.  
  35.  
  36.  
  37. void loop() {
  38. uint8_t send_data[6];
  39. send_data[0]='H';
  40. send_data[1]='E';
  41. send_data[2]='L';
  42. send_data[3]='L';
  43. send_data[4]='O';
  44. send_data[5]='.';
  45. SerialBT.write(send_data,6);//send_data, 6);
  46. delay(1000);
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment