AWS IOT compatibility

implement compatibility with Amazon Web Services IOT through an MQTT connection with certificates. (#1099)
This commit is contained in:
Florian authored and GitHub committed 2021-11-07 07:44:50 -06:00
1 parent 4b53a30af4
commit dcbce352be
22 files changed
+160 -5

No files matched your search

+6 -2
View File
@@ -142,7 +142,7 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
//MQTT Parameters definition
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
# define parameters_size 30
# define parameters_size 60
# define mqtt_topic_max_size 100
# ifdef MQTT_HTTPS_FW_UPDATE
# define mqtt_max_packet_size 2048
@@ -150,7 +150,7 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
# define mqtt_max_packet_size 1024
# endif
#else
# define parameters_size 15
# define parameters_size 30
# define mqtt_topic_max_size 50
# define mqtt_max_packet_size 128
#endif
@@ -188,6 +188,10 @@ const char* certificate PROGMEM = R"EOF("
# define MQTT_SECURE_DEFAULT false
# endif
# ifndef AWS_IOT
# define AWS_IOT false
# endif
//# define MQTT_HTTPS_FW_UPDATE //uncomment to enable updating via mqtt message.
# ifdef MQTT_HTTPS_FW_UPDATE
+10 -2
View File
@@ -161,11 +161,11 @@ void setupTLS(bool self_signed = false, uint8_t index = 0);
void callback(char* topic, byte* payload, unsigned int length);
char mqtt_user[parameters_size] = MQTT_USER; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size * 2] = MQTT_PASS; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size] = MQTT_PASS; // not compulsory only if your broker needs authentication
char mqtt_server[parameters_size] = MQTT_SERVER;
char mqtt_port[6] = MQTT_PORT;
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
char gateway_name[parameters_size * 2] = Gateway_Name;
char gateway_name[parameters_size] = Gateway_Name;
#ifdef USE_MAC_AS_GATEWAY_NAME
# undef WifiManager_ssid
# undef ota_hostname
@@ -398,7 +398,11 @@ void pubMQTT(const char* topic, const char* payload) {
void pubMQTT(const char* topic, const char* payload, bool retainFlag) {
if (client.connected()) {
Log.trace(F("[ OMG->MQTT ] topic: %s msg: %s " CR), topic, payload);
#if AWS_IOT
client.publish(topic, payload); // AWS IOT doesn't support retain flag for the moment
#else
client.publish(topic, payload, retainFlag);
#endif
} else {
Log.warning(F("Client not connected, aborting thes publication" CR));
}
@@ -507,7 +511,11 @@ void connectMQTT() {
strcat(topic, gateway_name);
strcat(topic, will_Topic);
client.setBufferSize(mqtt_max_packet_size);
#if AWS_IOT
if (client.connect(gateway_name, mqtt_user, mqtt_pass)) { // AWS doesn't support will topic for the moment
#else
if (client.connect(gateway_name, mqtt_user, mqtt_pass, topic, will_QoS, will_Retain, will_Message)) {
#endif
#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK)
if (lowpowermode < 2)
M5Display("MQTT connected", "", "");