1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-13 13:01:55 +03:00

Allman now (#6080)

* switch restyle script for CI

* remove confirmation

* restyle with allman
This commit is contained in:
Allman-astyler
2019-05-13 16:41:34 +02:00
committed by david gauchard
parent 625c3a62c4
commit 98125f8860
255 changed files with 51238 additions and 42984 deletions

View File

@ -1,22 +1,22 @@
/*
Old version of 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.
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
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Old version of 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.
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
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
@ -25,13 +25,13 @@
/********************************************************************************************
* NOTE!
*
* All method signatures in this file are deprecated and will be removed in core version 2.5.0.
* If you are still using these methods, please consider migrating to the new API shown in
* the ESP8266WiFiMesh.h source file.
*
* TODO: delete this file.
NOTE!
All method signatures in this file are deprecated and will be removed in core version 2.5.0.
If you are still using these methods, please consider migrating to the new API shown in
the ESP8266WiFiMesh.h source file.
TODO: delete this file.
********************************************************************************************/
@ -40,7 +40,7 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include "ESP8266WiFiMesh.h"
@ -51,131 +51,149 @@
// DEPRECATED!
ESP8266WiFiMesh::ESP8266WiFiMesh(uint32_t chipID, ESP8266WiFiMesh::compatibilityLayerHandlerType handler)
: _server(SERVER_PORT)
: _server(SERVER_PORT)
{
_chipID = chipID;
_SSID = String( String( SSID_PREFIX ) + String( _chipID ) );
_ssidPrefix = String( SSID_PREFIX );
_handler = handler;
_chipID = chipID;
_SSID = String(String(SSID_PREFIX) + String(_chipID));
_ssidPrefix = String(SSID_PREFIX);
_handler = handler;
}
/**
* Wait for a WiFiClient to connect
*
* @returns: True if the client is ready, false otherwise.
*
*/
Wait for a WiFiClient to connect
@returns: True if the client is ready, false otherwise.
*/
// DEPRECATED!
bool ESP8266WiFiMesh::waitForClient(WiFiClient &currClient, int maxWait)
{
int wait = maxWait;
while(currClient.connected() && !currClient.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 || !currClient.connected())
return false;
return true;
/* Return false if the client isn't ready to communicate */
if (WiFi.status() == WL_DISCONNECTED || !currClient.connected())
{
return false;
}
return true;
}
/**
* Send the supplied message then read back the other node's response
* and pass that to the user-supplied handler.
*
* @message The string to send to the node.
* @returns: True if the exchange was a succes, false otherwise.
*
*/
Send the supplied message then read back the other node's response
and pass that to the user-supplied handler.
@message The string to send to the node.
@returns: True if the exchange was a succes, false otherwise.
*/
// DEPRECATED!
bool ESP8266WiFiMesh::exchangeInfo(const char *message, WiFiClient &currClient)
{
currClient.println( message );
currClient.println(message);
if (!waitForClient(currClient, 1000))
return false;
if (!waitForClient(currClient, 1000))
{
return false;
}
String response = currClient.readStringUntil('\r');
currClient.readStringUntil('\n');
String response = currClient.readStringUntil('\r');
currClient.readStringUntil('\n');
if (response.length() <= 2)
return false;
if (response.length() <= 2)
{
return false;
}
/* Pass data to user callback */
_handler(response);
return true;
/* Pass data to user callback */
_handler(response);
return true;
}
/**
* Connect to the AP at ssid, send them a message then disconnect.
*
* @targetSSID The name of the AP the other node has set up.
* @message The string to send to the node.
*
*/
Connect to the AP at ssid, send them a message then disconnect.
@targetSSID The name of the AP the other node has set up.
@message The string to send to the node.
*/
// DEPRECATED!
void ESP8266WiFiMesh::connectToNode(const String &targetSSID, const char *message)
{
WiFiClient currClient;
WiFi.begin( targetSSID.c_str() );
WiFiClient currClient;
WiFi.begin(targetSSID.c_str());
int wait = 1500;
while((WiFi.status() == WL_DISCONNECTED) && wait--)
delay(3);
int wait = 1500;
while ((WiFi.status() == WL_DISCONNECTED) && wait--)
{
delay(3);
}
/* If the connection timed out */
if (WiFi.status() != 3)
return;
/* If the connection timed out */
if (WiFi.status() != 3)
{
return;
}
/* Connect to the node's server */
if (!currClient.connect(SERVER_IP_ADDR, SERVER_PORT))
return;
/* Connect to the node's server */
if (!currClient.connect(SERVER_IP_ADDR, SERVER_PORT))
{
return;
}
if (!exchangeInfo(message, currClient))
return;
if (!exchangeInfo(message, currClient))
{
return;
}
currClient.stop();
WiFi.disconnect();
currClient.stop();
WiFi.disconnect();
}
// DEPRECATED!
void ESP8266WiFiMesh::attemptScanKernel(const char *message)
{
/* Scan for APs */
int n = WiFi.scanNetworks();
/* Scan for APs */
int n = WiFi.scanNetworks();
for (int i = 0; i < n; ++i) {
String currentSSID = WiFi.SSID(i);
int index = currentSSID.indexOf( _ssidPrefix );
uint32_t targetChipID = (currentSSID.substring(index + _ssidPrefix.length())).toInt();
for (int i = 0; i < n; ++i)
{
String currentSSID = WiFi.SSID(i);
int index = currentSSID.indexOf(_ssidPrefix);
uint32_t targetChipID = (currentSSID.substring(index + _ssidPrefix.length())).toInt();
/* Connect to any _suitable_ APs which contain _ssidPrefix */
if (index >= 0 && (targetChipID < _chipID)) {
/* Connect to any _suitable_ APs which contain _ssidPrefix */
if (index >= 0 && (targetChipID < _chipID))
{
WiFi.mode(WIFI_STA);
delay(100);
connectToNode(currentSSID, message);
WiFi.mode(WIFI_AP_STA);
delay(100);
}
}
WiFi.mode(WIFI_STA);
delay(100);
connectToNode(currentSSID, message);
WiFi.mode(WIFI_AP_STA);
delay(100);
}
}
}
// DEPRECATED!
void ESP8266WiFiMesh::attemptScan(const String &message)
{
attemptScanKernel(message.c_str());
attemptScanKernel(message.c_str());
}
// DEPRECATED!
void ESP8266WiFiMesh::attemptScan(char *message)
{
attemptScanKernel(message);
attemptScanKernel(message);
}
// DEPRECATED!
template<size_t Size>
void ESP8266WiFiMesh::attemptScan(char (&message)[Size])
{
attemptScanKernel(message);
attemptScanKernel(message);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,27 @@
/*
ESP8266WiFiMesh.h - Mesh network node
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
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
ESP8266WiFiMesh.h - Mesh network node
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
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __WIFIMESH_H__
#define __WIFIMESH_H__
#include <WiFiClient.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <functional>
#include <vector>
@ -33,342 +33,343 @@
const String WIFI_MESH_EMPTY_STRING = "";
class ESP8266WiFiMesh {
class ESP8266WiFiMesh
{
private:
String _SSID;
String _meshName;
String _nodeID;
uint16_t _serverPort;
String _meshPassword;
uint8 _meshWiFiChannel;
bool _verboseMode;
WiFiServer _server;
uint32_t _lwipVersion[3];
static const uint32_t lwipVersion203Signature[3];
String _message = WIFI_MESH_EMPTY_STRING;
bool _scanHidden = false;
bool _apHidden = false;
uint8_t _maxAPStations = 4;
int32_t _connectionAttemptTimeoutMs = 10000;
int _stationModeTimeoutMs = 5000; // int is the type used in the Arduino core for this particular API, not uint32_t, which is why we use int here.
uint32_t _apModeTimeoutMs = 4500;
String _SSID;
String _meshName;
String _nodeID;
uint16_t _serverPort;
String _meshPassword;
uint8 _meshWiFiChannel;
bool _verboseMode;
WiFiServer _server;
uint32_t _lwipVersion[3];
static const uint32_t lwipVersion203Signature[3];
String _message = WIFI_MESH_EMPTY_STRING;
bool _scanHidden = false;
bool _apHidden = false;
uint8_t _maxAPStations = 4;
int32_t _connectionAttemptTimeoutMs = 10000;
int _stationModeTimeoutMs = 5000; // int is the type used in the Arduino core for this particular API, not uint32_t, which is why we use int here.
uint32_t _apModeTimeoutMs = 4500;
static String lastSSID;
static bool staticIPActivated;
static IPAddress staticIP;
static IPAddress gateway;
static IPAddress subnetMask;
static ESP8266WiFiMesh *apController;
static String lastSSID;
static bool staticIPActivated;
static IPAddress staticIP;
static IPAddress gateway;
static IPAddress subnetMask;
static ESP8266WiFiMesh *apController;
typedef std::function<String(const String &, ESP8266WiFiMesh &)> requestHandlerType;
typedef std::function<transmission_status_t(const String &, ESP8266WiFiMesh &)> responseHandlerType;
typedef std::function<void(int, ESP8266WiFiMesh &)> networkFilterType;
requestHandlerType _requestHandler;
responseHandlerType _responseHandler;
networkFilterType _networkFilter;
void updateNetworkNames(const String &newMeshName = WIFI_MESH_EMPTY_STRING, const String &newNodeID = WIFI_MESH_EMPTY_STRING);
void verboseModePrint(const String &stringToPrint, bool newline = true);
void fullStop(WiFiClient &currClient);
void initiateConnectionToAP(const String &targetSSID, int targetChannel = NETWORK_INFO_DEFAULT_INT, uint8_t *targetBSSID = NULL);
transmission_status_t connectToNode(const String &targetSSID, int targetChannel = NETWORK_INFO_DEFAULT_INT, uint8_t *targetBSSID = NULL);
transmission_status_t exchangeInfo(WiFiClient &currClient);
bool waitForClientTransmission(WiFiClient &currClient, uint32_t maxWait);
transmission_status_t attemptDataTransfer();
transmission_status_t attemptDataTransferKernel();
void storeLwipVersion();
bool atLeastLwipVersion(const uint32_t minLwipVersion[3]);
////////////////////////////<DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
typedef std::function<String(String)> compatibilityLayerHandlerType;
String _ssidPrefix;
uint32_t _chipID;
compatibilityLayerHandlerType _handler = NULL;
WiFiClient _client;
void connectToNode(const String &targetSSID, const char *message);
bool exchangeInfo(const char *message, WiFiClient &currClient);
bool waitForClient(WiFiClient &currClient, int maxWait);
void attemptScanKernel(const char *message);
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
typedef std::function<String(const String &, ESP8266WiFiMesh &)> requestHandlerType;
typedef std::function<transmission_status_t(const String &, ESP8266WiFiMesh &)> responseHandlerType;
typedef std::function<void(int, ESP8266WiFiMesh &)> networkFilterType;
requestHandlerType _requestHandler;
responseHandlerType _responseHandler;
networkFilterType _networkFilter;
void updateNetworkNames(const String &newMeshName = WIFI_MESH_EMPTY_STRING, const String &newNodeID = WIFI_MESH_EMPTY_STRING);
void verboseModePrint(const String &stringToPrint, bool newline = true);
void fullStop(WiFiClient &currClient);
void initiateConnectionToAP(const String &targetSSID, int targetChannel = NETWORK_INFO_DEFAULT_INT, uint8_t *targetBSSID = NULL);
transmission_status_t connectToNode(const String &targetSSID, int targetChannel = NETWORK_INFO_DEFAULT_INT, uint8_t *targetBSSID = NULL);
transmission_status_t exchangeInfo(WiFiClient &currClient);
bool waitForClientTransmission(WiFiClient &currClient, uint32_t maxWait);
transmission_status_t attemptDataTransfer();
transmission_status_t attemptDataTransferKernel();
void storeLwipVersion();
bool atLeastLwipVersion(const uint32_t minLwipVersion[3]);
////////////////////////////<DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
typedef std::function<String(String)> compatibilityLayerHandlerType;
String _ssidPrefix;
uint32_t _chipID;
compatibilityLayerHandlerType _handler = NULL;
WiFiClient _client;
void connectToNode(const String &targetSSID, const char *message);
bool exchangeInfo(const char *message, WiFiClient &currClient);
bool waitForClient(WiFiClient &currClient, int maxWait);
void attemptScanKernel(const char *message);
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
public:
////////////////////////////<DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
/**
* WiFiMesh Constructor method. Creates a WiFi Mesh Node, ready to be initialised.
*
* @chipID A unique identifier number for the node.
* @handler The callback handler for dealing with received messages. Takes a string as an argument which
* is the string received from another node and returns the string to send back.
*
*/
ESP8266WiFiMesh(uint32_t chipID, compatibilityLayerHandlerType handler);
////////////////////////////<DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
/**
* Scan for other nodes, and exchange the chosen message with any that are found.
*
* @message The message to send to all other nodes.
*
*/
void attemptScan(const String &message);
void attemptScan(char *message);
template<size_t Size>
void attemptScan(char (&message)[Size]);
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
/**
WiFiMesh Constructor method. Creates a WiFi Mesh Node, ready to be initialised.
~ESP8266WiFiMesh();
/**
* WiFiMesh Constructor method. Creates a WiFi Mesh Node, ready to be initialised.
*
* @param requestHandler The callback handler for dealing with received requests. Takes a string as an argument which
* is the request string received from another node and returns the string to send back.
* @param responseHandler The callback handler for dealing with received responses. Takes a string as an argument which
* is the response string received from another node. Returns a transmission status code as a transmission_status_t.
* @param networkFilter The callback handler for deciding which WiFi networks to connect to.
* @param meshPassword The WiFi password for the mesh network.
* @param meshName The name of the mesh network. Used as prefix for the node SSID and to find other network nodes in the example network filter function.
* @param nodeID The id for this mesh node. Used as suffix for the node SSID. If set to "", the id will default to ESP.getChipId().
* @param verboseMode Determines if we should print the events occurring in the library to Serial. Off by default.
* @param meshWiFiChannel The WiFi channel used by the mesh network. Valid values are integers from 1 to 13. Defaults to 1.
* WARNING: The ESP8266 has only one WiFi channel, and the the station/client mode is always prioritized for channel selection.
* This can cause problems if several ESP8266WiFiMesh instances exist on the same ESP8266 and use different WiFi channels.
* In such a case, whenever the station of one ESP8266WiFiMesh instance connects to an AP, it will silently force the
* WiFi channel of any active AP on the ESP8266 to match that of the station. This will cause disconnects and possibly
* make it impossible for other stations to detect the APs whose WiFi channels have changed.
* @param serverPort The server port used by the AP of the ESP8266WiFiMesh instance. If multiple APs exist on a single ESP8266, each requires a separate server port.
* If two AP:s on the same ESP8266 are using the same server port, they will not be able to have both server instances active at the same time.
* This is managed automatically by the activateAP method.
*
*/
ESP8266WiFiMesh(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter,
const String &meshPassword, const String &meshName = "MeshNode_", const String &nodeID = WIFI_MESH_EMPTY_STRING, bool verboseMode = false,
uint8 meshWiFiChannel = 1, uint16_t serverPort = 4011);
/**
* A vector that contains the NetworkInfo for each WiFi network to connect to.
* The connectionQueue vector is cleared before each new scan and filled via the networkFilter callback function once the scan completes.
* WiFi connections will start with connectionQueue[0] and then incrementally proceed to higher vector positions.
* Note that old network indicies often are invalidated whenever a new WiFi network scan occurs.
*/
static std::vector<NetworkInfo> connectionQueue;
@chipID A unique identifier number for the node.
@handler The callback handler for dealing with received messages. Takes a string as an argument which
is the string received from another node and returns the string to send back.
/**
* A vector with the TransmissionResult for each AP to which a transmission was attempted during the latest attemptTransmission call.
* The latestTransmissionOutcomes vector is cleared before each new transmission attempt.
* Connection attempts are indexed in the same order they were attempted.
* Note that old network indicies often are invalidated whenever a new WiFi network scan occurs.
*/
static std::vector<TransmissionResult> latestTransmissionOutcomes;
*/
ESP8266WiFiMesh(uint32_t chipID, compatibilityLayerHandlerType handler);
/**
* @returns True if latest transmission was successful (i.e. latestTransmissionOutcomes is not empty and all entries have transmissionStatus TS_TRANSMISSION_COMPLETE). False otherwise.
*/
static bool latestTransmissionSuccessful();
/**
Scan for other nodes, and exchange the chosen message with any that are found.
/**
* Initialises the node.
*/
void begin();
@message The message to send to all other nodes.
/**
* Each AP requires a separate server port. If two AP:s are using the same server port, they will not be able to have both server instances active at the same time.
* This is managed automatically by the activateAP method.
*/
void activateAP();
void deactivateAP();
void restartAP();
*/
void attemptScan(const String &message);
void attemptScan(char *message);
/**
* Get the ESP8266WiFiMesh instance currently in control of the ESP8266 AP.
* Note that the result will be nullptr when there is no active AP controller.
* If another instance takes control over the AP after the pointer is created,
* the created pointer will still point to the old AP instance.
*
* @returns A pointer to the ESP8266WiFiMesh instance currently in control of the ESP8266 AP,
* or nullptr if there is no active AP controller.
*/
static ESP8266WiFiMesh * getAPController();
/**
* Check if this ESP8266WiFiMesh instance is in control of the ESP8266 AP.
*
* @returns True if this ESP8266WiFiMesh instance is in control of the ESP8266 AP. False otherwise.
*/
bool isAPController();
template<size_t Size>
void attemptScan(char (&message)[Size]);
/**
* Change the WiFi channel used by this ESP8266WiFiMesh instance.
* Will also change the WiFi channel for the active AP if this ESP8266WiFiMesh instance is the current AP controller and it is possible to change channel.
*
* WARNING: The ESP8266 has only one WiFi channel, and the the station/client mode is always prioritized for channel selection.
* This can cause problems if several ESP8266WiFiMesh instances exist on the same ESP8266 and use different WiFi channels.
* In such a case, whenever the station of one ESP8266WiFiMesh instance connects to an AP, it will silently force the
* WiFi channel of any active AP on the ESP8266 to match that of the station. This will cause disconnects and possibly
* make it impossible for other stations to detect the APs whose WiFi channels have changed.
*
* @param newWiFiChannel The WiFi channel to change to. Valid values are integers from 1 to 13.
*
*/
void setWiFiChannel(uint8 newWiFiChannel);
uint8 getWiFiChannel();
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
/**
* Change the mesh name used by this ESP8266WiFiMesh instance.
* Will also change the mesh name (SSID prefix) for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
*
* @param newMeshName The mesh name to change to.
*/
void setMeshName(const String &newMeshName);
String getMeshName();
/**
* Change the node id used by this ESP8266WiFiMesh instance.
* Will also change the node id (SSID suffix) for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
*
* @param newNodeID The node id to change to.
*/
void setNodeID(const String &newNodeID);
String getNodeID();
/**
* Change the SSID (mesh name + node id) used by this ESP8266WiFiMesh instance.
* Will also change the SSID for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
*
* @param newMeshName The mesh name to change to. Will be the SSID prefix.
* @param newNodeID The node id to change to. Will be the SSID suffix.
*/
void setSSID(const String &newMeshName, const String &newNodeID);
String getSSID();
/**
* Set the message that will be sent to other nodes when calling attemptTransmission.
*
* @param newMessage The message to send.
*/
void setMessage(const String &newMessage);
String getMessage();
~ESP8266WiFiMesh();
/**
* If AP connection already exists, and the initialDisconnect argument is set to false, send message only to the already connected AP.
* Otherwise, scan for other networks, send the scan result to networkFilter and then transmit the message to the networks found in connectionQueue.
*
* @param message The message to send to other nodes. It will be stored in the class instance until replaced via attemptTransmission or setMessage.
* @param concludingDisconnect Disconnect from AP once transmission is complete.
* @param initialDisconnect Disconnect from any currently connected AP before attempting transmission.
* @param noScan Do not scan for new networks and do not call networkFilter function. Will only use the data already in connectionQueue for the transmission.
* @param scanAllWiFiChannels Scan all WiFi channels during a WiFi scan, instead of just the channel the ESP8266WiFiMesh instance is using.
* Scanning all WiFi channels takes about 2100 ms, compared to just 60 ms if only channel 1 (standard) is scanned.
* Note that if the ESP8266 has an active AP, that AP will switch WiFi channel to match that of any other AP the ESP8266 connects to.
* This can make it impossible for other nodes to detect the AP if they are scanning the wrong WiFi channel.
*/
void attemptTransmission(const String &message, bool concludingDisconnect = true, bool initialDisconnect = false, bool noScan = false, bool scanAllWiFiChannels = false);
/**
WiFiMesh Constructor method. Creates a WiFi Mesh Node, ready to be initialised.
/**
* If any clients are connected, accept their requests and call the requestHandler function for each one.
*/
void acceptRequest();
@param requestHandler The callback handler for dealing with received requests. Takes a string as an argument which
is the request string received from another node and returns the string to send back.
@param responseHandler The callback handler for dealing with received responses. Takes a string as an argument which
is the response string received from another node. Returns a transmission status code as a transmission_status_t.
@param networkFilter The callback handler for deciding which WiFi networks to connect to.
@param meshPassword The WiFi password for the mesh network.
@param meshName The name of the mesh network. Used as prefix for the node SSID and to find other network nodes in the example network filter function.
@param nodeID The id for this mesh node. Used as suffix for the node SSID. If set to "", the id will default to ESP.getChipId().
@param verboseMode Determines if we should print the events occurring in the library to Serial. Off by default.
@param meshWiFiChannel The WiFi channel used by the mesh network. Valid values are integers from 1 to 13. Defaults to 1.
WARNING: The ESP8266 has only one WiFi channel, and the the station/client mode is always prioritized for channel selection.
This can cause problems if several ESP8266WiFiMesh instances exist on the same ESP8266 and use different WiFi channels.
In such a case, whenever the station of one ESP8266WiFiMesh instance connects to an AP, it will silently force the
WiFi channel of any active AP on the ESP8266 to match that of the station. This will cause disconnects and possibly
make it impossible for other stations to detect the APs whose WiFi channels have changed.
@param serverPort The server port used by the AP of the ESP8266WiFiMesh instance. If multiple APs exist on a single ESP8266, each requires a separate server port.
If two AP:s on the same ESP8266 are using the same server port, they will not be able to have both server instances active at the same time.
This is managed automatically by the activateAP method.
/**
* Set a static IP address for the ESP8266 and activate use of static IP.
* The static IP needs to be at the same subnet as the server's gateway.
*/
void setStaticIP(const IPAddress &newIP);
IPAddress getStaticIP();
void disableStaticIP();
*/
ESP8266WiFiMesh(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter,
const String &meshPassword, const String &meshName = "MeshNode_", const String &nodeID = WIFI_MESH_EMPTY_STRING, bool verboseMode = false,
uint8 meshWiFiChannel = 1, uint16_t serverPort = 4011);
/**
* An empty IPAddress. Used as default when no IP is set.
*/
static const IPAddress emptyIP;
/**
A vector that contains the NetworkInfo for each WiFi network to connect to.
The connectionQueue vector is cleared before each new scan and filled via the networkFilter callback function once the scan completes.
WiFi connections will start with connectionQueue[0] and then incrementally proceed to higher vector positions.
Note that old network indicies often are invalidated whenever a new WiFi network scan occurs.
*/
static std::vector<NetworkInfo> connectionQueue;
void setRequestHandler(requestHandlerType requestHandler);
requestHandlerType getRequestHandler();
void setResponseHandler(responseHandlerType responseHandler);
responseHandlerType getResponseHandler();
void setNetworkFilter(networkFilterType networkFilter);
networkFilterType getNetworkFilter();
/**
A vector with the TransmissionResult for each AP to which a transmission was attempted during the latest attemptTransmission call.
The latestTransmissionOutcomes vector is cleared before each new transmission attempt.
Connection attempts are indexed in the same order they were attempted.
Note that old network indicies often are invalidated whenever a new WiFi network scan occurs.
*/
static std::vector<TransmissionResult> latestTransmissionOutcomes;
/**
* Set whether scan results from this ESP8266WiFiMesh instance will include WiFi networks with hidden SSIDs.
* This is false by default.
* The SSID field of a found hidden network will be blank in the scan results.
* WiFi.isHidden(networkIndex) can be used to verify that a found network is hidden.
*
* @param scanHidden If true, WiFi networks with hidden SSIDs will be included in scan results.
*/
void setScanHidden(bool scanHidden);
bool getScanHidden();
/**
@returns True if latest transmission was successful (i.e. latestTransmissionOutcomes is not empty and all entries have transmissionStatus TS_TRANSMISSION_COMPLETE). False otherwise.
*/
static bool latestTransmissionSuccessful();
/**
* Set whether the AP controlled by this ESP8266WiFiMesh instance will have a WiFi network with hidden SSID.
* This is false by default.
* Will also change the setting for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
*
* @param apHidden If true, the WiFi network created will have a hidden SSID.
*/
void setAPHidden(bool apHidden);
bool getAPHidden();
/**
Initialises the node.
*/
void begin();
/**
* Set the maximum number of stations that can simultaneously be connected to the AP controlled by this ESP8266WiFiMesh instance.
* This number is 4 by default.
* Once the max number has been reached, any other station that wants to connect will be forced to wait until an already connected station disconnects.
* The more stations that are connected, the more memory is required.
* Will also change the setting for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
*
* @param maxAPStations The maximum number of simultaneous station connections allowed. Valid values are 0 to 8.
*/
void setMaxAPStations(uint8_t maxAPStations);
bool getMaxAPStations();
/**
Each AP requires a separate server port. If two AP:s are using the same server port, they will not be able to have both server instances active at the same time.
This is managed automatically by the activateAP method.
*/
void activateAP();
void deactivateAP();
void restartAP();
/**
* Set the timeout for each attempt to connect to another AP that occurs through the attemptTransmission method by this ESP8266WiFiMesh instance.
* The timeout is 10 000 ms by default.
*
* @param connectionAttemptTimeoutMs The timeout for each connection attempt, in milliseconds.
*/
void setConnectionAttemptTimeout(int32_t connectionAttemptTimeoutMs);
int32_t getConnectionAttemptTimeout();
/**
Get the ESP8266WiFiMesh instance currently in control of the ESP8266 AP.
Note that the result will be nullptr when there is no active AP controller.
If another instance takes control over the AP after the pointer is created,
the created pointer will still point to the old AP instance.
/**
* Set the timeout to use for transmissions when this ESP8266WiFiMesh instance acts as a station (i.e. when connected to another AP).
* This will affect the timeout of the attemptTransmission method once a connection to an AP has been established.
* The timeout is 5 000 ms by default.
*
* @param stationModeTimeoutMs The timeout to use, in milliseconds.
*/
void setStationModeTimeout(int stationModeTimeoutMs);
int getStationModeTimeout();
@returns A pointer to the ESP8266WiFiMesh instance currently in control of the ESP8266 AP,
or nullptr if there is no active AP controller.
*/
static ESP8266WiFiMesh * getAPController();
/**
* Set the timeout to use for transmissions when this ESP8266WiFiMesh instance acts as an AP (i.e. when receiving connections from other stations).
* This will affect the timeout of the acceptRequest method.
* The timeout is 4 500 ms by default.
* Will also change the setting for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
*
* @param apModeTimeoutMs The timeout to use, in milliseconds.
*/
void setAPModeTimeout(uint32_t apModeTimeoutMs);
uint32_t getAPModeTimeout();
/**
Check if this ESP8266WiFiMesh instance is in control of the ESP8266 AP.
@returns True if this ESP8266WiFiMesh instance is in control of the ESP8266 AP. False otherwise.
*/
bool isAPController();
/**
Change the WiFi channel used by this ESP8266WiFiMesh instance.
Will also change the WiFi channel for the active AP if this ESP8266WiFiMesh instance is the current AP controller and it is possible to change channel.
WARNING: The ESP8266 has only one WiFi channel, and the the station/client mode is always prioritized for channel selection.
This can cause problems if several ESP8266WiFiMesh instances exist on the same ESP8266 and use different WiFi channels.
In such a case, whenever the station of one ESP8266WiFiMesh instance connects to an AP, it will silently force the
WiFi channel of any active AP on the ESP8266 to match that of the station. This will cause disconnects and possibly
make it impossible for other stations to detect the APs whose WiFi channels have changed.
@param newWiFiChannel The WiFi channel to change to. Valid values are integers from 1 to 13.
*/
void setWiFiChannel(uint8 newWiFiChannel);
uint8 getWiFiChannel();
/**
Change the mesh name used by this ESP8266WiFiMesh instance.
Will also change the mesh name (SSID prefix) for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
@param newMeshName The mesh name to change to.
*/
void setMeshName(const String &newMeshName);
String getMeshName();
/**
Change the node id used by this ESP8266WiFiMesh instance.
Will also change the node id (SSID suffix) for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
@param newNodeID The node id to change to.
*/
void setNodeID(const String &newNodeID);
String getNodeID();
/**
Change the SSID (mesh name + node id) used by this ESP8266WiFiMesh instance.
Will also change the SSID for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
@param newMeshName The mesh name to change to. Will be the SSID prefix.
@param newNodeID The node id to change to. Will be the SSID suffix.
*/
void setSSID(const String &newMeshName, const String &newNodeID);
String getSSID();
/**
Set the message that will be sent to other nodes when calling attemptTransmission.
@param newMessage The message to send.
*/
void setMessage(const String &newMessage);
String getMessage();
/**
If AP connection already exists, and the initialDisconnect argument is set to false, send message only to the already connected AP.
Otherwise, scan for other networks, send the scan result to networkFilter and then transmit the message to the networks found in connectionQueue.
@param message The message to send to other nodes. It will be stored in the class instance until replaced via attemptTransmission or setMessage.
@param concludingDisconnect Disconnect from AP once transmission is complete.
@param initialDisconnect Disconnect from any currently connected AP before attempting transmission.
@param noScan Do not scan for new networks and do not call networkFilter function. Will only use the data already in connectionQueue for the transmission.
@param scanAllWiFiChannels Scan all WiFi channels during a WiFi scan, instead of just the channel the ESP8266WiFiMesh instance is using.
Scanning all WiFi channels takes about 2100 ms, compared to just 60 ms if only channel 1 (standard) is scanned.
Note that if the ESP8266 has an active AP, that AP will switch WiFi channel to match that of any other AP the ESP8266 connects to.
This can make it impossible for other nodes to detect the AP if they are scanning the wrong WiFi channel.
*/
void attemptTransmission(const String &message, bool concludingDisconnect = true, bool initialDisconnect = false, bool noScan = false, bool scanAllWiFiChannels = false);
/**
If any clients are connected, accept their requests and call the requestHandler function for each one.
*/
void acceptRequest();
/**
Set a static IP address for the ESP8266 and activate use of static IP.
The static IP needs to be at the same subnet as the server's gateway.
*/
void setStaticIP(const IPAddress &newIP);
IPAddress getStaticIP();
void disableStaticIP();
/**
An empty IPAddress. Used as default when no IP is set.
*/
static const IPAddress emptyIP;
void setRequestHandler(requestHandlerType requestHandler);
requestHandlerType getRequestHandler();
void setResponseHandler(responseHandlerType responseHandler);
responseHandlerType getResponseHandler();
void setNetworkFilter(networkFilterType networkFilter);
networkFilterType getNetworkFilter();
/**
Set whether scan results from this ESP8266WiFiMesh instance will include WiFi networks with hidden SSIDs.
This is false by default.
The SSID field of a found hidden network will be blank in the scan results.
WiFi.isHidden(networkIndex) can be used to verify that a found network is hidden.
@param scanHidden If true, WiFi networks with hidden SSIDs will be included in scan results.
*/
void setScanHidden(bool scanHidden);
bool getScanHidden();
/**
Set whether the AP controlled by this ESP8266WiFiMesh instance will have a WiFi network with hidden SSID.
This is false by default.
Will also change the setting for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
@param apHidden If true, the WiFi network created will have a hidden SSID.
*/
void setAPHidden(bool apHidden);
bool getAPHidden();
/**
Set the maximum number of stations that can simultaneously be connected to the AP controlled by this ESP8266WiFiMesh instance.
This number is 4 by default.
Once the max number has been reached, any other station that wants to connect will be forced to wait until an already connected station disconnects.
The more stations that are connected, the more memory is required.
Will also change the setting for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
@param maxAPStations The maximum number of simultaneous station connections allowed. Valid values are 0 to 8.
*/
void setMaxAPStations(uint8_t maxAPStations);
bool getMaxAPStations();
/**
Set the timeout for each attempt to connect to another AP that occurs through the attemptTransmission method by this ESP8266WiFiMesh instance.
The timeout is 10 000 ms by default.
@param connectionAttemptTimeoutMs The timeout for each connection attempt, in milliseconds.
*/
void setConnectionAttemptTimeout(int32_t connectionAttemptTimeoutMs);
int32_t getConnectionAttemptTimeout();
/**
Set the timeout to use for transmissions when this ESP8266WiFiMesh instance acts as a station (i.e. when connected to another AP).
This will affect the timeout of the attemptTransmission method once a connection to an AP has been established.
The timeout is 5 000 ms by default.
@param stationModeTimeoutMs The timeout to use, in milliseconds.
*/
void setStationModeTimeout(int stationModeTimeoutMs);
int getStationModeTimeout();
/**
Set the timeout to use for transmissions when this ESP8266WiFiMesh instance acts as an AP (i.e. when receiving connections from other stations).
This will affect the timeout of the acceptRequest method.
The timeout is 4 500 ms by default.
Will also change the setting for the active AP if this ESP8266WiFiMesh instance is the current AP controller.
@param apModeTimeoutMs The timeout to use, in milliseconds.
*/
void setAPModeTimeout(uint32_t apModeTimeoutMs);
uint32_t getAPModeTimeout();
};
#endif

View File

@ -1,77 +1,77 @@
/*
* NetworkInfo
* 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.
*/
NetworkInfo
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 "NetworkInfo.h"
void NetworkInfo::copyBSSID(uint8_t newBSSID[6])
{
if(newBSSID != NULL)
{
if(BSSID == NULL)
if (newBSSID != NULL)
{
BSSID = _bssidArray;
if (BSSID == NULL)
{
BSSID = _bssidArray;
}
for (int i = 0; i < 6; i++)
{
BSSID[i] = newBSSID[i];
}
}
for(int i = 0; i < 6; i++)
else
{
BSSID[i] = newBSSID[i];
BSSID = NULL;
}
}
else
{
BSSID = NULL;
}
}
NetworkInfo::NetworkInfo(int newNetworkIndex, bool autofill) : networkIndex(newNetworkIndex)
{
if(autofill)
{
SSID = WiFi.SSID(newNetworkIndex);
wifiChannel = WiFi.channel(newNetworkIndex);
copyBSSID(WiFi.BSSID(newNetworkIndex));
}
{
if (autofill)
{
SSID = WiFi.SSID(newNetworkIndex);
wifiChannel = WiFi.channel(newNetworkIndex);
copyBSSID(WiFi.BSSID(newNetworkIndex));
}
}
NetworkInfo::NetworkInfo(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], int newNetworkIndex) :
SSID(newSSID), wifiChannel(newWiFiChannel), networkIndex(newNetworkIndex)
NetworkInfo::NetworkInfo(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], int newNetworkIndex) :
SSID(newSSID), wifiChannel(newWiFiChannel), networkIndex(newNetworkIndex)
{
copyBSSID(newBSSID);
copyBSSID(newBSSID);
}
NetworkInfo::NetworkInfo(const NetworkInfo &other) : SSID(other.SSID), wifiChannel(other.wifiChannel), networkIndex(other.networkIndex)
{
copyBSSID(other.BSSID);
copyBSSID(other.BSSID);
}
NetworkInfo & NetworkInfo::operator=(const NetworkInfo &other)
{
SSID = other.SSID;
wifiChannel = other.wifiChannel;
copyBSSID(other.BSSID);
networkIndex = other.networkIndex;
return *this;
SSID = other.SSID;
wifiChannel = other.wifiChannel;
copyBSSID(other.BSSID);
networkIndex = other.networkIndex;
return *this;
}

