1
1
/*
2
2
ETH.h - espre ETH PHY support.
3
- Based on WiFi.h from Ardiono WiFi shield library.
3
+ Based on WiFi.h from Arduino WiFi shield library.
4
4
Copyright (c) 2011-2014 Arduino. All right reserved.
5
5
6
6
This library is free software; you can redistribute it and/or
@@ -108,26 +108,43 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
108
108
return false ;
109
109
}
110
110
111
- /*
112
111
bool ETHClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
113
112
{
114
- if(!initialized){
113
+ esp_err_t err = ESP_OK;
114
+ tcpip_adapter_ip_info_t info;
115
+
116
+ if (local_ip != (uint32_t )0x00000000 ){
117
+ info.ip .addr = static_cast <uint32_t >(local_ip);
118
+ info.gw .addr = static_cast <uint32_t >(gateway);
119
+ info.netmask .addr = static_cast <uint32_t >(subnet);
120
+ } else {
121
+ info.ip .addr = 0 ;
122
+ info.gw .addr = 0 ;
123
+ info.netmask .addr = 0 ;
124
+ }
125
+
126
+ err = tcpip_adapter_dhcpc_stop (TCPIP_ADAPTER_IF_ETH);
127
+ if (err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED){
128
+ log_e (" DHCP could not be stopped! Error: %d" , err);
115
129
return false ;
116
130
}
117
131
118
- tcpip_adapter_ip_info_t info;
119
- info.ip.addr = static_cast<uint32_t>(local_ip);
120
- info.gw.addr = static_cast<uint32_t>(gateway);
121
- info.netmask.addr = static_cast<uint32_t>(subnet);
122
-
123
- if(!staticIP){
124
- tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH);
125
- }
126
- if(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &info) == ESP_OK) {
132
+ err = tcpip_adapter_set_ip_info (TCPIP_ADAPTER_IF_ETH, &info);
133
+ if (err != ERR_OK){
134
+ log_e (" STA IP could not be configured! Error: %d" , err);
135
+ return false ;
136
+ }
137
+ if (info.ip .addr ){
127
138
staticIP = true ;
128
139
} else {
129
- return false;
140
+ err = tcpip_adapter_dhcpc_start (TCPIP_ADAPTER_IF_ETH);
141
+ if (err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED){
142
+ log_w (" DHCP could not be started! Error: %d" , err);
143
+ return false ;
144
+ }
145
+ staticIP = false ;
130
146
}
147
+
131
148
ip_addr_t d;
132
149
d.type = IPADDR_TYPE_V4;
133
150
@@ -145,7 +162,6 @@ bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, I
145
162
146
163
return true ;
147
164
}
148
- */
149
165
150
166
IPAddress ETHClass::localIP ()
151
167
{
0 commit comments