【问题标题】:AWS MQTT Publish from AWS lAMBDA to deviceAWS MQTT 从 AWS Lambda 发布到设备
【发布时间】:2019-12-11 06:54:40
【问题描述】:

我正在尝试根据 DynamoDB 中的数据点亮连接到设备的 LED。问题是我能够连接并向主题发出订阅请求,但没有收到任何数据。

  1. 我编写了一个 lambda 函数来从数据库中获取数据。
  2. 创建规则(主题)并附加 lambda 函数
  3. 在订阅策略中包含主题
  4. 使用 AWSIoTPythonSDK,我使用证书在设备中创建了一个客户端
// Code works 
// I have given only the part of code from lambda function
// It fetches data from DB
import json
import boto3

def get_multiple_items():
    return table.scan()


def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'payload': json.dumps(get_multiple_items()),
        'event':event
    }

// Code from Device
def customCallback(client, userdata, message):
    print("Received a new message: ")
    print(message.payload)
    print("from topic: ")
    print(message.topic)
    print("--------------\n\n")


print("Subscribing Data")

// It is not calling the customCallback function
myClient.subscribe(topic,1,customCallback)
print("Subscribed Data")



【问题讨论】:

    标签: python amazon-web-services mqtt aws-iot


    【解决方案1】:

    伙计们,我有发布数据的解决方案,但遇到了另一个问题,发布方法只发布到另一个主题,但我希望它发布到设备。

    【讨论】:

      【解决方案2】:

      建议在 .subscribe(..) 调用之后包含 time.sleep(0.005) 或一些短暂的延迟。

      您能否在此处分享控制台日志输出,以便更好地了解您的问题?

      干杯,
      内存

      【讨论】:

        猜你喜欢
        • 2021-02-26
        • 1970-01-01
        • 2017-02-22
        • 1970-01-01
        • 2022-06-12
        • 2018-03-25
        • 2019-08-31
        • 2017-06-26
        • 2015-11-16
        相关资源
        最近更新 更多