1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +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

@ -0,0 +1,127 @@
/*
* TransmissionResult
* Copyright (C) 2018 Anders Löfgren
*
* License (MIT license):
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "ESP8266WiFiMesh.h"
#include <assert.h>
void ESP8266WiFiMesh::verboseModePrint(const String &stringToPrint, bool newline)
{
if(_verboseMode)
{
if(newline)
Serial.println(stringToPrint);
else
Serial.print(stringToPrint);
}
}
/**
* Note that using a base higher than 16 increases likelihood of randomly generating SSID strings containing controversial words.
*
* @param number The number to convert to a string with radix "base".
* @param base The radix to convert "number" into. Must be between 2 and 36.
* @returns A string of "number" encoded in radix "base".
*/
String ESP8266WiFiMesh::uint64ToString(uint64_t number, byte base)
{
assert(2 <= base && base <= 36);
String result = "";
while(number > 0)
{
result = String((uint32_t)(number % base), base) + result;
number /= base;
}
return (result == "" ? "0" : result);
}
/**
* Note that using a base higher than 16 increases likelihood of randomly generating SSID strings containing controversial words.
*
* @param string The string to convert to uint64_t. String must use radix "base".
* @param base The radix of "string". Must be between 2 and 36.
* @returns A uint64_t of the string, using radix "base" during decoding.
*/
uint64_t ESP8266WiFiMesh::stringToUint64(const String &string, byte base)
{
assert(2 <= base && base <= 36);
uint64_t result = 0;
char currentCharacter[1];
for(uint32_t i = 0; i < string.length(); i++)
{
result *= base;
currentCharacter[0] = string.charAt(i);
result += strtoul(currentCharacter, NULL, base);
}
return result;
}
/**
* Calculate the current lwIP version number and store the numbers in the _lwipVersion array.
* lwIP version can be changed in the "Tools" menu of Arduino IDE.
*/
void ESP8266WiFiMesh::storeLwipVersion()
{
// ESP.getFullVersion() looks something like:
// SDK:2.2.1(cfd48f3)/Core:win-2.5.0-dev/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-10-g0c0d8c2)/BearSSL:94e9704
String fullVersion = ESP.getFullVersion();
int i = fullVersion.indexOf("lwIP:") + 5;
char currentChar = fullVersion.charAt(i);
for(int versionPart = 0; versionPart < 3; versionPart++)
{
while(!isdigit(currentChar))
{
currentChar = fullVersion.charAt(++i);
}
while(isdigit(currentChar))
{
_lwipVersion[versionPart] = 10 * _lwipVersion[versionPart] + (currentChar - '0'); // Left shift and add digit value, in base 10.
currentChar = fullVersion.charAt(++i);
}
}
}
/**
* Check if the code is running on a version of lwIP that is at least minLwipVersion.
*/
bool ESP8266WiFiMesh::atLeastLwipVersion(const uint32_t minLwipVersion[3])
{
for(int versionPart = 0; versionPart < 3; versionPart++)
{
if(_lwipVersion[versionPart] > minLwipVersion[versionPart])
return true;
else if(_lwipVersion[versionPart] < minLwipVersion[versionPart])
return false;
}
return true;
}