I am using PyBluez 0.22 to send data from ESP32 to Python via Bluetooth. So far I have been receiving the data but it is not in the form it. Here is my code
from bluetooth import *
import sys
def input_and_send():
print("\nType something\n")
while True:
data = input()
if len(data) == 0: break
sock.send(data)
sock.send("\n")
def rx_and_echo():
sock.send("\nsend anything\n")
while True:
data = sock.recv(buf_size)
if data:
print(data)
sock.send(data)
addr = "08:3A:F2:52:1F:86"
service_matches = find_service( address = addr )
buf_size = 1024
if len(service_matches) == 0:
print("couldn't find the SampleServer service =(")
sys.exit(0)
for s in range(len(service_matches)):
print("\nservice_matches: [" + str(s) + "]:")
print(service_matches[s])
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
port=1
print("connecting to \"%s\" on %s, port %s" % (name, host, port))
sock=BluetoothSocket(RFCOMM)
sock.connect((host, port))
print("connected")
# input_and_send()
rx_and_echo()
sock.close()
print("\n--- bye ---\n")
If I send three digit number, each digit gets printed in a separate line. For example, If I send "365", the output is
b'3'
b'65\r\n'
I have tried with changing the values of buffer size but it is not helpful. Please guide me how to make it right.