Skip to content

Fixed ESP-IDF 4.0 compile errors #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ Due to [this issue](https://github.com/nkolban/esp32-snippets/issues/797), remov
### 2) Add new static method to kill BLE server properly

Add removeServer() method to BLEDevice class, so that the programmer could deinitialise the BLE server(kill the BLE server).

### 3) Creates a bunch of fixes for GCC warnings and errors

View commits for more information.
10 changes: 5 additions & 5 deletions cpp_utils/BLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,14 @@ void BLECharacteristic::setValue(std::string value) {
setValue((uint8_t*)(value.data()), value.length());
} // setValue

void BLECharacteristic::setValue(uint16_t& data16) {
void BLECharacteristic::setValue(uint16_t data16) {
uint8_t temp[2];
temp[0] = data16;
temp[1] = data16 >> 8;
setValue(temp, 2);
} // setValue

void BLECharacteristic::setValue(uint32_t& data32) {
void BLECharacteristic::setValue(uint32_t data32) {
uint8_t temp[4];
temp[0] = data32;
temp[1] = data32 >> 8;
Expand All @@ -677,7 +677,7 @@ void BLECharacteristic::setValue(uint32_t& data32) {
setValue(temp, 4);
} // setValue

void BLECharacteristic::setValue(int& data32) {
void BLECharacteristic::setValue(int data32) {
uint8_t temp[4];
temp[0] = data32;
temp[1] = data32 >> 8;
Expand All @@ -686,13 +686,13 @@ void BLECharacteristic::setValue(int& data32) {
setValue(temp, 4);
} // setValue

void BLECharacteristic::setValue(float& data32) {
void BLECharacteristic::setValue(float data32) {
uint8_t temp[4];
*((float*)temp) = data32;
setValue(temp, 4);
} // setValue

void BLECharacteristic::setValue(double& data64) {
void BLECharacteristic::setValue(double data64) {
uint8_t temp[8];
*((double*)temp) = data64;
setValue(temp, 8);
Expand Down
10 changes: 5 additions & 5 deletions cpp_utils/BLECharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class BLECharacteristic {
void setReadProperty(bool value);
void setValue(uint8_t* data, size_t size);
void setValue(std::string value);
void setValue(uint16_t& data16);
void setValue(uint32_t& data32);
void setValue(int& data32);
void setValue(float& data32);
void setValue(double& data64);
void setValue(uint16_t data16);
void setValue(uint32_t data32);
void setValue(int data32);
void setValue(float data32);
void setValue(double data64);
void setWriteProperty(bool value);
void setWriteNoResponseProperty(bool value);
std::string toString();
Expand Down
4 changes: 2 additions & 2 deletions cpp_utils/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
*/
void BLEDevice::whiteListAdd(BLEAddress address) {
ESP_LOGD(LOG_TAG, ">> whiteListAdd: %s", address.toString().c_str());
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_RANDOM); // True to add an entry.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
Expand All @@ -499,7 +499,7 @@ void BLEDevice::whiteListAdd(BLEAddress address) {
*/
void BLEDevice::whiteListRemove(BLEAddress address) {
ESP_LOGD(LOG_TAG, ">> whiteListRemove: %s", address.toString().c_str());
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_RANDOM); // False to remove an entry.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
Expand Down
1 change: 1 addition & 0 deletions cpp_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(COMPONENT_REQUIRES
"json"
"mdns"
"nvs_flash"
"bt"
)
set(COMPONENT_PRIV_REQUIRES )

Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "GeneralUtils.h"

#include <esp_log.h>
#include <hwcrypto/sha.h>
#include <esp32/sha.h>

#define STATE_NAME 0
#define STATE_VALUE 1
Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/SockServ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SockServ::~SockServ() {
pSockServ->m_clientSet.insert(tempSock);
xQueueSendToBack(pSockServ->m_acceptQueue, &tempSock, portMAX_DELAY);
pSockServ->m_clientSemaphore.give();
} catch (std::exception e) {
} catch (std::exception& e) {
ESP_LOGD(LOG_TAG, "acceptTask ending");
pSockServ->m_clientSemaphore.give(); // Wake up any waiting clients.
FreeRTOS::deleteTask();
Expand Down
16 changes: 8 additions & 8 deletions cpp_utils/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Socket Socket::accept() {
ESP_LOGD(LOG_TAG, ">> accept: Accepting on %s; sockFd: %d, using SSL: %d", addressToString(&addr).c_str(), m_sock, getSSL());
struct sockaddr_in client_addr;
socklen_t sin_size;
int clientSockFD = ::lwip_accept_r(m_sock, (struct sockaddr*) &client_addr, &sin_size);
int clientSockFD = ::lwip_accept(m_sock, (struct sockaddr*) &client_addr, &sin_size);
//printf("------> new connection client %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
if (clientSockFD == -1) {
SocketException se(errno);
Expand Down Expand Up @@ -117,7 +117,7 @@ int Socket::bind(uint16_t port, uint32_t address) {
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(address);
serverAddress.sin_port = htons(port);
int rc = ::lwip_bind_r(m_sock, (struct sockaddr*) &serverAddress, sizeof(serverAddress));
int rc = ::lwip_bind(m_sock, (struct sockaddr*) &serverAddress, sizeof(serverAddress));
if (rc != 0) {
ESP_LOGE(LOG_TAG, "<< bind: bind[socket=%d]: %d: %s", m_sock, errno, strerror(errno));
return rc;
Expand All @@ -144,7 +144,7 @@ int Socket::close() {
rc = 0;
if (m_sock != -1) {
ESP_LOGD(LOG_TAG, "Calling lwip_close on %d", m_sock);
rc = ::lwip_close_r(m_sock);
rc = ::lwip_close(m_sock);
if (rc != 0) {
ESP_LOGE(LOG_TAG, "Error with lwip_close: %d", rc);
}
Expand All @@ -170,7 +170,7 @@ int Socket::connect(struct in_addr address, uint16_t port) {
inet_ntop(AF_INET, &address, msg, sizeof(msg));
ESP_LOGD(LOG_TAG, "Connecting to %s:[%d]", msg, port);
createSocket();
int rc = ::lwip_connect_r(m_sock, (struct sockaddr*) &serverAddress, sizeof(struct sockaddr_in));
int rc = ::lwip_connect(m_sock, (struct sockaddr*) &serverAddress, sizeof(struct sockaddr_in));
if (rc == -1) {
ESP_LOGE(LOG_TAG, "connect_cpp: Error: %s", strerror(errno));
close();
Expand Down Expand Up @@ -268,7 +268,7 @@ int Socket::listen(uint16_t port, bool isDatagram, bool reuseAddress) {
// For a datagram socket, we don't execute a listen call. That is is only for connection oriented
// sockets.
if (!isDatagram) {
rc = ::lwip_listen_r(m_sock, 5);
rc = ::lwip_listen(m_sock, 5);
if (rc == -1) {
ESP_LOGE(LOG_TAG, "<< listen: %s", strerror(errno));
return rc;
Expand Down Expand Up @@ -356,7 +356,7 @@ size_t Socket::receive(uint8_t* data, size_t length, bool exact) {
ESP_LOGD(LOG_TAG, "rc=%d, MBEDTLS_ERR_SSL_WANT_READ=%d", rc, MBEDTLS_ERR_SSL_WANT_READ);
} while (rc == MBEDTLS_ERR_SSL_WANT_WRITE || rc == MBEDTLS_ERR_SSL_WANT_READ);
} else {
rc = ::lwip_recv_r(m_sock, data, length, 0);
rc = ::lwip_recv(m_sock, data, length, 0);
if (rc == -1) {
ESP_LOGE(LOG_TAG, "receive: %s", strerror(errno));
}
Expand All @@ -374,7 +374,7 @@ size_t Socket::receive(uint8_t* data, size_t length, bool exact) {
rc = mbedtls_ssl_read(&m_sslContext, data, amountToRead);
} while (rc == MBEDTLS_ERR_SSL_WANT_WRITE || rc == MBEDTLS_ERR_SSL_WANT_READ);
} else {
rc = ::lwip_recv_r(m_sock, data, amountToRead, 0);
rc = ::lwip_recv(m_sock, data, amountToRead, 0);
}
if (rc == -1) {
ESP_LOGE(LOG_TAG, "receive: %s", strerror(errno));
Expand Down Expand Up @@ -432,7 +432,7 @@ int Socket::send(const uint8_t* data, size_t length) const {
}
}
} else {
rc = ::lwip_send_r(m_sock, data, length, 0);
rc = ::lwip_send(m_sock, data, length, 0);
if ((rc < 0) && (errno != EAGAIN)) {
// no cure for errors other than EAGAIN - log and exit
ESP_LOGE(LOG_TAG, "send: socket=%d, %s", m_sock, strerror(errno));
Expand Down
4 changes: 2 additions & 2 deletions cpp_utils/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ void WiFi::dump() {
ESP_LOGD(LOG_TAG, "WiFi Dump");
ESP_LOGD(LOG_TAG, "---------");
char ipAddrStr[30];
ip_addr_t ip = ::dns_getserver(0);
inet_ntop(AF_INET, &ip, ipAddrStr, sizeof(ipAddrStr));
const ip_addr_t* ip = ::dns_getserver(0);
inet_ntop(AF_INET, ip, ipAddrStr, sizeof(ipAddrStr));
ESP_LOGD(LOG_TAG, "DNS Server[0]: %s", ipAddrStr);
} // dump

Expand Down