AWS MQTT从AWS lAMBDA发布到设备

问题描述 投票:0回答:1

我正在尝试从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个回答
0
投票

[我有发布数据的解决方案,但是遇到了另一个问题,发布方法仅发布到另一个主题,但是我希望它发布到设备上。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.