Connecting two esp32 devices via bluetooth

I want to transfer joystick data from one esp32 to another, so that I can make a remote controlled car. I’m having trouble connecting the two esp32 devices. I asked chatGPT and it gave me many codes using the bluetooth module and the BluetoothSocket class, but it seems like the BluetoothSocket class ins’t in the bluetooth module.
import bluetooth

This is the code:

Set the MAC address of the other ESP32 device

other_device_mac = “yy:yy:yy:yy:yy:yy”

Create a Bluetooth socket and listen for incoming connections

sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.bind((other_device_mac, 1))

Wait for a connection from the other device

print(“Waiting for connection…”)
client_sock, client_info = sock.accept()
print(“Accepted connection from”, client_info)

Receive data from the other device

data = client_sock.recv(1024)
print(“Received data:”, data.decode())

Close the client socket and the Bluetooth socket


I get this error:

Traceback (most recent call last):
File “”, line 7, in
AttributeError: ‘module’ object has no attribute ‘BluetoothSocket’

Does anyone have any suggestions to help connect the two esp32a via bluetooth, so that data transfer is possible?

I think you could get more useful information on micropython forum. :slight_smile:

esp32 ble functions are limited on micropython v1.19 (no l2cap, pair/bonding)

there are examples on github micropython/examples/bluetooth at master · micropython/micropython · GitHub

(The esp32 port now uses synchronous BLE events which allows support for BLE pairing and bonding… in v1.20 release note)