如何在订阅代码 mqtt 中打印发布者属性?

How to print publisher attributes in subscription code mqtt?

我在 raspberry pi 上有我的订阅代码 运行。因为它连接到多个发布者,所以我想打印出发布者属性,比如它的名称 ID。我怎样才能做到这一点?

你不能。

订阅者对发布者一无所知,只知道发布消息的主题。

如前所述,订阅者对发布者一无所知。但是,可以使用以下方式打印主题:

def on_message(mosq, obj, msg):
  print strftime("%Y-%m-%d %H:%M:%S", localtime())+ " "+msg.topic+" " +str(msg.payload)