使用 DBus 和 Bluez 向蓝牙设备写入数据
Write data to Bluetooth device with DBus and Bluez
我需要使用 Python dbus 库通过 DBus 和 Bluez 将数据写入蓝牙设备。
But only know how to connect and disconnect device:
import dbus
system_bus = dbus.SystemBus()
device = system_bus.get_object('org.bluez','/org/bluez/hci0/dev_FF_FF_99_96_64_60')
object = dbus.Interface(device, dbus_interface='org.bluez.Device1')
object.Connect()
object.Disconnect()
That's method description from DFeet app:
<method name="WriteValue">
<arg name="value" type="ay" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
UPDATE: Added code which write converted bytes
import dbus
import binascii
system_bus = dbus.SystemBus()
device = system_bus.get_object('org.bluez','/org/bluez/hci0/dev_FF_FF_99_96_64_60')
object = dbus.Interface(device, dbus_interface='org.bluez.Device1')
object.Connect()
device_2 = system_bus.get_object('org.bluez','/org/bluez/hci0/dev_FF_FF_99_96_64_60/service000c/char000d')
object_2 = dbus.Interface(device_2, dbus_interface='org.bluez.GattCharacteristic1')
#bytes = dbus.ByteArray(binascii.unhexlify("025a06000000"))
bytes = binascii.unhexlify("025a06000000")
object_2.WriteValue(bytes,{})
object.Disconnect()
在使用 BtleJuice Framework 进行一些测试后可以确认这足以发送字节:
bytes = binascii.unhexlify("025a06000000")
object_2.WriteValue(bytes,{})
在这样描述的方法中:
<method name="WriteValue">
<arg name="value" type="ay" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
至少它对我有用。
我需要使用 Python dbus 库通过 DBus 和 Bluez 将数据写入蓝牙设备。
But only know how to connect and disconnect device:
import dbus
system_bus = dbus.SystemBus()
device = system_bus.get_object('org.bluez','/org/bluez/hci0/dev_FF_FF_99_96_64_60')
object = dbus.Interface(device, dbus_interface='org.bluez.Device1')
object.Connect()
object.Disconnect()
That's method description from DFeet app:
<method name="WriteValue">
<arg name="value" type="ay" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
UPDATE: Added code which write converted bytes
import dbus
import binascii
system_bus = dbus.SystemBus()
device = system_bus.get_object('org.bluez','/org/bluez/hci0/dev_FF_FF_99_96_64_60')
object = dbus.Interface(device, dbus_interface='org.bluez.Device1')
object.Connect()
device_2 = system_bus.get_object('org.bluez','/org/bluez/hci0/dev_FF_FF_99_96_64_60/service000c/char000d')
object_2 = dbus.Interface(device_2, dbus_interface='org.bluez.GattCharacteristic1')
#bytes = dbus.ByteArray(binascii.unhexlify("025a06000000"))
bytes = binascii.unhexlify("025a06000000")
object_2.WriteValue(bytes,{})
object.Disconnect()
在使用 BtleJuice Framework 进行一些测试后可以确认这足以发送字节:
bytes = binascii.unhexlify("025a06000000")
object_2.WriteValue(bytes,{})
在这样描述的方法中:
<method name="WriteValue">
<arg name="value" type="ay" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
至少它对我有用。