I wanted to use bluetooth in Python to comunicate with my robot, so I looked online for some tutorials. I've found some examples using socket module which I've used before. So I tried to use it, but I'm getting this error AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'
. I've checked the official python documentation https://docs.python.org/3/library/socket.html and there it is. I'm using Windows10 and Python3.6.4
complete code:
import socket
hostMACAddress = 'adress'
port = 3
backlog = 1
size = 1024
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
s.bind((hostMACAddress,port))
s.listen(backlog)
try:
client, address = s.accept()
while 1:
data = client.recv(size)
if data:
print(data)
client.send(data)
except:
print("Closing socket")
client.close()
s.close()