Connecting two esp32 devices via bluetooth using micropython
Billy Kimber last edited by
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.
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)
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 "<stdin>", line 7, in <module>
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?