Skip to content

Commit 9c4eeb8

Browse files
authored
Merge branch 'master' into master
2 parents 522df52 + 7cdfb8b commit 9c4eeb8

File tree

102 files changed

+110
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+110
-52
lines changed

libraries/AsyncUDP/src/AsyncUDP.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ void AsyncUDPMessage::flush()
277277
_index = 0;
278278
}
279279

280+
AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){
281+
_udp = packet._udp;
282+
_pb = packet._pb;
283+
_if = packet._if;
284+
_data = packet._data;
285+
_len = packet._len;
286+
_index = 0;
287+
288+
pbuf_ref(_pb);
289+
}
280290

281291
AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif * ntif)
282292
{
@@ -479,6 +489,7 @@ AsyncUDP::AsyncUDP()
479489
{
480490
_pcb = NULL;
481491
_connected = false;
492+
_lastErr = ERR_OK;
482493
_handler = NULL;
483494
}
484495

@@ -517,8 +528,8 @@ bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port)
517528
}
518529
close();
519530
UDP_MUTEX_LOCK();
520-
err_t err = _udp_connect(_pcb, addr, port);
521-
if(err != ERR_OK) {
531+
_lastErr = _udp_connect(_pcb, addr, port);
532+
if(_lastErr != ERR_OK) {
522533
UDP_MUTEX_UNLOCK();
523534
return false;
524535
}
@@ -646,7 +657,7 @@ size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * add
646657
if(len > CONFIG_TCP_MSS) {
647658
len = CONFIG_TCP_MSS;
648659
}
649-
err_t err = ERR_OK;
660+
_lastErr = ERR_OK;
650661
pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
651662
if(pbt != NULL) {
652663
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
@@ -656,16 +667,16 @@ size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * add
656667
void * nif = NULL;
657668
tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif);
658669
if(!nif){
659-
err = _udp_sendto(_pcb, pbt, addr, port);
670+
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
660671
} else {
661-
err = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
672+
_lastErr = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
662673
}
663674
} else {
664-
err = _udp_sendto(_pcb, pbt, addr, port);
675+
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
665676
}
666677
UDP_MUTEX_UNLOCK();
667678
pbuf_free(pbt);
668-
if(err < ERR_OK) {
679+
if(_lastErr < ERR_OK) {
669680
return 0;
670681
}
671682
return len;
@@ -682,9 +693,8 @@ void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t po
682693
if(_handler) {
683694
AsyncUDPPacket packet(this, this_pb, addr, port, netif);
684695
_handler(packet);
685-
} else {
686-
pbuf_free(this_pb);
687696
}
697+
pbuf_free(this_pb);
688698
}
689699
}
690700

@@ -870,6 +880,10 @@ bool AsyncUDP::connected()
870880
return _connected;
871881
}
872882

883+
esp_err_t AsyncUDP::lastErr() {
884+
return _lastErr;
885+
}
886+
873887
void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void * arg)
874888
{
875889
onPacket(std::bind(cb, arg, std::placeholders::_1));

libraries/AsyncUDP/src/AsyncUDP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class AsyncUDPPacket : public Stream
5858
size_t _len;
5959
size_t _index;
6060
public:
61+
AsyncUDPPacket(AsyncUDPPacket &packet);
6162
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
6263
virtual ~AsyncUDPPacket();
6364

@@ -95,6 +96,7 @@ class AsyncUDP : public Print
9596
udp_pcb *_pcb;
9697
//xSemaphoreHandle _lock;
9798
bool _connected;
99+
esp_err_t _lastErr;
98100
AuPacketHandlerFunction _handler;
99101

100102
bool _init();
@@ -144,6 +146,7 @@ class AsyncUDP : public Print
144146
IPAddress listenIP();
145147
IPv6Address listenIPv6();
146148
bool connected();
149+
esp_err_t lastErr();
147150
operator bool();
148151

149152
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif);

libraries/BLE/src/BLEAdvertisedDevice.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
2525
m_manufacturerData = "";
2626
m_name = "";
2727
m_rssi = -9999;
28+
m_serviceUUIDs = {};
2829
m_serviceData = {};
2930
m_serviceDataUUIDs = {};
3031
m_txPower = 0;
@@ -34,8 +35,6 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
3435
m_haveManufacturerData = false;
3536
m_haveName = false;
3637
m_haveRSSI = false;
37-
m_haveServiceData = false;
38-
m_haveServiceUUID = false;
3938
m_haveTXPower = false;
4039

