Skip to content

Commit 7d5c39e

Browse files
committed
idf4.0_compat: Minor changes for IDF 4.0 compatibility
If IDF version being used is 4.0, following changes will happen: - tcpip_adapter will be used, instead of esp_netif. - MQTT port 8883 will be used, even if 443 is chosen, because 443 requires ALPN options in MQTT, which aren't supported in IDF 4.0
1 parent f476701 commit 7d5c39e

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ The key features of ESP RainMaker are:
1818
2. Zero configuration required on the Cloud.
1919
3. Phone apps that dynamically render the UI as per the device information.
2020

21+
## Supported ESP-IDF versions
22+
23+
ESP RainMaker can work with ESP IDF 4.0 and above.
24+
2125
## Phone Apps
2226

2327
### Android

components/esp_rainmaker/src/mqtt/esp_rmaker_mqtt.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@
1919
#include <freertos/event_groups.h>
2020
#include <esp_log.h>
2121
#include <mqtt_client.h>
22-
2322
#include <esp_rmaker_mqtt.h>
2423

24+
#include <esp_idf_version.h>
25+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
26+
// Features supported in 4.1
27+
28+
#ifdef CONFIG_ESP_RMAKER_MQTT_PORT_443
29+
#define ESP_RMAKER_MQTT_USE_PORT_443
30+
#endif
31+
32+
#else
33+
34+
#ifdef CONFIG_ESP_RMAKER_MQTT_PORT_443
35+
#warning "Port 443 not supported in idf versions below 4.1. Using 8883 instead."
36+
#endif
37+
38+
#endif /* !IDF4.1 */
39+
2540
static const char *TAG = "esp_rmaker_mqtt";
2641

2742
#define MAX_MQTT_SUBSCRIPTIONS 5
@@ -212,9 +227,9 @@ esp_err_t esp_rmaker_mqtt_disconnect(void)
212227
}
213228
return err;
214229
}
215-
#ifdef CONFIG_ESP_RMAKER_MQTT_PORT_443
230+
#ifdef ESP_RMAKER_MQTT_USE_PORT_443
216231
static const char *alpn_protocols[] = { "x-amzn-mqtt-ca", NULL };
217-
#endif /* CONFIG_ESP_RMAKER_MQTT_PORT_443 */
232+
#endif /* ESP_RMAKER_MQTT_USE_PORT_443 */
218233
esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_config_t *config)
219234
{
220235
if (mqtt_data) {
@@ -229,13 +244,12 @@ esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_config_t *config)
229244
mqtt_data->config = config;
230245
const esp_mqtt_client_config_t mqtt_client_cfg = {
231246
.host = config->mqtt_host,
232-
#ifdef CONFIG_ESP_RMAKER_MQTT_PORT_443
247+
#ifdef ESP_RMAKER_MQTT_USE_PORT_443
233248
.port = 443,
234249
.alpn_protos = alpn_protocols,
235-
#endif /* CONFIG_ESP_RMAKER_MQTT_PORT_443 */
236-
#ifdef CONFIG_ESP_RMAKER_MQTT_PORT_8883
250+
#else
237251
.port = 8883,
238-
#endif /* CONFIG_ESP_RMAKER_MQTT_PORT_8883 */
252+
#endif /* !ESP_RMAKER_MQTT_USE_PORT_443 */
239253
.cert_pem = (const char *)config->server_cert,
240254
.client_cert_pem = (const char *)config->client_cert,
241255
.client_key_pem = (const char *)config->client_key,

examples/common/app_wifi/app_wifi.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
#include <esp_wifi.h>
1313
#include <esp_event.h>
1414
#include <esp_log.h>
15+
#include <esp_idf_version.h>
16+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
17+
// Features supported in 4.1+
18+
#define ESP_NETIF_SUPPORTED
19+
#endif
20+
21+
#ifdef ESP_NETIF_SUPPORTED
22+
#include <esp_netif.h>
23+
#else
24+
#include <tcpip_adapter.h>
25+
#endif
26+
1527
#include <wifi_provisioning/manager.h>
1628
#ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE
1729
#include <wifi_provisioning/scheme_ble.h>
@@ -181,7 +193,11 @@ static esp_err_t get_device_pop(char *pop, size_t max, app_wifi_pop_type_t pop_t
181193
void app_wifi_init(void)
182194
{
183195
/* Initialize TCP/IP */
196+
#ifdef ESP_NETIF_SUPPORTED
184197
esp_netif_init();
198+
#else
199+
tcpip_adapter_init();
200+
#endif
185201

186202
/* Initialize the event loop */
187203
ESP_ERROR_CHECK(esp_event_loop_create_default());
@@ -193,7 +209,9 @@ void app_wifi_init(void)
193209
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
194210

195211
/* Initialize Wi-Fi including netif with default config */
212+
#ifdef ESP_NETIF_SUPPORTED
196213
esp_netif_create_default_wifi_sta();
214+
#endif
197215
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
198216
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
199217
}
@@ -236,7 +254,9 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type)
236254
/* If device is not yet provisioned start provisioning service */
237255
if (!provisioned) {
238256
ESP_LOGI(TAG, "Starting provisioning");
257+
#ifdef ESP_NETIF_SUPPORTED
239258
esp_netif_create_default_wifi_ap();
259+
#endif
240260

241261
/* What is the Device Service Name that we want
242262
* This translates to :

0 commit comments

Comments
 (0)