Hi, I am writing code on RPi which connects to device having glucose service. It worked well but from few days it is unable to write to the glucose measurement characteristic and code stuck there while waiting for response from device.
!usr/bin/env python
from future import print_function
import bluepy
from bluepy import btle
from bluepy.btle import Scanner, DefaultDelegate, Peripheral
from time import sleep,time, mktime
import binascii
import datetime
import os
handleDiscovery function is called when new device is scanned
class MyDelegate_glucose(DefaultDelegate):
def init(self):
btle.DefaultDelegate.init(self)
def handleNotification(self, cHandle, data):
data = binascii.hexlify(data)
print(data)
write to glucose characteristic
def glucose_data(connected_dev):
connected_dev.withDelegate(MyDelegate_glucose())#stores the reference for connected device which receives callbacks for glucose meter
try:
connected_dev.writeCharacteristic(12,bytearray([0x01,0x00]),withResponse = True)#configure glucose measurement characteristic for notification
connected_dev.writeCharacteristic(15,bytearray([0x01,0x00]),withResponse = True)#configure glucose measurement context for notification
connected_dev.writeCharacteristic(20,bytearray([0x02,0x00]),withResponse = True)#configure record access control point for indiaction
connected_dev.writeCharacteristic(19,bytearray([0x01,0x01]),withResponse = True)#write to record access control point to request for stored records
except:
print("exception occured")
end_time = time()+30
while time()<end_time:
if connected_dev.waitForNotifications(30):
print("before calling handler")
continue
Hi, I am writing code on RPi which connects to device having glucose service. It worked well but from few days it is unable to write to the glucose measurement characteristic and code stuck there while waiting for response from device.
!usr/bin/env python
from future import print_function import bluepy from bluepy import btle from bluepy.btle import Scanner, DefaultDelegate, Peripheral from time import sleep,time, mktime import binascii import datetime import os
handleDiscovery function is called when new device is scanned
class ScanDelegate(DefaultDelegate):
class MyDelegate_glucose(DefaultDelegate): def init(self): btle.DefaultDelegate.init(self)
write to glucose characteristic
def glucose_data(connected_dev):
connected_dev.withDelegate(MyDelegate_glucose())#stores the reference for connected device which receives callbacks for glucose meter try: connected_dev.writeCharacteristic(12,bytearray([0x01,0x00]),withResponse = True)#configure glucose measurement characteristic for notification connected_dev.writeCharacteristic(15,bytearray([0x01,0x00]),withResponse = True)#configure glucose measurement context for notification connected_dev.writeCharacteristic(20,bytearray([0x02,0x00]),withResponse = True)#configure record access control point for indiaction connected_dev.writeCharacteristic(19,bytearray([0x01,0x01]),withResponse = True)#write to record access control point to request for stored records except: print("exception occured") end_time = time()+30 while time()<end_time: if connected_dev.waitForNotifications(30): print("before calling handler") continue
scanner = Scanner().withDelegate(ScanDelegate()) devices = scanner.scan(2) ADDR_TO_CONNECT =
connected_dev = Peripheral(ADDR_TO_CONNECT)
glucose_data(connected_dev)