1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-09-09 18:40:33 +03:00

Update of mesh network library. (#4718)

* Make mesh network actually usable. Make mesh network use static IP during initial connection to speed up connection time. Add separate handlers for requests and responses. Add network password. Provide more detailed code example. Add optional verbose mode. Improve comments. Add readme file.

* Fix compiler warnings. Fix code style of HelloMesh.ino to avoid upsetting Travis.

* Remove stray spaces.

* Make mesh network WiFi password settable via the ESP8266WiFiMesh constructor. Make use of static IP optional by moving static IP initialization code to setStaticIP method. Increase scanning interval from one to two seconds in the HelloMesh.ino example to increase chances of successful connections. Update comments. Update README.rst.

* Increase specificity in the conditions of the waitForClientTransmission method (renamed from waitForClient) to avoid issues related to #4626 , #4728 and #4754 in the future.

* Improve most parts of the library to achieve better performance and greatly increase flexibility.

Changes:
* Make WiFi-connection related variables static to allow for the use of multiple ESP8266WiFiMesh instances on a single node (useful e.g. when communicating with several different mesh networks).
* Make it possible to choose AP port, which is helpful when using multiple ESP8266WiFiMesh AP:s on a single node.
* Add user-customizable network filter.
* Make activation of own AP optional for each mesh node.
* Add ways to change mesh network name and node id for existing ESP8266WiFiMesh instances.
* Add verboseModePrint method to clean up the code.
* Add reactivation of static IP after successful data transfers to speed up re-connection attempts.
* Add empty_IP constant which can be used to check if static IP is disabled for a ESP8266WiFiMesh instance.
* Remove the WiFiClient _client class variable in ESP8266WiFiMesh since there is no need to save _client in the class instance.
* Add transmission status as a return value from attemptTransmission.
* Pass calling ESP8266WiFiMesh instance pointer to callback functions to allow for greater range of actions in callbacks.
* Make transmission message a class variable to allow it to be stored in the class and accessed from callbacks.
* Add getters for mesh name and node id to ESP8266WiFiMesh.
* Add getter and setter for networkFilter to ESP8266WiFiMesh.
* Increase range of available node_id:s by changing the type to String and adding functions to convert between String and uint64_t using a customizable radix between 2 and 36.
* Make it possible to connect to several nodes during each attemptTransmission call.
* Add static connection_queue and latest_transmission_outcomes vectors to the ESP8266WiFiMesh class, a NetworkInfo class and a TransmissionResult class to aid in bookkeeping when connecting to several AP:s during one attemptTransmission call.
* Make wifi_channel and BSSID optional when connecting to an AP (though excluding them will slow down the connection process).
* Add optional scan and static ip optimizations available in Arduino core for ESP8266 version 2.4.2.
* Add functions to check lwIP version in order to enable WiFi optimizations only available with lwIP2.
* Add concluding_disconnect, initial_disconnect and no_scan options to the attemptTransmission method.
* Update documentation.

* Improve README.rst formatting.

* Further improve README.rst.

* Even further improve README.rst.

* Make source code comments Doxygen compatible. Improve README file and change its file format to .md.

* Add temporary compatibility layer to ensure backwards compatibility with the old mesh network library API until the next major core release (2.5.0).

* Polish documentation slightly.

* Add scan_all_wifi_channels option to attemptTransmission method.

* - Add getter and setter for the WiFi channel of a ESP8266WiFiMesh instance.
- Separate methods for changing mesh name and node id from AP control methods.
- Add methods getAPController and isAPController to better handle situations when multiple ESP8266WiFiMesh instances take turns to be in control of the AP.
- Create separate UtilityMethods.cpp file for utility methods.
- Improve code efficiency and robustness, e.g. by passing arguments by reference instead of by value for non-POD types and employing typedefs.
- Update README.md.

* Make the code more stylish.

* Update README.md with the new ESP8266WiFiMesh constructor documentation.

* Make attemptScan method in CompatibilityLayer use reference as argument.

* Make it possible to use const String as argument to attemptScan.

* - Make code use camelCase instead of snake_case.
- Improve documentation.

* Rename Uint64ToString to uint64ToString and StringToUint64 to stringToUint64, since they are methods.
This commit is contained in:
aerlon
2018-08-01 04:46:20 +02:00
committed by Develo
parent b1f0435fb3
commit 7d5997dad1
12 changed files with 1535 additions and 156 deletions

View File

@@ -1,9 +1,9 @@
/*
ESP8266WiFiMesh.cpp - Mesh network node
Sets up a Mesh Node which acts as a router, creating a Mesh Network with other nodes. All information
is passed in both directions, but it is up to the user what the data sent is and how it is dealt with.
Sets up a Mesh Node which acts as a router, creating a Mesh Network with other nodes.
Copyright (c) 2015 Julian Fell. All rights reserved.
Updated 2018 by Anders Löfgren.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,151 +18,555 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <assert.h>
#include "ESP8266WiFiMesh.h"
#define SSID_PREFIX "Mesh_Node"
#define SERVER_IP_ADDR "192.168.4.1"
#define SERVER_PORT 4011
#define SERVER_IP_ADDR "192.168.4.1"
ESP8266WiFiMesh::ESP8266WiFiMesh(uint32_t chip_id, std::function<String(String)> handler)
: _server(SERVER_PORT)
const IPAddress ESP8266WiFiMesh::emptyIP = IPAddress();
const uint32_t ESP8266WiFiMesh::lwipVersion203Signature[3] {2,0,3};
String ESP8266WiFiMesh::lastSSID = "";
bool ESP8266WiFiMesh::staticIPActivated = false;
// IP needs to be at the same subnet as server gateway (192.168.4 in this case). Station gateway ip must match ip for server.
IPAddress ESP8266WiFiMesh::staticIP = emptyIP;
IPAddress ESP8266WiFiMesh::gateway = IPAddress(192,168,4,1);
IPAddress ESP8266WiFiMesh::subnetMask = IPAddress(255,255,255,0);
ESP8266WiFiMesh *ESP8266WiFiMesh::apController = nullptr;
std::vector<NetworkInfo> ESP8266WiFiMesh::connectionQueue = {};
std::vector<TransmissionResult> ESP8266WiFiMesh::latestTransmissionOutcomes = {};
ESP8266WiFiMesh::~ESP8266WiFiMesh()
{
_chip_id = chip_id;
_ssid = String( String( SSID_PREFIX ) + String( _chip_id ) );
_ssid_prefix = String( SSID_PREFIX );
_handler = handler;
if(isAPController())
{
apController = nullptr;
}
}
ESP8266WiFiMesh::ESP8266WiFiMesh(ESP8266WiFiMesh::requestHandlerType requestHandler, ESP8266WiFiMesh::responseHandlerType responseHandler,
ESP8266WiFiMesh::networkFilterType networkFilter, const String &meshPassword, const String &meshName,
const String &nodeID, bool verboseMode, uint8 meshWiFiChannel, int serverPort)
: _server(serverPort), _lwipVersion{0, 0, 0}
{
storeLwipVersion();
updateNetworkNames(meshName, (nodeID != "" ? nodeID : uint64ToString(ESP.getChipId())));
_requestHandler = requestHandler;
_responseHandler = responseHandler;
setWiFiChannel(meshWiFiChannel);
_serverPort = serverPort;
_meshPassword = meshPassword;
_verboseMode = verboseMode;
_networkFilter = networkFilter;
}
void ESP8266WiFiMesh::updateNetworkNames(const String &newMeshName, const String &newNodeID)
{
if(newMeshName != "")
_meshName = newMeshName;
if(newNodeID != "")
_nodeID = newNodeID;
_SSID = _meshName + _nodeID;
// Apply SSID changes to active AP.
if(isAPController())
restartAP();
}
void ESP8266WiFiMesh::begin()
{
WiFi.mode(WIFI_AP_STA);
WiFi.softAP( _ssid.c_str() );
_server.begin();
////////////////////////////<DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
if(_handler != NULL)
{
WiFi.mode(WIFI_AP_STA);
WiFi.softAP( _SSID.c_str() );
_server.begin();
}
else
{
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
WiFi.mode(WIFI_AP_STA);
#ifdef ENABLE_STATIC_IP_OPTIMIZATION
if(atLeastLwipVersion(lwipVersion203Signature))
{
verboseModePrint("lwIP version is at least 2.0.3. Static ip optimizations enabled.\n");
}
else
{
verboseModePrint("lwIP version is less than 2.0.3. Static ip optimizations DISABLED.\n");
}
#endif
}
}
void ESP8266WiFiMesh::setStaticIP(const IPAddress &newIP)
{
// Comment out the line below to remove static IP and use DHCP instead.
// DHCP makes WiFi connection happen slower, but there is no need to care about manually giving different IPs to the nodes and less need to worry about used IPs giving "Server unavailable" issues.
// Static IP has faster connection times (50 % of DHCP) and will make sending of data to a node that is already transmitting data happen more reliably.
// Note that after WiFi.config(staticIP, gateway, subnetMask) is used, static IP will always be active, even for new connections, unless WiFi.config(0u,0u,0u); is called.
WiFi.config(newIP, gateway, subnetMask);
staticIPActivated = true;
staticIP = newIP;
}
IPAddress ESP8266WiFiMesh::getStaticIP()
{
if(staticIPActivated)
return staticIP;
return emptyIP;
}
void ESP8266WiFiMesh::disableStaticIP()
{
WiFi.config(0u,0u,0u);
yield();
staticIPActivated = false;
}
void ESP8266WiFiMesh::activateAP()
{
// Deactivate active AP to avoid two servers using the same port, which can lead to crashes.
if(ESP8266WiFiMesh *currentAPController = ESP8266WiFiMesh::getAPController())
currentAPController->deactivateAP();
WiFi.softAP( _SSID.c_str(), _meshPassword.c_str(), _meshWiFiChannel ); // Note that a maximum of 5 stations can be connected at a time to each AP
_server.begin(); // Actually calls _server.stop()/_server.close() first.
apController = this;
}
void ESP8266WiFiMesh::deactivateAP()
{
if(isAPController())
{
_server.stop();
WiFi.softAPdisconnect();
// Since there is no active AP controller now, make the apController variable point to nothing.
apController = nullptr;
}
}
void ESP8266WiFiMesh::restartAP()
{
deactivateAP();
yield();
activateAP();
yield();
}
ESP8266WiFiMesh * ESP8266WiFiMesh::getAPController()
{
return apController;
}
bool ESP8266WiFiMesh::isAPController()
{
return (this == apController);
}
uint8 ESP8266WiFiMesh::getWiFiChannel()
{
return _meshWiFiChannel;
}
void ESP8266WiFiMesh::setWiFiChannel(uint8 newWiFiChannel)
{
assert(1 <= newWiFiChannel && newWiFiChannel <= 13);
_meshWiFiChannel = newWiFiChannel;
// Apply changes to active AP.
if(isAPController())
restartAP();
}
String ESP8266WiFiMesh::getMeshName() {return _meshName;}
void ESP8266WiFiMesh::setMeshName(const String &newMeshName)
{
updateNetworkNames(newMeshName);
}
String ESP8266WiFiMesh::getNodeID() {return _nodeID;}
void ESP8266WiFiMesh::setNodeID(const String &newNodeID)
{
updateNetworkNames("", newNodeID);
}
void ESP8266WiFiMesh::setSSID(const String &newMeshName, const String &newNodeID)
{
updateNetworkNames(newMeshName, newNodeID);
}
String ESP8266WiFiMesh::getMessage() {return _message;}
void ESP8266WiFiMesh::setMessage(const String &newMessage) {_message = newMessage;}
ESP8266WiFiMesh::networkFilterType ESP8266WiFiMesh::getNetworkFilter() {return _networkFilter;}
void ESP8266WiFiMesh::setNetworkFilter(ESP8266WiFiMesh::networkFilterType networkFilter) {_networkFilter = networkFilter;}
/**
* Disconnect completely from a network.
*/
void ESP8266WiFiMesh::fullStop(WiFiClient &currClient)
{
currClient.stop();
yield();
WiFi.disconnect();
yield();
}
/**
* Wait for a WiFiClient to connect
* Wait for a WiFiClient to transmit
*
* @returns: True if the client is ready, false otherwise.
*
*/
bool ESP8266WiFiMesh::waitForClient(WiFiClient curr_client, int max_wait)
bool ESP8266WiFiMesh::waitForClientTransmission(WiFiClient &currClient, int maxWait)
{
int wait = max_wait;
while(curr_client.connected() && !curr_client.available() && wait--)
delay(3);
int wait = maxWait;
while(currClient.connected() && !currClient.available() && wait--)
delay(3);
/* Return false if the client isn't ready to communicate */
if (WiFi.status() == WL_DISCONNECTED || !curr_client.connected())
return false;
return true;
/* Return false if the client isn't ready to communicate */
if (WiFi.status() == WL_DISCONNECTED && !currClient.available())
{
verboseModePrint("Disconnected!");
return false;
}
return true;
}
/**
* Send the supplied message then read back the other node's response
* and pass that to the user-supplied handler.
* Send the mesh instance's current message then read back the other node's response
* and pass that to the user-supplied responseHandler.
*
* @target_ssid The name of the AP the other node has set up.
* @message The string to send to the node.
* @returns: True if the exchange was a succes, false otherwise.
* @param currClient The client to which the message should be transmitted.
* @returns: A status code based on the outcome of the exchange.
*
*/
bool ESP8266WiFiMesh::exchangeInfo(String message, WiFiClient curr_client)
transmission_status_t ESP8266WiFiMesh::exchangeInfo(WiFiClient &currClient)
{
curr_client.println( message.c_str() );
verboseModePrint("Transmitting");
currClient.print(getMessage() + "\r");
yield();
if (!waitForClient(curr_client, 1000))
return false;
if (!waitForClientTransmission(currClient, 1000))
{
fullStop(currClient);
return TS_CONNECTION_FAILED;
}
String response = curr_client.readStringUntil('\r');
curr_client.readStringUntil('\n');
if (!currClient.available())
{
verboseModePrint("No response!");
return TS_TRANSMISSION_FAILED; // WiFi.status() != WL_DISCONNECTED so we do not want to use fullStop(currClient) here since that would force the node to scan for WiFi networks.
}
if (response.length() <= 2)
return false;
String response = currClient.readStringUntil('\r');
yield();
currClient.flush();
/* Pass data to user callback */
_handler(response);
return true;
/* Pass data to user callback */
return _responseHandler(response, *this);
}
/**
* Connect to the AP at ssid, send them a message then disconnect.
* Handle data transfer process with a connected AP.
*
* @target_ssid The name of the AP the other node has set up.
* @message The string to send to the node.
*
* @returns: A status code based on the outcome of the data transfer attempt.
*/
void ESP8266WiFiMesh::connectToNode(String target_ssid, String message)
transmission_status_t ESP8266WiFiMesh::attemptDataTransfer()
{
WiFiClient curr_client;
WiFi.begin( target_ssid.c_str() );
int wait = 1500;
while((WiFi.status() == WL_DISCONNECTED) && wait--)
delay(3);
/* If the connection timed out */
if (WiFi.status() != 3)
return;
/* Connect to the node's server */
if (!curr_client.connect(SERVER_IP_ADDR, SERVER_PORT))
return;
if (!exchangeInfo(message, curr_client))
return;
curr_client.stop();
WiFi.disconnect();
// Unlike WiFi.mode(WIFI_AP);, WiFi.mode(WIFI_AP_STA); allows us to stay connected to the AP we connected to in STA mode, at the same time as we can receive connections from other stations.
// We cannot send data to the AP in STA_AP mode though, that requires STA mode.
// Switching to STA mode will disconnect all stations connected to the node AP (though they can request a reconnect even while we are in STA mode).
WiFi.mode(WIFI_STA);
delay(1);
transmission_status_t transmissionOutcome = attemptDataTransferKernel();
WiFi.mode(WIFI_AP_STA);
delay(1);
return transmissionOutcome;
}
void ESP8266WiFiMesh::attemptScan(String message)
/**
* Helper function that contains the core functionality for the data transfer process with a connected AP.
*
* @returns: A status code based on the outcome of the data transfer attempt.
*/
transmission_status_t ESP8266WiFiMesh::attemptDataTransferKernel()
{
/* Scan for APs */
int n = WiFi.scanNetworks();
WiFiClient currClient;
/* Connect to the node's server */
if (!currClient.connect(SERVER_IP_ADDR, _serverPort))
{
fullStop(currClient);
verboseModePrint("Server unavailable");
return TS_CONNECTION_FAILED;
}
for (int i = 0; i < n; ++i) {
String current_ssid = WiFi.SSID(i);
int index = current_ssid.indexOf( _ssid_prefix );
uint32_t target_chip_id = (current_ssid.substring(index + _ssid_prefix.length())).toInt();
transmission_status_t transmissionOutcome = exchangeInfo(currClient);
if (transmissionOutcome <= 0)
{
verboseModePrint("Transmission failed during exchangeInfo.");
return transmissionOutcome;
}
currClient.stop();
yield();
/* Connect to any _suitable_ APs which contain _ssid_prefix */
if (index >= 0 && (target_chip_id < _chip_id)) {
return transmissionOutcome;
}
WiFi.mode(WIFI_STA);
delay(100);
connectToNode(current_ssid, message);
WiFi.mode(WIFI_AP_STA);
delay(100);
}
}
void ESP8266WiFiMesh::initiateConnectionToAP(const String &targetSSID, int targetChannel, uint8_t *targetBSSID)
{
if(targetChannel == NETWORK_INFO_DEFAULT_INT)
WiFi.begin( targetSSID.c_str(), _meshPassword.c_str() ); // Without giving channel and BSSID, connection time is longer.
else if(targetBSSID == NULL)
WiFi.begin( targetSSID.c_str(), _meshPassword.c_str(), targetChannel ); // Without giving channel and BSSID, connection time is longer.
else
WiFi.begin( targetSSID.c_str(), _meshPassword.c_str(), targetChannel, targetBSSID );
}
/**
* Connect to the AP at SSID and transmit the mesh instance's current message.
*
* @param targetSSID The name of the AP the other node has set up.
* @param targetChannel The WiFI channel of the AP the other node has set up.
* @param targetBSSID The mac address of the AP the other node has set up.
* @returns: A status code based on the outcome of the connection and data transfer process.
*
*/
transmission_status_t ESP8266WiFiMesh::connectToNode(const String &targetSSID, int targetChannel, uint8_t *targetBSSID)
{
if(staticIPActivated && lastSSID != "" && lastSSID != targetSSID) // So we only do this once per connection, in case there is a performance impact.
{
#ifdef ENABLE_STATIC_IP_OPTIMIZATION
if(atLeastLwipVersion(lwipVersion203Signature))
{
// Can be used with Arduino core for ESP8266 version 2.4.2 or higher with lwIP2 enabled to keep static IP on even during network switches.
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_AP_STA);
yield();
}
else
{
// Disable static IP so that we can connect to other servers via DHCP (DHCP is slower but required for connecting to more than one server, it seems (possible bug?)).
disableStaticIP();
verboseModePrint("\nConnecting to a different network. Static IP deactivated to make this possible.");
}
#else
// Disable static IP so that we can connect to other servers via DHCP (DHCP is slower but required for connecting to more than one server, it seems (possible bug?)).
disableStaticIP();
verboseModePrint("\nConnecting to a different network. Static IP deactivated to make this possible.");
#endif
}
lastSSID = targetSSID;
verboseModePrint("Connecting... ", false);
initiateConnectionToAP(targetSSID, targetChannel, targetBSSID);
int connectionStartTime = millis();
int attemptNumber = 1;
int waitingTime = millis() - connectionStartTime;
while((WiFi.status() == WL_DISCONNECTED) && waitingTime <= 10000)
{
if(waitingTime > attemptNumber * 10000) // 10000 can be lowered if you want to limit the time allowed for each connection attempt.
{
verboseModePrint("... ", false);
WiFi.disconnect();
yield();
initiateConnectionToAP(targetSSID, targetChannel, targetBSSID);
attemptNumber++;
}
delay(1);
waitingTime = millis() - connectionStartTime;
}
verboseModePrint(String(waitingTime));
/* If the connection timed out */
if (WiFi.status() != WL_CONNECTED)
{
verboseModePrint("Timeout");
return TS_CONNECTION_FAILED;
}
return attemptDataTransfer();
}
void ESP8266WiFiMesh::attemptTransmission(const String &message, bool concludingDisconnect, bool initialDisconnect, bool noScan, bool scanAllWiFiChannels)
{
setMessage(message);
if(initialDisconnect)
{
WiFi.disconnect();
yield();
}
latestTransmissionOutcomes.clear();
if(WiFi.status() == WL_CONNECTED)
{
transmission_status_t transmissionResult = attemptDataTransfer();
latestTransmissionOutcomes.push_back(TransmissionResult(connectionQueue.back(), transmissionResult));
}
else
{
if(!noScan)
{
verboseModePrint("Scanning... ", false);
/* Scan for APs */
connectionQueue.clear();
// If scanAllWiFiChannels is true or Arduino core for ESP8266 version < 2.4.2 scanning will cause the WiFi radio to cycle through all WiFi channels.
// This means existing WiFi connections are likely to break or work poorly if done frequently.
int n = 0;
#ifdef ENABLE_WIFI_SCAN_OPTIMIZATION
if(scanAllWiFiChannels)
{
n = WiFi.scanNetworks();
}
else
{
// Scan function argument overview: scanNetworks(bool async = false, bool show_hidden = false, uint8 channel = 0, uint8* ssid = NULL)
n = WiFi.scanNetworks(false, false, _meshWiFiChannel);
}
#else
n = WiFi.scanNetworks();
#endif
_networkFilter(n, *this); // Update the connectionQueue.
}
for(NetworkInfo &currentNetwork : connectionQueue)
{
WiFi.disconnect();
yield();
String currentSSID = "";
int currentWiFiChannel = NETWORK_INFO_DEFAULT_INT;
uint8_t *currentBSSID = NULL;
// If an SSID has been assigned, it is prioritized over an assigned networkIndex since the networkIndex is more likely to change.
if(currentNetwork.SSID != "")
{
currentSSID = currentNetwork.SSID;
currentWiFiChannel = currentNetwork.wifiChannel;
currentBSSID = currentNetwork.BSSID;
}
else // Use only networkIndex
{
currentSSID = WiFi.SSID(currentNetwork.networkIndex);
currentWiFiChannel = WiFi.channel(currentNetwork.networkIndex);
currentBSSID = WiFi.BSSID(currentNetwork.networkIndex);
}
if(_verboseMode) // Avoid string generation if not required
{
verboseModePrint("AP acquired: " + currentSSID + ", Ch:" + String(currentWiFiChannel) + " ", false);
if(currentNetwork.networkIndex != NETWORK_INFO_DEFAULT_INT)
{
verboseModePrint("(" + String(WiFi.RSSI(currentNetwork.networkIndex)) + "dBm) " +
(WiFi.encryptionType(currentNetwork.networkIndex) == ENC_TYPE_NONE ? "open" : ""), false);
}
verboseModePrint("... ", false);
}
transmission_status_t transmissionResult = connectToNode(currentSSID, currentWiFiChannel, currentBSSID);
latestTransmissionOutcomes.push_back(TransmissionResult{.origin = currentNetwork, .transmissionStatus = transmissionResult});
}
}
if(WiFi.status() == WL_CONNECTED && staticIP != emptyIP && !staticIPActivated)
{
verboseModePrint("Reactivating static IP to allow for faster re-connects.");
setStaticIP(staticIP);
}
// If we do not want to be connected at end of transmission, disconnect here so we can re-enable static IP first (above).
if(concludingDisconnect)
{
WiFi.disconnect();
yield();
}
}
void ESP8266WiFiMesh::acceptRequest()
{
while (true) {
_client = _server.available();
if (!_client)
break;
////////////////////////////<DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
if(_handler != NULL)
{
while (true) {
_client = _server.available();
if (!_client)
break;
if (!waitForClient(_client, 1500)) {
continue;
}
if (!waitForClient(_client, 1500)) {
continue;
}
/* Read in request and pass it to the supplied handler */
String request = _client.readStringUntil('\r');
_client.readStringUntil('\n');
/* Read in request and pass it to the supplied handler */
String request = _client.readStringUntil('\r');
_client.readStringUntil('\n');
String response = _handler(request);
String response = _handler(request);
/* Send the response back to the client */
if (_client.connected())
_client.println(response);
}
/* Send the response back to the client */
if (_client.connected())
_client.println(response);
}
}
else
{
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
while (true) {
WiFiClient _client = _server.available();
if (!_client)
break;
if (!waitForClientTransmission(_client, 1500) || !_client.available()) {
continue;
}
/* Read in request and pass it to the supplied requestHandler */
String request = _client.readStringUntil('\r');
yield();
_client.flush();
String response = _requestHandler(request, *this);
/* Send the response back to the client */
if (_client.connected())
{
verboseModePrint("Responding");
_client.print(response + "\r");
_client.flush();
yield();
}
}
}
}