Changed from tcpip_adapter_get_ip_info to esp_netif_get_ip_info

This commit is contained in:
nopnop2002
2022-04-29 09:15:34 +09:00
parent a8be8b0034
commit c2361f1894
6 changed files with 21 additions and 43 deletions
-16
View File
@@ -1,16 +0,0 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := can2mqtt
include $(IDF_PATH)/make/project.mk
# Create a SPIFFS image from the contents of the 'spiffs_image' directory
# that fits the partition named 'storage'. FLASH_IN_PROJECT indicates that
# the generated image should be flashed when the entire project is flashed to
# the target with 'make flash'.
SPIFFS_IMAGE_FLASH_IN_PROJECT := 1
$(eval $(call spiffs_create_partition_image,storage,csv))
+6 -1
View File
@@ -90,6 +90,11 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
ESP_LOGI(TAG, "Last mbedtls failure: 0x%x", mbedtls_err);
}
break;
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
esp_http_client_set_header(evt->client, "From", "user@example.com");
esp_http_client_set_header(evt->client, "Accept", "text/html");
break;
}
return ESP_OK;
}
@@ -148,7 +153,7 @@ static void http_rest_with_url(char * path, char * post_data)
void http_client_task(void *pvParameters)
{
ESP_LOGI(TAG, "Start HTTP Client: http://%s:%d", CONFIG_WEB_SERVER, CONFIG_WEB_PORT);
ESP_LOGI(TAG, "Start HTTP Client: connect to http://%s:%d", CONFIG_WEB_SERVER, CONFIG_WEB_PORT);
FRAME_t frameBuf;
while (1) {
xQueueReceive(xQueue_http_client, &frameBuf, portMAX_DELAY);
+1
View File
@@ -19,6 +19,7 @@
#include "esp_vfs.h"
#include "esp_spiffs.h"
#include "esp_http_server.h"
#include "esp_chip_info.h"
#include "cJSON.h"
#include "driver/twai.h"
+7 -13
View File
@@ -104,19 +104,10 @@ void wifi_init_sta()
ESP_LOGI(TAG,"ESP-IDF Ver%d.%d", ESP_IDF_VERSION_MAJOR, ESP_IDF_VERSION_MINOR);
ESP_LOGI(TAG,"ESP_IDF_VERSION %d", ESP_IDF_VERSION);
//#if ESP_IDF_VERSION_MAJOR >= 4 && ESP_IDF_VERSION_MINOR >= 1
#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0)
ESP_LOGI(TAG,"ESP-IDF esp_netif");
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_t *netif = esp_netif_create_default_wifi_sta();
assert(netif);
#else
ESP_LOGE(TAG,"esp-idf version 4.1 or higher required");
while(1) {
vTaskDelay(1);
}
#endif // ESP_IDF_VERSION
#if CONFIG_STATIC_IP
@@ -357,7 +348,7 @@ esp_err_t build_table(TOPIC_t **topics, char *file, int16_t *ntopic)
void dump_table(TOPIC_t *topics, int16_t ntopic)
{
for(int i=0;i<ntopic;i++) {
ESP_LOGI(pcTaskGetTaskName(0), "topics[%d] frame=%d canid=0x%x topic=[%s] topic_len=%d",
ESP_LOGI(pcTaskGetName(0), "topics[%d] frame=%d canid=0x%x topic=[%s] topic_len=%d",
i, (topics+i)->frame, (topics+i)->canid, (topics+i)->topic, (topics+i)->topic_len);
}
@@ -416,11 +407,14 @@ void app_main()
dump_table(publish, npublish);
/* Get the local IP address */
tcpip_adapter_ip_info_t ip_info;
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
//tcpip_adapter_ip_info_t ip_info;
//ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
esp_netif_ip_info_t ip_info;
ESP_ERROR_CHECK(esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &ip_info));
char cparam0[64];
sprintf(cparam0, "%s", ip4addr_ntoa(&ip_info.ip));
//sprintf(cparam0, "%s", ip4addr_ntoa(&ip_info.ip));
sprintf(cparam0, IPSTR, IP2STR(&ip_info.ip));
xTaskCreate(http_server_task, "server", 1024*6, (void *)cparam0, 2, NULL);
xTaskCreate(http_client_task, "client", 1024*6, NULL, 2, NULL);
-6
View File
@@ -5,12 +5,6 @@ CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
#
# ESP32-specific
#
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240
#
# mDNS
#