Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2017 11:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
python, BLE GATT client test ( central device/nanoPI)
# -*- coding: utf-8 -*-
from bluepy import btle
from bluepy.btle import BTLEException
import time
import datetime
import sys
import traceback
def get2byteUUID(sUUID):
if(len(sUUID) >= 8):
sRet= "0x"+ sUUID[4:8]
return sRet
def getGATT_char(cRead ):
for temp in cRead:
#print(temp )
ret +=temp
return ret
def mainLoop():
# connect
tPeripheral = btle.Peripheral(deviceAddr=LIGHT_MAC_ADDR)
# find-characteristic
tCharList = tPeripheral.getCharacteristics()
iLen = len(tCharList)
# print(iLen )
for tChar in tCharList:
# print tChar
if (
sUUID=get2byteUUID( str(tChar.uuid) )
iUUID =int(sUUID ,16 )
if(iUUID== mCHAR_UUID ):
print "#uuid="+ str(tChar.uuid )
cRead =
print("rdLen=" + str(len(cRead )))
sRead = getGATT_char(cRead )
print("sRead="+ sRead)
if __name__ == '__main__':
from datetime import datetime
while True:
sTime ="%Y-%m-%d %H:%M:%S")
print("time=" +sTime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment