I want to convert a python code used to connect bluetooth device to Raspberry pi to C code. Is it possible?? Is there a way to connect a bluetooth device to raspberry pi using c programming. The code is given below:
import pygatt
from binascii import hexlify
import time
adapter = pygatt.GATTToolBackend()
def handle_data(handle, value):
"""
handle -- integer, characteristic read handle the data was received on
value -- bytearray, the data returned in the notification
"""
print("Received data: %s" % hexlify(value))
try:
adapter.start()
device = adapter.connect('AC:23:3F:AA:36:7C')
device.subscribe("7f280002-8204-f393-e0a9-e50e24dcca9e",
callback=handle_data)
# The subscription runs on a background thread. You must stop this main
# thread from exiting, otherwise you will not receive any messages, and
# the program will exit. Sleeping in a while loop like this is a simple
# solution that won't eat up unnecessary CPU, but there are many other
# ways to handle this in more complicated program. Multi-threaded
# programming is outside the scope of this README.
while True:
time.sleep(10)
finally:
adapter.stop()
Two choices that I know of: https://github.com/petzval/btferret and https://github.com/weliem/bluez_inc . In the interests of complete disclosure, btferret is my code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.