4140
} // BLEAdvertisedDevice
@@ -107,19 +106,15 @@ BLEScan* BLEAdvertisedDevice::getScan() {
107106
* @return Number of service data discovered.
108107
*/
109108
int BLEAdvertisedDevice::getServiceDataCount() {
110-
if (m_haveServiceData)
111-
return m_serviceData.size();
112-
else
113-
return 0;
114-
109+
return m_serviceData.size();
115110
} //getServiceDataCount
116111

117112
/**
118113
* @brief Get the service data.
119114
* @return The ServiceData of the advertised device.
120115
*/
121116
std::string BLEAdvertisedDevice::getServiceData() {
122-
return m_serviceData[0];
117+
return m_serviceData.empty() ? std::string() : m_serviceData.front();
123118
} //getServiceData
124119

125120
/**
@@ -130,12 +125,20 @@ std::string BLEAdvertisedDevice::getServiceData(int i) {
130125
return m_serviceData[i];
131126
} //getServiceData
132127

128+
/**
129+
* @brief Get the number of service data UUIDs.
130+
* @return Number of service data UUIDs discovered.
131+
*/
132+
int BLEAdvertisedDevice::getServiceDataUUIDCount() {
133+
return m_serviceDataUUIDs.size();
134+
} //getServiceDataUUIDCount
135+
133136
/**
134137
* @brief Get the service data UUID.
135138
* @return The service data UUID.
136139
*/
137140
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
138-
return m_serviceDataUUIDs[0];
141+
return m_serviceDataUUIDs.empty() ? BLEUUID() : m_serviceDataUUIDs.front();
139142
} // getServiceDataUUID
140143

141144
/**
@@ -146,12 +149,20 @@ BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) {
146149
return m_serviceDataUUIDs[i];
147150
} // getServiceDataUUID
148151

152+
/**
153+
* @brief Get the number of service UUIDs.
154+
* @return Number of service UUIDs discovered.
155+
*/
156+
int BLEAdvertisedDevice::getServiceUUIDCount() {
157+
return m_serviceUUIDs.size();
158+
} //getServiceUUIDCount
159+
149160
/**
150161
* @brief Get the Service UUID.
151162
* @return The Service UUID of the advertised device.
152163
*/
153164
BLEUUID BLEAdvertisedDevice::getServiceUUID() {
154-
return m_serviceUUIDs[0];
165+
return m_serviceUUIDs.empty() ? BLEUUID() : m_serviceUUIDs.front();
155166
} // getServiceUUID
156167

