Skip to content

Commit d8aa61f

Browse files
committed
Optimize some error messages
1 parent 7e0811e commit d8aa61f

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

libraries/WiFi/src/WiFiClient.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
5959
{
6060
sockfd = socket(AF_INET, SOCK_STREAM, 0);
6161
if (sockfd < 0) {
62-
log_e("error: %d", errno);
62+
log_e("socket: %d", errno);
6363
return 0;
6464
}
6565
uint32_t ip_addr = ip;
@@ -70,7 +70,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
7070
serveraddr.sin_port = htons(port);
7171
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
7272
if (res < 0) {
73-
log_e("error: %d", errno);
73+
log_e("lwip_connect_r: %d", errno);
7474
close(sockfd);
7575
sockfd = -1;
7676
return 0;
@@ -94,7 +94,7 @@ int WiFiClient::setSocketOption(int option, char* value, size_t len)
9494
{
9595
int res = setsockopt(sockfd, SOL_SOCKET, option, value, len);
9696
if(res < 0) {
97-
log_e("error: %d", errno);
97+
log_e("%d", errno);
9898
}
9999
return res;
100100
}
@@ -114,7 +114,7 @@ int WiFiClient::setOption(int option, int *value)
114114
{
115115
int res = setsockopt(sockfd, IPPROTO_TCP, option, (char *)value, sizeof(int));
116116
if(res < 0) {
117-
log_e("error: %d", errno);
117+
log_e("%d", errno);
118118
}
119119
return res;
120120
}
@@ -124,7 +124,7 @@ int WiFiClient::getOption(int option, int *value)
124124
size_t size = sizeof(int);
125125
int res = getsockopt(sockfd, IPPROTO_TCP, option, (char *)value, &size);
126126
if(res < 0) {
127-
log_e("error: %d", errno);
127+
log_e("%d", errno);
128128
}
129129
return res;
130130
}
@@ -164,7 +164,7 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
164164
}
165165
int res = send(sockfd, (void*)buf, size, MSG_DONTWAIT);
166166
if(res < 0) {
167-
log_e("error: %d", errno);
167+
log_e("%d", errno);
168168
_connected = false;
169169
sockfd = -1;
170170
res = 0;
@@ -179,7 +179,7 @@ int WiFiClient::read(uint8_t *buf, size_t size)
179179
}
180180
int res = recv(sockfd, buf, size, MSG_DONTWAIT);
181181
if(res < 0 && errno != EWOULDBLOCK) {
182-
log_e("error: %d", errno);
182+
log_e("%d", errno);
183183
_connected = false;
184184
sockfd = -1;
185185
}
@@ -194,7 +194,7 @@ int WiFiClient::available()
194194
int count;
195195
int res = ioctl(sockfd, FIONREAD, &count);
196196
if(res < 0) {
197-
log_e("error: %d", errno);
197+
log_e("%d", errno);
198198
_connected = false;
199199
sockfd = -1;
200200
return 0;

libraries/WiFi/src/WiFiGeneric.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,18 @@ extern "C" {
3232
#include <stdlib.h>
3333
#include <inttypes.h>
3434
#include <string.h>
35+
3536
#include <esp_err.h>
3637
#include <esp_wifi.h>
3738
#include <esp_event_loop.h>
38-
#include <lwip/ip_addr.h>
39-
39+
#include "lwip/ip_addr.h"
4040
#include "lwip/opt.h"
4141
#include "lwip/err.h"
4242
#include "lwip/dns.h"
4343

4444
#include "esp32-hal-log.h"
4545
}
4646

47-
//#include "WiFiClient.h"
48-
//#include "WiFiUdp.h"
49-
5047
#undef min
5148
#undef max
5249
#include <vector>
@@ -107,7 +104,7 @@ void WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, system_event_id_t event)
107104
*/
108105
esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
109106
{
110-
log_d("wifi evt: %d", event->event_id);
107+
log_d("%d", event->event_id);
111108

112109
if(event->event_id == SYSTEM_EVENT_SCAN_DONE) {
113110
WiFiScanClass::_scanDone();
@@ -122,7 +119,6 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
122119
} else {
123120
WiFiSTAClass::_setStatus(WL_DISCONNECTED);
124121
}
125-
log_d("wifi reason: %d", reason);
126122
} else if(event->event_id == SYSTEM_EVENT_STA_START) {
127123
WiFiSTAClass::_setStatus(WL_DISCONNECTED);
128124
} else if(event->event_id == SYSTEM_EVENT_STA_STOP) {
@@ -303,21 +299,21 @@ void startWiFi()
303299

304300
err = esp_wifi_start();
305301
if (err != ESP_OK) {
306-
log_e("esp_wifi_start fail %d\n", err);
302+
log_e("esp_wifi_start: %d", err);
307303
return;
308304
}
309305

310306
err = esp_wifi_get_mode(&mode);
311307
if (err != ESP_OK) {
312-
log_e("esp_wifi_get_mode fail %d\n", err);
308+
log_e("esp_wifi_get_mode: %d", err);
313309
return;
314310
}
315311

316312
err = esp_wifi_get_auto_connect(&auto_connect);
317313
if ((mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) && auto_connect) {
318314
err = esp_wifi_connect();
319315
if (err != ESP_OK) {
320-
log_e("esp_wifi_connect fail %d\n", err);
316+
log_e("esp_wifi_connect: %d", err);
321317
}
322318
}
323319
}

0 commit comments

Comments
 (0)