Optimize some error messages

This commit is contained in:
me-no-dev 2016-11-13 17:30:21 +02:00
parent 7e0811ec56
commit d8aa61fa52
2 changed files with 14 additions and 18 deletions

View File

@ -59,7 +59,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
{
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
log_e("error: %d", errno);
log_e("socket: %d", errno);
return 0;
}
uint32_t ip_addr = ip;
@ -70,7 +70,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
serveraddr.sin_port = htons(port);
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
if (res < 0) {
log_e("error: %d", errno);
log_e("lwip_connect_r: %d", errno);
close(sockfd);
sockfd = -1;
return 0;
@ -94,7 +94,7 @@ int WiFiClient::setSocketOption(int option, char* value, size_t len)
{
int res = setsockopt(sockfd, SOL_SOCKET, option, value, len);
if(res < 0) {
log_e("error: %d", errno);
log_e("%d", errno);
}
return res;
}
@ -114,7 +114,7 @@ int WiFiClient::setOption(int option, int *value)
{
int res = setsockopt(sockfd, IPPROTO_TCP, option, (char *)value, sizeof(int));
if(res < 0) {
log_e("error: %d", errno);
log_e("%d", errno);
}
return res;
}
@ -124,7 +124,7 @@ int WiFiClient::getOption(int option, int *value)
size_t size = sizeof(int);
int res = getsockopt(sockfd, IPPROTO_TCP, option, (char *)value, &size);
if(res < 0) {
log_e("error: %d", errno);
log_e("%d", errno);
}
return res;
}
@ -164,7 +164,7 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
}
int res = send(sockfd, (void*)buf, size, MSG_DONTWAIT);
if(res < 0) {
log_e("error: %d", errno);
log_e("%d", errno);
_connected = false;
sockfd = -1;
res = 0;
@ -179,7 +179,7 @@ int WiFiClient::read(uint8_t *buf, size_t size)
}
int res = recv(sockfd, buf, size, MSG_DONTWAIT);
if(res < 0 && errno != EWOULDBLOCK) {
log_e("error: %d", errno);
log_e("%d", errno);
_connected = false;
sockfd = -1;
}
@ -194,7 +194,7 @@ int WiFiClient::available()
int count;
int res = ioctl(sockfd, FIONREAD, &count);
if(res < 0) {
log_e("error: %d", errno);
log_e("%d", errno);
_connected = false;
sockfd = -1;
return 0;

View File

@ -32,11 +32,11 @@ extern "C" {
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <esp_err.h>
#include <esp_wifi.h>
#include <esp_event_loop.h>
#include <lwip/ip_addr.h>
#include "lwip/ip_addr.h"
#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/dns.h"
@ -44,9 +44,6 @@ extern "C" {
#include "esp32-hal-log.h"
}
//#include "WiFiClient.h"
//#include "WiFiUdp.h"
#undef min
#undef max
#include <vector>
@ -107,7 +104,7 @@ void WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, system_event_id_t event)
*/
esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
{
log_d("wifi evt: %d", event->event_id);
log_d("%d", event->event_id);
if(event->event_id == SYSTEM_EVENT_SCAN_DONE) {
WiFiScanClass::_scanDone();
@ -122,7 +119,6 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
} else {
WiFiSTAClass::_setStatus(WL_DISCONNECTED);
}
log_d("wifi reason: %d", reason);
} else if(event->event_id == SYSTEM_EVENT_STA_START) {
WiFiSTAClass::_setStatus(WL_DISCONNECTED);
} else if(event->event_id == SYSTEM_EVENT_STA_STOP) {
@ -303,13 +299,13 @@ void startWiFi()
err = esp_wifi_start();
if (err != ESP_OK) {
log_e("esp_wifi_start fail %d\n", err);
log_e("esp_wifi_start: %d", err);
return;
}
err = esp_wifi_get_mode(&mode);
if (err != ESP_OK) {
log_e("esp_wifi_get_mode fail %d\n", err);
log_e("esp_wifi_get_mode: %d", err);
return;
}
@ -317,7 +313,7 @@ void startWiFi()
if ((mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) && auto_connect) {
err = esp_wifi_connect();
if (err != ESP_OK) {
log_e("esp_wifi_connect fail %d\n", err);
log_e("esp_wifi_connect: %d", err);
}
}
}