gpt4 book ai didi

mqtt - ESP32 - 使用 MicroPython 的 MQTT 到 AWS IoT

转载 作者:行者123 更新时间:2023-12-04 03:41:28 25 4
gpt4 key购买 nike

我已在 AWS IoT 上将我的 ESP32 注册为一个事物,并下载了其各自的证书以及公钥和私钥。还通过我终端中的以下命令验证了这些连接是否正确:

openssl s_client -connect host.iot.region.amazonaws.com:8443 -CAfile AmazonRootCA1.pem -cert certificate.pem.crt -key private.pem.key
这是我使用 MicroPython 连接到 AWS IoT 的(main.py)简单代码
import machine
from network import WLAN
import network
from umqtt.simple import MQTTClient

# AWS endpoint parameters.
HOST = b'HOST' # ex: b'abcdefg1234567'
REGION = b'REGION' # ex: b'us-east-1'

CLIENT_ID = "CLIENT_ID" # Should be unique for each device connected.
AWS_ENDPOINT = b'%s.iot.%s.amazonaws.com' % (HOST, REGION)

keyfile = '/certs/private.pem.key'
with open(keyfile, 'r') as f:
key = f.read()

certfile = "/certs/certificate.pem.crt"
with open(certfile, 'r') as f:
cert = f.read()

# SSL certificates.
SSL_PARAMS = {'key': key,'cert': cert, 'server_side': False}


# Setup WiFi connection.
wlan = network.WLAN( network.STA_IF )
wlan.active( True )
wlan.connect( "SSID", "PASSWORD" )

while not wlan.isconnected():
machine.idle()

# Connect to MQTT broker.
mqtt = MQTTClient( CLIENT_ID, AWS_ENDPOINT, port = 8883, keepalive = 10000, ssl = True, ssl_params = SSL_PARAMS )
mqtt.connect()
# Publish a test MQTT message.
mqtt.publish( topic = 'test', msg = 'hello world', qos = 0 )
但是当我尝试连接时出现此错误:
(-17168, 'MBEDTLS_ERR_RSA_PRIVATE_FAILED+MBEDTLS_ERR_MPI_ALLOC_FAILED')

最佳答案

经过一番努力,我得到了这个工作。我不得不使用 idf3 MicroPython 二进制文件,

esp32-idf3-20191220-v1.12.bin
v1.12 之后的 idf4 二进制文件和 idf3 不起作用。存在堆不足和内存分配问题。
- - - - - - 编辑 - - - - - -
新闻更新!基于 idf4 的新版 MicroPython v1.15 与适用于 IoT 的 AWS MQTT 配合使用。

关于mqtt - ESP32 - 使用 MicroPython 的 MQTT 到 AWS IoT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65960193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com