You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Move all Strings to flash and optimize String usage, saving 4-5 kB of RAM.
- Replace const with constexpr where possible.
- Use default constructor instead of copy constructor for IPAddress variable initialization.
- Add MeshTypeConversionFunctions namespace around TypeConversionFunctions.
- Add MeshUtilityFunctions namespace around UtilityFunctions.
- Add ESP8266WIFIMESH_DISABLE_COMPATIBILITY preprocessor flag to retain compatibility with old code despite new namespaces.
- Add setLogEntryLifetimeMs and setBroadcastResponseTimeoutMs methods to EspnowMeshBackend.
- Move FloodingMesh constant definitions from header to .cpp file to reduce the risk of extra RAM consumption.
- Add deactivateAP method to FloodingMesh.
- Make deactivateAP static and add new non-static deactivateControlledAP method to MeshBackendBase.
- Add example of how to transfer null values using multiStrings to HelloEspnow.ino.
- Improve documentation.
- Improve comments.
Copy file name to clipboardExpand all lines: libraries/ESP8266WiFiMesh/examples/HelloEspnow/HelloEspnow.ino
+31-13Lines changed: 31 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
+
#defineESP8266WIFIMESH_DISABLE_COMPATIBILITY// Excludes redundant compatibility code. Should be used for new code until the compatibility code is removed with release 3.0.0 of the Arduino core.
2
+
1
3
#include<ESP8266WiFi.h>
2
4
#include<EspnowMeshBackend.h>
3
5
#include<TypeConversionFunctions.h>
4
6
#include<assert.h>
5
7
8
+
namespaceTypeCast= MeshTypeConversionFunctions;
9
+
6
10
/**
7
11
NOTE: Although we could define the strings below as normal String variables,
8
12
here we are using PROGMEM combined with the FPSTR() macro (and also just the F() macro further down in the file).
constchar exampleMeshName[] PROGMEM = "MeshNode_"; // The name of the mesh network. Used as prefix for the node SSID and to find other network nodes in the example networkFilter and broadcastFilter functions below.
18
-
constchar exampleWiFiPassword[] PROGMEM = "ChangeThisWiFiPassword_TODO"; // The password has to be min 8 and max 64 characters long, otherwise an AP which uses it will not be found during scans.
21
+
constexprchar exampleMeshName[] PROGMEM = "MeshNode_"; // The name of the mesh network. Used as prefix for the node SSID and to find other network nodes in the example networkFilter and broadcastFilter functions below.
22
+
constexprchar exampleWiFiPassword[] PROGMEM = "ChangeThisWiFiPassword_TODO"; // The password has to be min 8 and max 64 characters long, otherwise an AP which uses it will not be found during scans.
19
23
20
24
// A custom encryption key is required when using encrypted ESP-NOW transmissions. There is always a default Kok set, but it can be replaced if desired.
21
25
// All ESP-NOW keys below must match in an encrypted connection pair for encrypted communication to be possible.
// If you need to print the whole String it is better to store it and print it in the loop() later.
73
77
// Note that request.substring will not work as expected if the String contains null values as data.
74
78
Serial.print("Request received: ");
75
-
Serial.println(request.substring(0, 100));
79
+
80
+
if (request.charAt(0) == 0) {
81
+
Serial.println(request); // substring will not work for multiStrings.
82
+
} else {
83
+
Serial.println(request.substring(0, 100));
84
+
}
76
85
77
86
/* return a string to send back */
78
87
return ("Hello world response #" + String(responseNumber++) + " from " + meshInstance.getMeshName() + meshInstance.getNodeID() + " with AP MAC " + WiFi.softAPmacAddress() + ".");
espnowDelay(100); // Wait for responses (broadcasts can receive an unlimited number of responses, other transmissions can only receive one response).
347
356
357
+
// If you have a data array containing null values it is possible to transmit the raw data by making the array into a multiString as shown below.
358
+
// You can use String::c_str() or String::begin() to retreive the data array later.
359
+
// Note that certain String methods such as String::substring use null values to determine String length, which means they will not work as normal with multiStrings.
Copy file name to clipboardExpand all lines: libraries/ESP8266WiFiMesh/examples/HelloMesh/HelloMesh.ino
+18-14Lines changed: 18 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,15 @@
5
5
That way you will get instant confirmation of the mesh communication without checking the Serial Monitor.
6
6
*/
7
7
8
+
#defineESP8266WIFIMESH_DISABLE_COMPATIBILITY// Excludes redundant compatibility code. Should be used for new code until the compatibility code is removed with release 3.0.0 of the Arduino core.
9
+
8
10
#include<ESP8266WiFi.h>
9
11
#include<TypeConversionFunctions.h>
10
12
#include<assert.h>
11
13
#include<FloodingMesh.h>
12
14
15
+
namespaceTypeCast= MeshTypeConversionFunctions;
16
+
13
17
/**
14
18
NOTE: Although we could define the strings below as normal String variables,
15
19
here we are using PROGMEM combined with the FPSTR() macro (and also just the F() macro further down in the file).
constchar exampleMeshName[] PROGMEM = "MeshNode_"; // The name of the mesh network. Used as prefix for the node SSID and to find other network nodes in the example networkFilter and broadcastFilter functions below.
25
-
constchar exampleWiFiPassword[] PROGMEM = "ChangeThisWiFiPassword_TODO"; // The password has to be min 8 and max 64 characters long, otherwise an AP which uses it will not be found during scans.
28
+
constexprchar exampleMeshName[] PROGMEM = "MeshNode_"; // The name of the mesh network. Used as prefix for the node SSID and to find other network nodes in the example networkFilter and broadcastFilter functions below.
29
+
constexprchar exampleWiFiPassword[] PROGMEM = "ChangeThisWiFiPassword_TODO"; // The password has to be min 8 and max 64 characters long, otherwise an AP which uses it will not be found during scans.
26
30
27
31
// A custom encryption key is required when using encrypted ESP-NOW transmissions. There is always a default Kok set, but it can be replaced if desired.
28
32
// All ESP-NOW keys below must match in an encrypted connection pair for encrypted communication to be possible.
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
@@ -150,7 +154,7 @@ void setup() {
150
154
// The main benefit of AEAD encryption is that it can be used with normal broadcasts (which are substantially faster than encryptedBroadcasts).
151
155
// The main drawbacks are that AEAD only encrypts the message data (not transmission metadata), transfers less data per message and lacks replay attack protection.
152
156
// When using AEAD, potential replay attacks must thus be handled manually.
153
-
//floodingMesh.getEspnowMeshBackend().setEspnowMessageEncryptionKey("ChangeThisKeySeed_TODO"); // The message encryption key should always be set manually. Otherwise a default key (all zeroes) is used.
157
+
//floodingMesh.getEspnowMeshBackend().setEspnowMessageEncryptionKey(F("ChangeThisKeySeed_TODO")); // The message encryption key should always be set manually. Otherwise a default key (all zeroes) is used.
floodingMeshDelay(5000); // Give some time for user to start the nodes
@@ -180,17 +184,17 @@ void loop() {
180
184
ledState = ledState ^ bool(benchmarkCount); // Make other nodes' LEDs alternate between on and off once benchmarking begins.
181
185
182
186
// Note: The maximum length of an unencrypted broadcast message is given by floodingMesh.maxUnencryptedMessageLength(). It is around 670 bytes by default.
183
-
floodingMesh.broadcast(String(floodingMesh.metadataDelimiter()) + String(ledState) + theOneMac + " is The One.");
0 commit comments