diff --git a/docs/c-api/mqtt.h/intro.md b/docs/c-api/mqtt.h/intro.md
index 7c52013465a973f0e7e2b1f71fdc7dc64a36dd00..5ae849aa34821e14e1d74073b164380149594c87 100644
--- a/docs/c-api/mqtt.h/intro.md
+++ b/docs/c-api/mqtt.h/intro.md
@@ -20,6 +20,7 @@ items:
   - { name: mg_send_mqtt_handshake.md }
   - { name: mg_send_mqtt_handshake_opt.md }
   - { name: mg_set_protocol_mqtt.md }
+  - { name: struct_mg_mqtt_proto_data.md }
 ---
 
 
diff --git a/docs/c-api/mqtt.h/struct_mg_mqtt_proto_data.md b/docs/c-api/mqtt.h/struct_mg_mqtt_proto_data.md
new file mode 100644
index 0000000000000000000000000000000000000000..8ae54fcfcb96499a569b7ff25e76cbf06737399d
--- /dev/null
+++ b/docs/c-api/mqtt.h/struct_mg_mqtt_proto_data.md
@@ -0,0 +1,12 @@
+---
+title: "struct mg_mqtt_proto_data"
+decl_name: "struct mg_mqtt_proto_data"
+symbol_kind: "struct"
+signature: |
+  struct mg_mqtt_proto_data {
+    uint16_t keep_alive;
+  };
+---
+
+mg_mqtt_proto_data should be in header to allow external access to it 
+
diff --git a/examples/examples.mk b/examples/examples.mk
index 7b258f22e309cfcb15dc8f50a1396b050d7f931a..1ddaa5fa1fd6a4d66d463c1689ce64c18e129523 100644
--- a/examples/examples.mk
+++ b/examples/examples.mk
@@ -11,7 +11,7 @@ else
 ifeq ($(SSL_LIB),openssl)
 CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto
 else ifeq ($(SSL_LIB), krypton)
-CFLAGS += -DMG_ENABLE_SSL -DMG_DISABLE_PFS ../../../krypton/krypton.c
+CFLAGS += -DMG_ENABLE_SSL -DMG_DISABLE_PFS -DSSL_KRYPTON ../../../krypton/krypton.c -I../../../krypton
 endif
 CFLAGS += -lpthread
 endif
diff --git a/mongoose.c b/mongoose.c
index fd32a5a9205771957a1811e6e679c5f01d3a9392..f551580f36ee484187d69b4555fffbef6d6a4857 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -8536,8 +8536,14 @@ static void mqtt_handler(struct mg_connection *nc, int ev, void *ev_data) {
   }
 }
 
+static void mg_mqtt_proto_data_destructor(void *proto_data) {
+  MG_FREE(proto_data);
+}
+
 void mg_set_protocol_mqtt(struct mg_connection *nc) {
   nc->proto_handler = mqtt_handler;
+  nc->proto_data = MG_CALLOC(1, sizeof(struct mg_mqtt_proto_data));
+  nc->proto_data_destructor = mg_mqtt_proto_data_destructor;
 }
 
 void mg_send_mqtt_handshake(struct mg_connection *nc, const char *client_id) {
@@ -8551,6 +8557,7 @@ void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id,
   uint8_t rem_len;
   uint16_t keep_alive;
   uint16_t len;
+  struct mg_mqtt_proto_data* pd = (struct mg_mqtt_proto_data*) nc->proto_data;
 
   /*
    * 9: version_header(len, magic_string, version_number), 1: flags, 2:
@@ -8576,6 +8583,7 @@ void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id,
   if (opts.keep_alive == 0) {
     opts.keep_alive = 60;
   }
+
   keep_alive = htons(opts.keep_alive);
   mg_send(nc, &keep_alive, 2);
 
@@ -8593,6 +8601,10 @@ void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id,
     mg_send(nc, &len, 2);
     mg_send(nc, opts.password, strlen(opts.password));
   }
+
+  if (pd != NULL) {
+    pd->keep_alive = opts.keep_alive;
+  }
 }
 
 static void mg_mqtt_prepend_header(struct mg_connection *nc, uint8_t cmd,
diff --git a/mongoose.h b/mongoose.h
index 71aaeddaca326ec690af2da1f1ae9237a4b68a30..146a5d367aa78b9639af4a8ec491254e5145091d 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -4712,6 +4712,11 @@ struct mg_send_mqtt_handshake_opts {
   const char *password;
 };
 
+/* mg_mqtt_proto_data should be in header to allow external access to it */
+struct mg_mqtt_proto_data {
+  uint16_t keep_alive;
+};
+
 /* Message types */
 #define MG_MQTT_CMD_CONNECT 1
 #define MG_MQTT_CMD_CONNACK 2