Cannot MQTT connect Tasmota to AWS IOT

699 Views Asked by At

In user_config_override.h: #define USE_MQTT_AWS_IOT_LIGHT

  • compile it + flash OTA minimal + flash new compiled firmware

Always get this error:

03:53:25 MQT: Connect failed to dq5l0h2crqi8-ats.iot.eu-west-1.amazonaws.com:443, rc -4. Retry in 100 sec

I tried to use 1883 and port 8883 instead of 443. I double checked my login/password from AWS CloudFormation (used TasmotaAuth template), no luck.

Anyone successfully connected to AWS ?

2

There are 2 best solutions below

0
On

I thought defining only this was enough for login/password auth:

#define USE_MQTT_AWS_IOT_LIGHT

While I needed this whole:

#ifndef USE_MQTT_TLS
#define USE_MQTT_TLS
#define USE_MQTT_TLS_CA_CERT // Optional but highly recommended
#endif
#ifndef USE_MQTT_AWS_IOT_LIGHT
#define USE_MQTT_AWS_IOT_LIGHT
#endif
#ifdef USE_DISCOVERY
#undef USE_DISCOVERY
#endif

(in user_config_ovverride.h)

0
On

I got similar error, and Tasmota could never connect to AWS. Everybody was referring to this page: https://github.com/arendst/Sonoff-Tasmota/wiki/AWS-IoT But there is no such page. The URL had moved to its new location: https://tasmota.github.io/docs/AWS-IoT/

Finally I found that the CloudFormation yaml was incomplete. The AWS console generated TasmotaAuth/Outputs/BackLogCommand was:

BackLog MqttHost xxxxx-ats.iot.us-east-2.amazonaws.com; MqttPort 443; MqttUser tasmota?x-amz-customauthorizer-name=TasmotaAuth; MqttPassword xxxxxxx

It should have included the following to additional options:

SetOption3 1; SetOption103 1; 

Probably these were there in an earlier version, but are now missing, as of August 2021.

SetOption103 defaults to false, so my TLS was disabled:

#define MQTT_TLS_ENABLED       false      // [SetOption103] Enable TLS mode (requires TLS version)

When I manually issued the command

SetOption103 1

on the Tasmota web console, messages started flowing to AWS.

Either the CloudFormation script need to be changed, or the documentation should be corrected as follows:

Add the following to user_config_override.h:

#ifndef USE_MQTT_TLS
#define USE_MQTT_TLS
#define USE_MQTT_TLS_CA_CERT // Optional but highly recommended
#endif
#ifndef USE_MQTT_AWS_IOT_LIGHT
#define USE_MQTT_AWS_IOT_LIGHT
#endif
#ifdef  USE_DISCOVERY
#undef  USE_DISCOVERY
#endif
#undef  MQTT_TLS_ENABLED
#define MQTT_TLS_ENABLED    true