From c2361f1894a4ea7dc5712b12692d652293874c93 Mon Sep 17 00:00:00 2001 From: nopnop2002 Date: Fri, 29 Apr 2022 09:15:34 +0900 Subject: [PATCH] Changed from tcpip_adapter_get_ip_info to esp_netif_get_ip_info --- Makefile | 16 ---------------- main/http_post.c | 19 ++++++++++++------- main/http_server.c | 1 + main/main.c | 20 +++++++------------- main/twai.c | 2 +- sdkconfig.defaults | 6 ------ 6 files changed, 21 insertions(+), 43 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 38c808b..0000000 --- a/Makefile +++ /dev/null @@ -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)) - diff --git a/main/http_post.c b/main/http_post.c index a76a2a8..1b358a1 100644 --- a/main/http_post.c +++ b/main/http_post.c @@ -1,10 +1,10 @@ /* ESP HTTP Client Example - This example code is in the Public Domain (or CC0 licensed, at your option.) + This example code is in the Public Domain (or CC0 licensed, at your option.) - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. */ #include @@ -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; } @@ -111,7 +116,7 @@ static void http_rest_with_url(char * path, char * post_data) .port = CONFIG_WEB_PORT, .path = path, .event_handler = _http_event_handler, - .user_data = local_response_buffer, // Pass address of local buffer to get response + .user_data = local_response_buffer, // Pass address of local buffer to get response .disable_auto_redirect = true, }; @@ -120,7 +125,7 @@ static void http_rest_with_url(char * path, char * post_data) esp_http_client_config_t config = { .url = "http://192.168.10.43:8000/post", .event_handler = _http_event_handler, - .user_data = local_response_buffer, // Pass address of local buffer to get response + .user_data = local_response_buffer, // Pass address of local buffer to get response .disable_auto_redirect = true, }; #endif @@ -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); diff --git a/main/http_server.c b/main/http_server.c index 5ffdbac..3b188b4 100644 --- a/main/http_server.c +++ b/main/http_server.c @@ -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" diff --git a/main/main.c b/main/main.c index 269ca10..2df276b 100644 --- a/main/main.c +++ b/main/main.c @@ -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;iframe, (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); diff --git a/main/twai.c b/main/twai.c index 47786de..7fe4272 100644 --- a/main/twai.c +++ b/main/twai.c @@ -50,7 +50,7 @@ void twai_task(void *pvParameters) #if CONFIG_ENABLE_PRINT if (ext == STANDARD_FRAME) { - printf("Standard ID: 0x%03x ", rx_msg.identifier); + printf("Standard ID: 0x%03x ", rx_msg.identifier); } else { printf("Extended ID: 0x%08x", rx_msg.identifier); } diff --git a/sdkconfig.defaults b/sdkconfig.defaults index cf4711b..70aa6c9 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -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 #