mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-12-16 02:43:47 +08:00
feat(mqtt): update mqtt component to esp-mqtt commit id 752953dc and update some example
This commit is contained in:
@@ -6,4 +6,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(mqtt_websocket_secure)
|
||||
|
||||
target_add_binary_data(mqtt_websocket_secure.elf "main/iot_eclipse_org.pem" TEXT)
|
||||
target_add_binary_data(mqtt_websocket_secure.elf "main/mqtt_eclipse_org.pem" TEXT)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# ESP-MQTT MQTT over WSS Sample application
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example connects to the broker iot.eclipse.org over secure websockets and as a demonstration subscribes/unsubscribes and send a message on certain topic.
|
||||
This example connects to the broker mqtt.eclipse.org over secure websockets and as a demonstration subscribes/unsubscribes and send a message on certain topic.
|
||||
|
||||
It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker.
|
||||
|
||||
@@ -21,10 +21,10 @@ make menuconfig
|
||||
|
||||
* Set ssid and password for the board to connect to AP.
|
||||
|
||||
Note how to create a PEM certificate for iot.eclipse.org:
|
||||
Note how to create a PEM certificate for mqtt.eclipse.org:
|
||||
|
||||
```
|
||||
openssl s_client -showcerts -connect iot.eclipse.org:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem
|
||||
openssl s_client -showcerts -connect mqtt.eclipse.org:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem
|
||||
```
|
||||
|
||||
### Build and Flash
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
config WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
|
||||
config WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
default "mypassword"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
config WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
default "mypassword"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
config BROKER_URI
|
||||
string "Broker URL"
|
||||
default "wss://iot.eclipse.org:443/ws"
|
||||
help
|
||||
URL of an mqtt broker which this example connects to.
|
||||
config BROKER_URI
|
||||
string "Broker URL"
|
||||
default "wss://mqtt.eclipse.org:443/mqtt"
|
||||
help
|
||||
URL of an mqtt broker which this example connects to.
|
||||
|
||||
config BROKER_CERTIFICATE_OVERRIDE
|
||||
string "Server certificate override"
|
||||
default ""
|
||||
help
|
||||
Please leave empty if server certificate included from a textfile; otherwise fill in a base64 part of PEM format certificate
|
||||
config BROKER_CERTIFICATE_OVERRIDE
|
||||
string "Server certificate override"
|
||||
default ""
|
||||
help
|
||||
Please leave empty if server certificate included from a textfile; otherwise fill in a base64 part of PEM
|
||||
format certificate
|
||||
|
||||
config BROKER_CERTIFICATE_OVERRIDDEN
|
||||
bool
|
||||
default y if BROKER_CERTIFICATE_OVERRIDE != ""
|
||||
config BROKER_CERTIFICATE_OVERRIDDEN
|
||||
bool
|
||||
default y if BROKER_CERTIFICATE_OVERRIDE != ""
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -78,11 +78,11 @@ static void wifi_init(void)
|
||||
}
|
||||
|
||||
#if CONFIG_BROKER_CERTIFICATE_OVERRIDDEN == 1
|
||||
static const uint8_t iot_eclipse_org_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----";
|
||||
static const uint8_t mqtt_eclipse_org_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----";
|
||||
#else
|
||||
extern const uint8_t iot_eclipse_org_pem_start[] asm("_binary_iot_eclipse_org_pem_start");
|
||||
extern const uint8_t mqtt_eclipse_org_pem_start[] asm("_binary_mqtt_eclipse_org_pem_start");
|
||||
#endif
|
||||
extern const uint8_t iot_eclipse_org_pem_end[] asm("_binary_iot_eclipse_org_pem_end");
|
||||
extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end");
|
||||
|
||||
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
|
||||
{
|
||||
@@ -124,6 +124,9 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
|
||||
case MQTT_EVENT_ERROR:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -133,7 +136,7 @@ static void mqtt_app_start(void)
|
||||
const esp_mqtt_client_config_t mqtt_cfg = {
|
||||
.uri = CONFIG_BROKER_URI,
|
||||
.event_handle = mqtt_event_handler,
|
||||
.cert_pem = (const char *)iot_eclipse_org_pem_start,
|
||||
.cert_pem = (const char *)mqtt_eclipse_org_pem_start,
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
|
||||
|
||||
@@ -1 +1 @@
|
||||
COMPONENT_EMBED_TXTFILES := iot_eclipse_org.pem
|
||||
COMPONENT_EMBED_TXTFILES := mqtt_eclipse_org.pem
|
||||
|
||||
@@ -84,8 +84,8 @@ def test_examples_protocol_mqtt_wss(env, extra_data):
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.tls_set(None,
|
||||
None,
|
||||
None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1, ciphers=None)
|
||||
None,
|
||||
None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
|
||||
print("Connecting...")
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
@@ -114,5 +114,6 @@ def test_examples_protocol_mqtt_wss(env, extra_data):
|
||||
event_stop_client.set()
|
||||
thread1.join()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_protocol_mqtt_wss()
|
||||
|
||||
Reference in New Issue
Block a user