-
My goal is: STM32/W5500/MbedTLS Skip Verification and Connect to MQTT/8883.
-
My question is: How do I set skip_verifcation in Mongoosews to access MQTTS 8883 without authentication? I need to test my project in this environment. I can't connect successfully using either MG_TLS_MBED or MG_TLS_BUILTIN. (This is custom PCB board).
-
The result I saw:
931 2 mongoose.c:5131:mg_tcpip_poll Status: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0
93f 1 mongoose.c:5159:mg_tcpip_poll Network is down
d17 2 mongoose.c:5131:mg_tcpip_poll Status: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0
d25 1 mongoose.c:4386:onstatechange Link up
d35 3 mongoose.c:4499:tx_dhcp_discov DHCP discover sent. Our MAC: 02:04:0e:08:0d:06
d85 3 mongoose.c:4478:tx_dhcp_reques DHCP req sent
de3 2 mongoose.c:4621:rx_dhcp_client Lease: 86400 sec (86403)
ded 1 mongoose.c:4383:onstatechange Got IP
e03 2 mongoose.c:4379:onstatechange READY, IP: 192.168.0.171
e0d 2 mongoose.c:4380:onstatechange GW: 192.168.0.1
e17 2 mongoose.c:4381:onstatechange MAC: 02:04:0e:08:0d:06
a18f 3 mongoose.c:4054:mg_connect_svc 5 -1 mqtts://test.mosquitto.org:8883
MQTT_Timer_Fn Trigger
a199 2 mongoose.c:5131:mg_tcpip_poll Status: ready, IP: 192.168.0.171, rx:42, tx:20, dr:0, er:0
a1ad 3 mongoose.c:299:dns_cb 5 test.mosquitto.org is 5.196.78.28
a1b4 3 mongoose.c:5326:mg_connect_res 5 192.168.0.171:33799 -> 5.196.78.28:8883
[MQTT] MG_EV_CONNECT
[MQTT] TLS connection detected, initializing TLS…
a2cb 3 mongoose.c:14147:mg_tls_init 5 Setting TLS
TLS min/max: 3.3 - 3.3
[TLS] automode verify none
[TLS] setup success
[MQTT TLS] Using Mongoose TLS with maximum compatibility (no SNI)
a3dc 1 mongoose.c:502:mg_error 5 -1 TLS handshake: -0x7780
[MQTT] 5 MG_EV_ERROR TLS handshake: -0x7780
[MQTT TLS DIAGNOSIS] ================================
[MQTT TLS] Error -0x7780: MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY
[MQTT TLS] Server closed connection during handshake
[MQTT TLS] Common causes:
[MQTT TLS] - TLS version mismatch (server expects different version)
[MQTT TLS] - Cipher suite incompatibility
[MQTT TLS] - Server doesn’t accept our TLS configuration
[MQTT TLS] - SNI hostname verification issue
[MQTT TLS] Solutions to try:
[MQTT TLS] 1. Disable SNI (set name to empty)
[MQTT TLS] 2. Try different TLS versions
[MQTT TLS] 3. Use non-encrypted connection first to test
[MQTT TLS DIAGNOSIS] ================================
[MQTT] MG_EV_CLOSE 5
[MQTT TLS] TLS resources cleaned up
a428 3 mongoose.c:4024:mg_close_conn 5 -1 closed
Environment
- mongoose version: 7.18
- Compiler/IDE and SDK: STM32CubeIDE 1.16.1 / STM32F401
- Target hardware/board: Custom
- Connectivity chip/module: STM32F401/W5500
- Target RTOS/OS (if applicable): FreeRTOS
- Lib: MbedTLS(2.16), Mongoosews 7.8
Config
#define MG_ARCH MG_ARCH_NEWLIB // MG_ARCH_ARMGCC, Plain ARM GCC
#define MG_TLS MG_TLS_MBED
#define MG_ENABLE_MIP 1
#define MG_ENABLE_TCPIP 1
#define MG_HTTP_INDEX "index.html" // default page, mongoose.h 977 lines
#define MG_ENABLE_CUSTOM_MILLIS 1
#define MG_ENABLE_CUSTOM_RANDOM 1
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 1 // Debug
#define MG_ENABLE_PACKED_FS 1
#define MG_ENABLE_FATFS 1
#define MG_ENABLE_POSIX_FS 0
#define MG_ENABLE_LOG 1
#define MG_ENABLE_DRIVER_W5500 1
Code
#define MQTT_URL "mqtts://test.mosquitto.org:8883"
void MQTTEvent(struct mg_connection *c, int ev, void ev_data) {
switch(ev) {
case MG_EV_CONNECT: {
struct mg_tls_opts mqtt_tls_opts = {0};
mqtt_tls_opts.ca = mg_str(""); // or not use
mqtt_tls_opts.skip_verification = 1;
mg_tls_init(c, &mqtt_tls_opts);
};
break;
}
}
void MQTT_Timer_Fn(void *arg) {
struct mg_mgr *mgr = (struct mg_mgr *) arg;
struct mg_mqtt_opts mqtt_opts;
memset(&mqtt_opts, 0, sizeof(mqtt_opts));
mqtt_opts.clean = true;
mqtt_opts.keepalive = 10;
mqtt_opts.version = 4;
mqtt_opts.pass = mg_str(MQTT_PASS);
mqtt_opts.user = mg_str(MQTT_USER);
if (s_mqtt_conn == NULL) {
s_mqtt_conn = mg_mqtt_connect(mgr, MQTT_URL, &mqtt_opts, MQTTEvent, NULL);
} else {
mg_mqtt_ping(s_mqtt_conn);
};
printf("MQTT_Timer_Fn Trigger\n");
}
My goal is: STM32/W5500/MbedTLS Skip Verification and Connect to MQTT/8883.
My question is: How do I set skip_verifcation in Mongoosews to access MQTTS 8883 without authentication? I need to test my project in this environment. I can't connect successfully using either MG_TLS_MBED or MG_TLS_BUILTIN. (This is custom PCB board).
The result I saw:
Environment
Config
#define MG_ARCH MG_ARCH_NEWLIB // MG_ARCH_ARMGCC, Plain ARM GCC
#define MG_TLS MG_TLS_MBED
#define MG_ENABLE_MIP 1
#define MG_ENABLE_TCPIP 1
#define MG_HTTP_INDEX "index.html" // default page, mongoose.h 977 lines
#define MG_ENABLE_CUSTOM_MILLIS 1
#define MG_ENABLE_CUSTOM_RANDOM 1
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 1 // Debug
#define MG_ENABLE_PACKED_FS 1
#define MG_ENABLE_FATFS 1
#define MG_ENABLE_POSIX_FS 0
#define MG_ENABLE_LOG 1
#define MG_ENABLE_DRIVER_W5500 1
Code
#define MQTT_URL "mqtts://test.mosquitto.org:8883"
void MQTTEvent(struct mg_connection *c, int ev, void ev_data) {
switch(ev) {
case MG_EV_CONNECT: {
struct mg_tls_opts mqtt_tls_opts = {0};
mqtt_tls_opts.ca = mg_str(""); // or not use
mqtt_tls_opts.skip_verification = 1;
mg_tls_init(c, &mqtt_tls_opts);
};
break;
}
}
void MQTT_Timer_Fn(void *arg) {
struct mg_mgr *mgr = (struct mg_mgr *) arg;
struct mg_mqtt_opts mqtt_opts;
memset(&mqtt_opts, 0, sizeof(mqtt_opts));
mqtt_opts.clean = true;
mqtt_opts.keepalive = 10;
mqtt_opts.version = 4;
mqtt_opts.pass = mg_str(MQTT_PASS);
mqtt_opts.user = mg_str(MQTT_USER);
if (s_mqtt_conn == NULL) {
s_mqtt_conn = mg_mqtt_connect(mgr, MQTT_URL, &mqtt_opts, MQTTEvent, NULL);
} else {
mg_mqtt_ping(s_mqtt_conn);
};
printf("MQTT_Timer_Fn Trigger\n");
}