【问题标题】:ESP32 - MQTT to AWS IoT using MicroPythonESP32 - MQTT 到 AWS IoT 使用 MicroPython
【发布时间】:2021-05-03 17:03:12
【问题描述】:

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

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')

【问题讨论】:

  • 你让它工作了吗?我也面临同样的问题,但无法找到解决方案。

标签: mqtt esp32 aws-iot micropython


【解决方案1】:

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

esp32-idf3-20191220-v1.12.bin

idf4 二进制文件和高于 v1.12 的 idf3 不起作用。存在堆不足和内存分配问题。

----------- 编辑 -----------

新闻更新!基于 idf4 的 MicroPython 新 v1.15 版本可与 AWS MQTT for IoT 配合使用。

【讨论】:

    猜你喜欢
    • 2022-07-29
    • 2022-06-12
    • 1970-01-01
    • 1970-01-01
    • 2022-11-09
    • 2018-06-14
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    相关资源
    最近更新 更多