【问题标题】:Cannot publish to reserved topic using AWS IoT SDK无法使用 AWS IoT 开发工具包发布到保留主题
【发布时间】:2017-06-17 22:37:48
【问题描述】:

我目前正在使用 javascript AWS IoT 开发工具包。改编here提供的示例,我已经能够注册我的thingShadow,并且我正在尝试在注册后发布更新。但是,当我这样做时,我收到以下错误消息:

cannot publish to reserved topic '$aws/things/<thingName>/shadow/update'

我理解“$”表示这是一个保留主题,但亚马逊的文档 (http://docs.aws.amazon.com/iot/latest/developerguide/topics.html) 此保留主题允许发布和订阅操作的状态。如果是这种情况,我不确定为什么我的发布尝试会导致错误。这个 sn-p 演示了我如何尝试在我的连接回调中发布:

shadows.register(<thingName>, {
    persistentSubscribe: true
}, () => {
    shadows.publish('$aws/things/<thingName>/shadow/update', <message>);
});

【问题讨论】:

  • 冒着提出一个荒谬问题的风险,您并没有在shadows.publish('$aws/things/&lt;thingName&gt;/shadow/update', &lt;message&gt;); 显示的文字字符串中使用字符&lt;thingName&gt;...对吗?这里有一个实际有效的事物名称吗?
  • @Michael-sqlbot 哈哈,公平的问题。是的,我目前在这些字符串中使用了有效的 thingName 和消息。

标签: javascript amazon-web-services iot


【解决方案1】:

我看到您正在使用 SDK 的 thing shadow class 发布保留主题。通过查看SDK的源码,我看到it is not possible to publish on a reserved topic使用了这种类型的客户端,因为所有对保留主题的操作都是由.register()和.update()进行的。

不过,您可以使用device class 在these reserved topics 上发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 2017-02-22
    • 2019-06-18
    相关资源
    最近更新 更多