Typescript 下一步,尝试为dbus中的Bluez LEAdvertisement1接口创建对象
我对DBUS和BlueZ很陌生。我一直在遵循几条指南,直到需要创建LEAdvertisement1接口并向LEAdvertisingManager1注册为止 我一直在阅读LEAdvertisement1的BlueZ文档:Typescript 下一步,尝试为dbus中的Bluez LEAdvertisement1接口创建对象,typescript,raspberry-pi,bluetooth-lowenergy,dbus,bluez,Typescript,Raspberry Pi,Bluetooth Lowenergy,Dbus,Bluez,我对DBUS和BlueZ很陌生。我一直在遵循几条指南,直到需要创建LEAdvertisement1接口并向LEAdvertisingManager1注册为止 我一直在阅读LEAdvertisement1的BlueZ文档: Service org.bluez Interface org.bluez.LEAdvertisement1 Object path freely definable 我不确定自由定义的对象路径是什么意思。我试图遵循BlueZ示例(使用dbusnext而不是pyt
Service org.bluez
Interface org.bluez.LEAdvertisement1
Object path freely definable
我不确定自由定义的对象路径是什么意思。我试图遵循BlueZ示例(使用dbusnext而不是python),但在运行registeradvisement时,我一直遇到错误“org.BlueZ.error.Failed”。该错误没有提供任何有用的信息,因此为了排除故障,我运行了dbus监视器
sudo dbus-monitor --system "destination='org.bluez'" "sender='org.bluez'"
在监视器内,我收到以下错误:
method call time=1622421524.320548 sender=:1.18 -> destination=org.freedesktop.DBus serial=71 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
string "type='signal',sender=':1.37',path='/org/bluez/example/advertisement0',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.bluez.LEAdvertisement1'"
method return time=1622421524.320650 sender=org.freedesktop.DBus -> destination=:1.18 serial=35 reply_serial=71
method call time=1622421524.322726 sender=:1.18 -> destination=org.freedesktop.DBus serial=72 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=StartServiceByName
string ":1.37"
uint32 0
error time=1622421524.322852 sender=org.freedesktop.DBus -> destination=:1.18 error_name=org.freedesktop.DBus.Error.ServiceUnknown reply_serial=72
string "The name :1.37 was not provided by any .service files"
接口类:
const LE_ADVERTISEMENT_IFACE = 'org.bluez.LEAdvertisement1';
const PATH_BASE = '/org/bluez/example/advertisement';
export class BLEAdvertisementInterface extends dbus.interface.Interface {
adType: string = "peripheral";
serviceUuids: Array<any> = [];
manufacturerData: any; //none
solicitUuids: Array<any> = []; //none
serviceData: any; //none
localName: string = "Testing";
includeTxPower: boolean = false;
data: any; //none
constructor() {
super(LE_ADVERTISEMENT_IFACE);
this.serviceUuids = [uuidv4()];
}
@method({ inSignature: "s", outSignature: "a{sv}" })
GetAll(): Variant {
console.log("This does not run due to service unknown error");
let includes = [];
if(this.includeTxPower) includes.push("tx-power");
const allProperties = {
LocalName: new Variant("s", this.localName),
ServiceUUIDs: new Variant("as", this.serviceUuids),
Includes: new Variant("as",includes),
Type: new Variant("s", this.adType)
};
return new Variant("a{sv}", allProperties);
}
@method({ inSignature: "", outSignature: "" })
Release() {
console.log("released!");
}
}
我不确定我到底错过了什么。我尝试了一些方法,比如requestName和export。以及检查system.d下的安全设置。我觉得我需要在Linux(raspbian)中进行一些配置才能使其正常工作,但我不确定在哪里。任何人能为我提供帮助,帮助我找出下一步,我将不胜感激。大多数在线指南似乎都忽略了这一步,并参考了图书馆。不幸的是,它们都是用python编写的
BlueZ文档:
BlueZ示例:
dbus下一步:
感谢要使用DBus API在BlueZ中创建广告,需要做两件事。第一个是使用接口
org.bluez.leadwertisement1
创建一个DBus服务,第二个是使用RegisterAdvertisement
告诉bluez该服务在哪里
从您在问题中发布的错误消息来看,BlueZ似乎无法找到位于/org/BlueZ/example/advertisement0
的服务
我对node js没有什么经验,但是有一个node dbus next
文档的快速浏览器,看起来您需要它
bus.export('/org/bluez/example/advertisement0', advertisement)
发布已定义的DBus服务
在命令行上,如果执行busctl列表
,即使不执行RegisterAdvertisement
的第二步,也应该能够看到新服务已出现。服务将具有唯一的名称(即:x.xxx
),而不使用请求名称。由于安全设置的原因,您将无法使用该服务,但它将证明您正在发布某些内容。
下一步是向BlueZ注册服务。在这个阶段,如果广告的格式不是BlueZ所期望的格式,您可能会看到
解析广告失败
错误。谢谢。我可以得到“未能解析广告”错误。在registerName/export之后,我能够使用busctl列表来验证我的服务是否已注册。之后我发现我需要使用@property而不是GetAll。奇怪的是,dbus监视器仍然提供一个服务未知错误,但我能够获得一个proxyObject/proxyInterface,显示它已注册属性。不管怎样,这个错误似乎并没有阻止我尝试注册(还有一些工作要做)。
bus.export('/org/bluez/example/advertisement0', advertisement)