I've been working on connecting my ESP8266 to AWS IoT over SSL. I've managed to overcome all the obstacles related to certificates and my code 'works'. The only issue is that the initial connection initialization takes about 30 seconds. As my use case is to send a single measurement to the broker, go to deep sleep, and send it again, the MQTT connection is re-established every time.
I tested the same solution against a local mosquitto, without SSL and it works like a charm. (Un)fortunately, AWS only allows TLS connections.
My code is very simple:
Code: Select all
from umqtt.simple import MQTTClient
# Read cert and private key files
certificate = ...
private_key = ...
mqtt_client = MQTTClient(
client_id=mqtt_client_id,
server=mqtt_host,
port=8883,
ssl=True,
ssl_params={
"cert": certificate,
"key": private_key
}
)
print('Connecting to AWS IoT Core...')
mqtt_client.connect()
client.publish('foo', 'bar', qos=1)
Does anyone have suggestions on how to improve this?