代码之家  ›  专栏  ›  技术社区  ›  Burner

通过bluepy和Sensirion Smartgadget使用通知

  •  1
  • Burner  · 技术社区  · 6 年前

    我正在尝试在Sensirion Smartgadget上使用温度更新通知。到目前为止,一切正常:通过轮询连接、读取数据。

    我不知道如何在Sensirion Smartgadget上启用通知。我必须向哪个特征发送什么?

    我找到的唯一文件是 this 第10页。

    从现在起,我尝试了以下不起作用的方法:

    from bluepy import btle
    from bluepy.btle import Peripheral
    
    class MyDelegate(btle.DefaultDelegate):
        def __init__(self):
            btle.DefaultDelegate.__init__(self)
    
        def handleNotification(self, cHandle, data):
            print('notification arrived')
    
    
    p = Peripheral(myAddress, "random")
    p.setDelegate( MyDelegate() )
    
    svc = p.getServiceByUUID( "00002234-b38d-4985-720e-0f993a68ee41" )
    ch = svc.getCharacteristics( "00002235-b38d-4985-720e-0f993a68ee41" )[0]
    
    ch.write((1).to_bytes(1, byteorder='little'))
    ch.write((1).to_bytes(2, byteorder='big'))
    ch.write((1).to_bytes(2, byteorder='little'))
    ch.write((2).to_bytes(1, byteorder='big'))
    ch.write((2).to_bytes(1, byteorder='little'))
    ch.write((2).to_bytes(2, byteorder='big'))
    ch.write((2).to_bytes(2, byteorder='little'))
    
    while True:
        if p.waitForNotifications(1.0):
            continue
    
        print("Waiting...")
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Marcello B.    5 年前

    重新开始调查问题,并找到了一个暴力解决方案,我当时没有看到。。。

    迭代了 getCharacteristics 并写道 0x01 对他们来说。事实证明,我需要向第三个特征写入值以打开通知。

    我在GitHub上为Sensirion启动了一个API,可以找到 here .