157168
/**
@@ -167,7 +178,7 @@ BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) {
167178
* @return Return true if service is advertised
168179
*/
169180
bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){
170-
for (int i = 0; i < m_serviceUUIDs.size(); i++) {
181+
for (int i = 0; i < getServiceUUIDCount(); i++) {
171182
if (m_serviceUUIDs[i].equals(uuid)) return true;
172183
}
173184
return false;
@@ -224,7 +235,7 @@ bool BLEAdvertisedDevice::haveRSSI() {
224235
* @return True if there is a service data value present.
225236
*/
226237
bool BLEAdvertisedDevice::haveServiceData() {
227-
return m_haveServiceData;
238+
return !m_serviceData.empty();
228239
} // haveServiceData
229240

230241

@@ -233,7 +244,7 @@ bool BLEAdvertisedDevice::haveServiceData() {
233244
* @return True if there is a service UUID value present.
234245
*/
235246
bool BLEAdvertisedDevice::haveServiceUUID() {
236-
return m_haveServiceUUID;
247+
return !m_serviceUUIDs.empty();
237248
} // haveServiceUUID
238249

239250

@@ -486,7 +497,6 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
486497
*/
487498
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
488499
m_serviceUUIDs.push_back(serviceUUID);
489-
m_haveServiceUUID = true;
490500
log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
491501
} // setServiceUUID
492502

@@ -496,7 +506,6 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
496506
* @param [in] data ServiceData value.
497507
*/
498508
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
499-
m_haveServiceData = true; // Set the flag that indicates we have service data.
500509
m_serviceData.push_back(serviceData); // Save the service data that we received.
501510
} //setServiceData
502511

@@ -506,7 +515,6 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
506515
* @param [in] data ServiceDataUUID value.
507516
*/
508517
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
509-
m_haveServiceData = true; // Set the flag that indicates we have service data.
510518
m_serviceDataUUIDs.push_back(uuid);
511519
log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
512520
} // setServiceDataUUID
@@ -542,7 +550,7 @@ std::string BLEAdvertisedDevice::toString() {
542550
free(pHex);
543551
}
544552
if (haveServiceUUID()) {
545-
for (int i=0; i < m_serviceUUIDs.size(); i++) {
553+
for (int i=0; i < getServiceUUIDCount(); i++) {
546554
res += ", serviceUUID: " + getServiceUUID(i).toString();
547555
}
548556
}

libraries/BLE/src/BLEAdvertisedDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class BLEAdvertisedDevice {
4242
BLEUUID getServiceUUID();
4343
BLEUUID getServiceUUID(int i);
4444
int getServiceDataCount();
45+
int getServiceDataUUIDCount();
46+
int getServiceUUIDCount();
4547
int8_t getTXPower();
4648
uint8_t* getPayload();
4749
size_t getPayloadLength();
@@ -83,8 +85,6 @@ class BLEAdvertisedDevice {
8385
bool m_haveManufacturerData;
8486
bool m_haveName;
8587
bool m_haveRSSI;
86-
bool m_haveServiceData;
87-
bool m_haveServiceUUID;
8888
bool m_haveTXPower;
8989

9090

libraries/BLE/src/BLEClient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ BLEClient::~BLEClient() {
6060
delete myPair.second;
6161
}
6262
m_servicesMap.clear();
63+
m_servicesMapByInstID.clear();
6364
} // ~BLEClient
6465

6566

libraries/BLE/src/BLERemoteCharacteristic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
5252
*/
5353
BLERemoteCharacteristic::~BLERemoteCharacteristic() {
5454
removeDescriptors(); // Release resources for any descriptor information we may have allocated.
55+
free(m_rawData);
5556
} // ~BLERemoteCharacteristic
5657

5758

libraries/ESPmDNS/src/ESPmDNS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MDNSResponder {
8484
void enableArduino(uint16_t port=3232, bool auth=false);
8585
void disableArduino();
8686

87-
void enableWorkstation(wifi_interface_t interface=ESP_IF_WIFI_STA);
87+
void enableWorkstation(wifi_interface_t interface=WIFI_IF_STA);
8888
void disableWorkstation();
8989

9090
IPAddress queryHost(char *host, uint32_t timeout=2000);

libraries/HTTPClient/src/HTTPClient.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,20 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
269269

270270
// get port
271271
index = host.indexOf(':');
272+
String the_host;
272273
if(index >= 0) {
273-
_host = host.substring(0, index); // hostname
274+
the_host = host.substring(0, index); // hostname
274275
host.remove(0, (index + 1)); // remove hostname + :
275276
_port = host.toInt(); // get port
276277
} else {
277-
_host = host;
278+
the_host = host;
278279
}
280+
if(_host != the_host && connected()){
281+
log_d("switching host from '%s' to '%s'. disconnecting first", _host.c_str(), the_host.c_str());
282+
_canReuse = false;
283+
disconnect(true);
284+
}
285+
_host = the_host;
279286
_uri = url;
280287
log_d("host: %s port: %d url: %s", _host.c_str(), _port, _uri.c_str());
281288
return true;
@@ -1318,9 +1325,9 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)
13181325
readBytes = buff_size;
13191326
}
13201327

1321-
// stop if no more reading
1322-
if (readBytes == 0)
1323-
break;
1328+
// stop if no more reading
1329+
if (readBytes == 0)
1330+
break;
13241331

13251332
// read data
13261333
int bytesRead = _client->readBytes(buff, readBytes);

libraries/WebServer/src/Parsing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,14 @@ void WebServer::_uploadWriteByte(uint8_t b){
303303
}
304304

305305
int WebServer::_uploadReadByte(WiFiClient& client){
306-
if (!client.connected()) return -1;
307306
int res = client.read();
308307
if(res < 0) {
309308
// keep trying until you either read a valid byte or timeout
310309
unsigned long startMillis = millis();
311310
long timeoutIntervalMillis = client.getTimeout();
312311
boolean timedOut = false;
313312
for(;;) {
313+
if (!client.connected()) return -1;
314314
// loosely modeled after blinkWithoutDelay pattern
315315
while(!timedOut && !client.available() && client.connected()){
316316
delay(2);

libraries/WebServer/src/WebServer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ void WebServer::_prepareHeader(String& response, int code, const char* content_t
412412
}
413413
if (_corsEnabled) {
414414
sendHeader(String(FPSTR("Access-Control-Allow-Origin")), String("*"));
415+
sendHeader(String(FPSTR("Access-Control-Allow-Methods")), String("*"));
416+
sendHeader(String(FPSTR("Access-Control-Allow-Headers")), String("*"));
415417
}
416418
sendHeader(String(F("Connection")), String(F("close")));
417419

0 commit comments

Comments
 (0)