View File

@ -1,27 +1,27 @@
/*
* NetworkInfo
* 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.
*/
NetworkInfo
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.
*/
#ifndef __NETWORKINFO_H__
#define __NETWORKINFO_H__
@ -30,40 +30,41 @@
const int NETWORK_INFO_DEFAULT_INT = -1;
class NetworkInfo {
class NetworkInfo
{
private:
uint8_t _bssidArray[6] {0};
uint8_t _bssidArray[6] {0};
public:
String SSID = "";
int wifiChannel = NETWORK_INFO_DEFAULT_INT;
uint8_t *BSSID = NULL;
int networkIndex = NETWORK_INFO_DEFAULT_INT;
String SSID = "";
int wifiChannel = NETWORK_INFO_DEFAULT_INT;
uint8_t *BSSID = NULL;
int networkIndex = NETWORK_INFO_DEFAULT_INT;
/**
* @param autofill Automatically fill in the rest of the network info using newNetworkIndex and the WiFi scan results.
*/
NetworkInfo(int newNetworkIndex, bool autofill = true);
/**
@param autofill Automatically fill in the rest of the network info using newNetworkIndex and the WiFi scan results.
*/
NetworkInfo(int newNetworkIndex, bool autofill = true);
/**
* Without giving channel and BSSID, connection time is longer.
*/
NetworkInfo(const String &newSSID, int newWiFiChannel = NETWORK_INFO_DEFAULT_INT, uint8_t newBSSID[6] = NULL, int newNetworkIndex = NETWORK_INFO_DEFAULT_INT);
/**
Without giving channel and BSSID, connection time is longer.
*/
NetworkInfo(const String &newSSID, int newWiFiChannel = NETWORK_INFO_DEFAULT_INT, uint8_t newBSSID[6] = NULL, int newNetworkIndex = NETWORK_INFO_DEFAULT_INT);
NetworkInfo(const NetworkInfo &other);
NetworkInfo(const NetworkInfo &other);
NetworkInfo & operator=(const NetworkInfo &other);
NetworkInfo & operator=(const NetworkInfo &other);
// No need for explicit destructor with current class design
// No need for explicit destructor with current class design
/**
* Copy newBSSID into BSSID.
* Prefer this method for changing NetworkInfo BSSID, unless you actually want to change the BSSID pointer.
*/
void copyBSSID(uint8_t newBSSID[6]);
/**
Copy newBSSID into BSSID.
Prefer this method for changing NetworkInfo BSSID, unless you actually want to change the BSSID pointer.
*/
void copyBSSID(uint8_t newBSSID[6]);
};
#endif

View File

@ -1,42 +1,42 @@
/*
* 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.
*/
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 "TransmissionResult.h"
TransmissionResult::TransmissionResult(int newNetworkIndex, transmission_status_t newTransmissionStatus, bool autofill) :
NetworkInfo(newNetworkIndex, autofill), transmissionStatus(newTransmissionStatus)
TransmissionResult::TransmissionResult(int newNetworkIndex, transmission_status_t newTransmissionStatus, bool autofill) :
NetworkInfo(newNetworkIndex, autofill), transmissionStatus(newTransmissionStatus)
{ }
TransmissionResult::TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], transmission_status_t newTransmissionStatus) :
NetworkInfo(newSSID, newWiFiChannel, newBSSID), transmissionStatus(newTransmissionStatus)
TransmissionResult::TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], transmission_status_t newTransmissionStatus) :
NetworkInfo(newSSID, newWiFiChannel, newBSSID), transmissionStatus(newTransmissionStatus)
{ }
TransmissionResult::TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], int newNetworkIndex, transmission_status_t newTransmissionStatus) :
NetworkInfo(newSSID, newWiFiChannel, newBSSID, newNetworkIndex), transmissionStatus(newTransmissionStatus)
NetworkInfo(newSSID, newWiFiChannel, newBSSID, newNetworkIndex), transmissionStatus(newTransmissionStatus)
{ }
TransmissionResult::TransmissionResult(const NetworkInfo& origin, transmission_status_t newTransmissionStatus) :
NetworkInfo(origin), transmissionStatus(newTransmissionStatus)
TransmissionResult::TransmissionResult(const NetworkInfo& origin, transmission_status_t newTransmissionStatus) :
NetworkInfo(origin), transmissionStatus(newTransmissionStatus)
{ }

