python - AWS MQTT 从 AWS Lambda 发布到设备
问题描述
我正在尝试从 DynamoDB 中的数据点亮连接到设备的 LED。问题是我能够连接并向主题发出订阅请求,但没有收到任何数据。
- 我编写了一个 lambda 函数来从数据库中获取数据。
- 创建规则(主题)并附加 lambda 函数
- 在订阅政策中包含主题
- 使用 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 - 在 pyspark 或 pysql 中删除包含特殊字符(如“/”)的行
- java - 将 Spring xml 配置转换为 java
- performance - 改进 Nuxt TTFB
- c# - 转换为 OrganizationServiceContext 时出现 InvalidCastException
- parallel-processing - 在多 GPU 机器上使用 pytorch 进行并行超参数优化
- android - 如何根据recyclerview的内容自动更改android中的列数?
- javascript - 如何使用 Thymeleaf th:if 在没有 onclick 的情况下调用 javascript 函数?
- flutter - Flutter Firebase 存储期货问题
- python - setup.py - 如何将子文件夹设置为主包目录?
- python - Spark:如何在纱线上成功导入python文件