'tcpip_adapter_init' has been deprecated

This commit is contained in:
nopnop2002
2022-03-27 10:56:32 +09:00
parent a0eb32d972
commit 22f41d860b
3 changed files with 27 additions and 51 deletions
+8 -22
View File
@@ -73,29 +73,11 @@ __NOTE__
Check [here](http://www.ti.com/lit/an/slla337/slla337.pdf).
# Installation for ESP32
# Installation
```
git clone https://github.com/nopnop2002/esp-idf-can2http
cd esp-idf-can2http
idf.py set-target esp32
idf.py menuconfig
idf.py flash
```
# Installation for ESP32-S2
```
git clone https://github.com/nopnop2002/esp-idf-can2http
cd esp-idf-can2http
idf.py set-target esp32s2
idf.py menuconfig
idf.py flash
```
# Installation for ESP32-C3
```
git clone https://github.com/nopnop2002/esp-idf-can2http
cd esp-idf-can2http
idf.py set-target esp32c3
idf.py set-target {esp32/esp32s2/esp32c3}
idf.py menuconfig
idf.py flash
```
@@ -105,7 +87,7 @@ idf.py flash
![config-app](https://user-images.githubusercontent.com/6020549/123870638-94709180-d96d-11eb-94da-b4860148be6a.jpg)
## CAN Setting
![config-can](https://user-images.githubusercontent.com/6020549/123870665-a05c5380-d96d-11eb-89b1-78a274bfd957.jpg)
![config-can](https://user-images.githubusercontent.com/6020549/160263252-f2a10f2b-a970-44bf-ab9c-22ae7baa4ab5.jpg)
## WiFi Setting
![config-wifi-1](https://user-images.githubusercontent.com/6020549/125028704-73254900-e0c3-11eb-9a44-25482d7a08be.jpg)
@@ -118,7 +100,7 @@ You can connect using mDNS.
## External HTTP Server Setting
The External HTTP Server receives CAN Bus received data.
![config-http](https://user-images.githubusercontent.com/6020549/123873614-b5d37c80-d971-11eb-8ead-827f52aed982.jpg)
![config-http](https://user-images.githubusercontent.com/6020549/160263251-1b1a4771-a5f0-43f2-b75e-572fa6904ac9.jpg)
__Note__
The Built-in HTTP Server receives CAN Bus transmittion data.
@@ -178,10 +160,12 @@ CANBus reception using UNO.
# HTTP Server Using Tornado
```
cd $HOME
sudo apt install python3-pip python3-setuptools
python -m pip install -U pip
python -m pip install -U wheel
python -m pip install tornado
cd esp-idf-can2http
cd tornado
python can.py
```
@@ -190,11 +174,13 @@ python can.py
# HTTP Server Using Flask
```
cd $HOME
sudo apt install python3-pip python3-setuptools
python -m pip install -U pip
python -m pip install -U wheel
python -m pip install -U Werkzeug
python -m pip install flask
cd esp-idf-can2http
cd flask
python can.py
```
+2 -1
View File
@@ -65,6 +65,7 @@ menu "Application Configuration"
config ENABLE_PRINT
bool "Output the received CAN FRAME to STDOUT"
default y
help
Output the received CAN FRAME to STDOUT.
@@ -129,7 +130,7 @@ menu "Application Configuration"
config WEB_SERVER
string "HTTP Server IP or mDNS"
default "myhttpserver"
default "httpserver.local"
help
The host name or IP address of the HTTP server to use.
+17 -28
View File
@@ -1,9 +1,9 @@
/*
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 <stdio.h>
@@ -65,7 +65,7 @@ static EventGroupHandle_t s_wifi_event_group;
* - we are connected to the AP with an IP
* - we failed to connect after the maximum amount of retries */
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
#define WIFI_FAIL_BIT BIT1
static int s_retry_num = 0;
@@ -102,17 +102,21 @@ void wifi_init_sta()
s_wifi_event_group = xEventGroupCreate();
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_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_LOGI(TAG,"ESP-IDF tcpip_adapter");
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
#endif
ESP_LOGE(TAG,"esp-idf version 4.1 or higher required");
while(1) {
vTaskDelay(1);
}
#endif // ESP_IDF_VERSION
#if CONFIG_STATIC_IP
@@ -120,7 +124,6 @@ void wifi_init_sta()
ESP_LOGI(TAG, "CONFIG_STATIC_GW_ADDRESS=[%s]",CONFIG_STATIC_GW_ADDRESS);
ESP_LOGI(TAG, "CONFIG_STATIC_NM_ADDRESS=[%s]",CONFIG_STATIC_NM_ADDRESS);
#if ESP_IDF_VERSION_MAJOR >= 4 && ESP_IDF_VERSION_MINOR >= 1
/* Stop DHCP client */
ESP_ERROR_CHECK(esp_netif_dhcpc_stop(netif));
ESP_LOGI(TAG, "Stop DHCP Services");
@@ -133,20 +136,6 @@ void wifi_init_sta()
ip_info.gw.addr = ipaddr_addr(CONFIG_STATIC_GW_ADDRESS);;
esp_netif_set_ip_info(netif, &ip_info);
#else
/* Stop DHCP client */
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
ESP_LOGI(TAG, "Stop DHCP Services");
/* Set STATIC IP Address */
tcpip_adapter_ip_info_t ip_info;
memset(&ip_info, 0 , sizeof(tcpip_adapter_ip_info_t));
ip_info.ip.addr = ipaddr_addr(CONFIG_STATIC_IP_ADDRESS);
ip_info.netmask.addr = ipaddr_addr(CONFIG_STATIC_NM_ADDRESS);
ip_info.gw.addr = ipaddr_addr(CONFIG_STATIC_GW_ADDRESS);;
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
#endif
/*
I referred from here.
https://www.esp32.com/viewtopic.php?t=5380
@@ -162,7 +151,7 @@ void wifi_init_sta()
d.u_addr.ip4.addr = 0x08080404; //8.8.4.4 dns
dns_setserver(1, &d);
#endif
#endif // CONFIG_STATIC_IP
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
@@ -383,8 +372,8 @@ void app_main()
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);