View File

@ -1,27 +1,27 @@
/*
* 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.
*/
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.
*/
#ifndef __TRANSMISSIONRESULT_H__
#define __TRANSMISSIONRESULT_H__
@ -29,29 +29,30 @@
#include <ESP8266WiFi.h>
#include "NetworkInfo.h"
typedef enum
typedef enum
{
TS_CONNECTION_FAILED = -1,
TS_TRANSMISSION_FAILED = 0,
TS_TRANSMISSION_COMPLETE = 1
} transmission_status_t;
class TransmissionResult : public NetworkInfo {
class TransmissionResult : public NetworkInfo
{
public:
transmission_status_t transmissionStatus;
transmission_status_t transmissionStatus;
/**
* @param autofill Automatically fill in the rest of the network info using newNetworkIndex and the WiFi scan results.
*/
TransmissionResult(int newNetworkIndex, transmission_status_t newTransmissionStatus, bool autofill = true);
/**
@param autofill Automatically fill in the rest of the network info using newNetworkIndex and the WiFi scan results.
*/
TransmissionResult(int newNetworkIndex, transmission_status_t newTransmissionStatus, bool autofill = true);
TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], transmission_status_t newTransmissionStatus);
TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], transmission_status_t newTransmissionStatus);
TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], int newNetworkIndex, transmission_status_t newTransmissionStatus);
TransmissionResult(const String &newSSID, int newWiFiChannel, uint8_t newBSSID[6], int newNetworkIndex, transmission_status_t newTransmissionStatus);
TransmissionResult(const NetworkInfo& origin, transmission_status_t newTransmissionStatus);
TransmissionResult(const NetworkInfo& origin, transmission_status_t newTransmissionStatus);
};
#endif

View File

@ -1,58 +1,58 @@
/*
* TypeConversionFunctions
* 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.
*/
TypeConversionFunctions
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 "TypeConversionFunctions.h"
String uint64ToString(uint64_t number, byte base)
{
assert(2 <= base && base <= 36);
String result = "";
assert(2 <= base && base <= 36);
while(number > 0)
{
result = String((uint32_t)(number % base), base) + result;
number /= base;
}
return (result == "" ? "0" : result);
String result = "";
while (number > 0)
{
result = String((uint32_t)(number % base), base) + result;
number /= base;
}
return (result == "" ? "0" : result);
}
uint64_t stringToUint64(const String &string, byte base)
{
assert(2 <= base && base <= 36);
uint64_t result = 0;
assert(2 <= base && base <= 36);
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;
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;
}

View File

@ -1,27 +1,27 @@
/*
* TypeConversionFunctions
* 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.
*/
TypeConversionFunctions
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.
*/
#ifndef __TYPECONVERSIONFUNCTIONS_H__
#define __TYPECONVERSIONFUNCTIONS_H__
@ -30,21 +30,21 @@
#include <assert.h>
/**
* 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".
*/
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 uint64ToString(uint64_t number, byte base = 16);
/**
* 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.
*/
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 stringToUint64(const String &string, byte base = 16);
#endif

View File

@ -1,81 +1,89 @@
/*
* 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.
*/
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 "TypeConversionFunctions.h"
#include "ESP8266WiFiMesh.h"
void ESP8266WiFiMesh::verboseModePrint(const String &stringToPrint, bool newline)
{
if(_verboseMode)
{
if(newline)
Serial.println(stringToPrint);
else
Serial.print(stringToPrint);
}
if (_verboseMode)
{
if (newline)
{
Serial.println(stringToPrint);
}
else
{
Serial.print(stringToPrint);
}
}
}
/**
* 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.
*/
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();
// 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);
int i = fullVersion.indexOf("lwIP:") + 5;
char currentChar = fullVersion.charAt(i);
for(int versionPart = 0; versionPart < 3; versionPart++)
{
while(!isdigit(currentChar))
for (int versionPart = 0; versionPart < 3; versionPart++)
{
currentChar = fullVersion.charAt(++i);
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);
}
}
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.
*/
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;
}
{
for (int versionPart = 0; versionPart < 3; versionPart++)
{
if (_lwipVersion[versionPart] > minLwipVersion[versionPart])
{
return true;
}
else if (_lwipVersion[versionPart] < minLwipVersion[versionPart])
{
return false;
}
}
return true;
return true;
}