Skip to content

Commit 5cb167f

Browse files
authored
Merge branch 'master' into network_flush_to_clear
2 parents 06e2528 + cff2a18 commit 5cb167f

File tree

9 files changed

+51
-41
lines changed

9 files changed

+51
-41
lines changed

Diff for: libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@ void setup() {
6767
Serial.begin(115200);
6868
while (!Serial) delay(10);
6969

70+
// Initialize the Wi-Fi module
71+
WiFi.mode(WIFI_STA);
72+
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
73+
while(!WiFi.STA.started()) delay(100);
74+
7075
Serial.println("ESP-NOW Example - Broadcast Master");
7176
Serial.println("Wi-Fi parameters:");
7277
Serial.println(" Mode: STA");
7378
Serial.println(" MAC Address: " + WiFi.macAddress());
7479
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);
7580

76-
// Initialize the Wi-Fi module
77-
WiFi.mode(WIFI_STA);
78-
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
79-
8081
// Register the broadcast peer
8182
if (!broadcast_peer.begin()) {
8283
Serial.println("Failed to initialize broadcast peer");

Diff for: libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino

+7-6
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public:
4545
return true;
4646
}
4747

48-
// Function to print the received messages from the master
49-
void _onReceive(const uint8_t *data, size_t len, bool broadcast) {
48+
// Function to print the received messages from the master
49+
void onReceive(const uint8_t *data, size_t len, bool broadcast) {
5050
Serial.printf("Received a message from master " MACSTR " (%s)\n", MAC2STR(addr()), broadcast ? "broadcast" : "unicast");
5151
Serial.printf(" Message: %s\n", (char *)data);
5252
}
@@ -85,16 +85,17 @@ void setup() {
8585
Serial.begin(115200);
8686
while (!Serial) delay(10);
8787

88+
// Initialize the Wi-Fi module
89+
WiFi.mode(WIFI_STA);
90+
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
91+
while(!WiFi.STA.started()) delay(100);
92+
8893
Serial.println("ESP-NOW Example - Broadcast Slave");
8994
Serial.println("Wi-Fi parameters:");
9095
Serial.println(" Mode: STA");
9196
Serial.println(" MAC Address: " + WiFi.macAddress());
9297
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);
9398

94-
// Initialize the Wi-Fi module
95-
WiFi.mode(WIFI_STA);
96-
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
97-
9899
// Initialize the ESP-NOW protocol
99100
if (!ESP_NOW.begin()) {
100101
Serial.println("Failed to initialize ESP-NOW");

Diff for: libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino

+7-6
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ public:
162162
void onSent(bool success) {
163163
bool broadcast = memcmp(addr(), ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0;
164164
if (broadcast) {
165-
log_v("Broadcast message reported as sent %s", success ? "successfully" : "unsuccessfully");
165+
log_i("Broadcast message reported as sent %s", success ? "successfully" : "unsuccessfully");
166166
}
167167
else {
168-
log_v("Unicast message reported as sent %s to peer " MACSTR, success ? "successfully" : "unsuccessfully", MAC2STR(addr()));
168+
log_i("Unicast message reported as sent %s to peer " MACSTR, success ? "successfully" : "unsuccessfully", MAC2STR(addr()));
169169
}
170170
}
171171
};
@@ -253,16 +253,17 @@ void setup() {
253253
Serial.begin(115200);
254254
while (!Serial) delay(10);
255255

256+
// Initialize the Wi-Fi module
257+
WiFi.mode(WIFI_STA);
258+
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
259+
while(!WiFi.STA.started()) delay(100);
260+
256261
Serial.println("ESP-NOW Network Example");
257262
Serial.println("Wi-Fi parameters:");
258263
Serial.println(" Mode: STA");
259264
Serial.println(" MAC Address: " + WiFi.macAddress());
260265
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);
261266

262-
// Initialize the Wi-Fi module
263-
WiFi.mode(WIFI_STA);
264-
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
265-
266267
// Generate yhis device's priority based on the 3 last bytes of the MAC address
267268
WiFi.macAddress(self_mac);
268269
self_priority = self_mac[3] << 16 | self_mac[4] << 8 | self_mac[5];

Diff for: libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void setup() {
5454
Serial.println(ESPNOW_WIFI_CHANNEL);
5555
WiFi.setChannel(ESPNOW_WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE);
5656

57+
while(!(WiFi.STA.started() || WiFi.AP.started())) delay(100);
58+
5759
Serial.print("MAC Address: ");
5860
Serial.println(ESPNOW_WIFI_MODE == WIFI_AP ? WiFi.softAPmacAddress() : WiFi.macAddress());
5961

Diff for: libraries/ESP_NOW/src/ESP32_NOW.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ class ESP_NOW_Peer {
4141

4242
//optional callbacks to be implemented by the upper class
4343
virtual void onReceive(const uint8_t * data, size_t len, bool broadcast) {
44-
log_i("Received %d bytes from " MACSTR " %s", len, MAC2STR(mac), broadcast ? "broadcast" : "");
44+
log_i("Received %d bytes from " MACSTR " %s", len, MAC2STR(mac), broadcast ? "(broadcast)" : "");
45+
}
46+
47+
virtual void onSent(bool success) {
48+
log_i("Message transmission to peer " MACSTR " %s", MAC2STR(mac), success ? "successful" : "failed");
4549
}
46-
virtual void onSent(bool success) { log_i("Message reported as sent %s", success ? "successfully" : "unsuccessfully"); }
4750
};
4851

4952
class ESP_NOW_Class : public Print {

Diff for: libraries/Network/src/NetworkManager.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ int NetworkManager::hostByName(const char* aHostname, IPAddress& aResult)
6767

6868
const char *servname = "0";
6969
struct addrinfo *res;
70-
const struct addrinfo hints = {
71-
.ai_family = AF_UNSPEC,
72-
.ai_socktype = SOCK_STREAM,
73-
};
70+
struct addrinfo hints;
71+
memset(&hints, 0, sizeof(hints));
72+
hints.ai_family = AF_UNSPEC;
73+
hints.ai_socktype = SOCK_STREAM;
74+
7475
err = lwip_getaddrinfo(aHostname, servname, &hints, &res);
7576
if (err == ERR_OK)
7677
{

Diff for: libraries/WiFi/src/AP.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ bool APClass::end(){
200200
return true;
201201
}
202202

203-
bool APClass::create(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder){
203+
bool APClass::create(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder, wifi_auth_mode_t auth_mode, wifi_cipher_type_t cipher){
204204
if(!ssid || *ssid == 0) {
205205
log_e("SSID missing!");
206206
return false;
@@ -226,8 +226,8 @@ bool APClass::create(const char* ssid, const char* passphrase, int channel, int
226226
_wifi_strncpy((char*)conf.ap.ssid, ssid, 32);
227227
conf.ap.ssid_len = strlen(ssid);
228228
if(passphrase != NULL && passphrase[0] != 0){
229-
conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
230-
conf.ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP; // Disable by default enabled insecure TKIP and use just CCMP.
229+
conf.ap.authmode = auth_mode;
230+
conf.ap.pairwise_cipher = cipher;
231231
_wifi_strncpy((char*)conf.ap.password, passphrase, 64);
232232
}
233233
}
@@ -318,15 +318,15 @@ size_t APClass::printDriverInfo(Print & out) const{
318318

319319
if(info.ap.authmode == WIFI_AUTH_OPEN){ bytes += out.print(",OPEN"); }
320320
else if(info.ap.authmode == WIFI_AUTH_WEP){ bytes += out.print(",WEP"); }
321-
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WWPA_PSK"); }
322-
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WWPA2_PSK"); }
323-
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WWPA_WPA2_PSK"); }
321+
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WPA_PSK"); }
322+
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WPA2_PSK"); }
323+
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WPA_WPA2_PSK"); }
324324
else if(info.ap.authmode == WIFI_AUTH_ENTERPRISE){ bytes += out.print(",WEAP"); }
325-
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WWPA3_PSK"); }
326-
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WWPA2_WPA3_PSK"); }
327-
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WWAPI_PSK"); }
328-
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",WOWE"); }
329-
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WWPA3_ENT_SUITE_B_192_BIT"); }
325+
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WPA3_PSK"); }
326+
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WPA2_WPA3_PSK"); }
327+
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WAPI_PSK"); }
328+
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",OWE"); }
329+
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WPA3_ENT_SUITE_B_192_BIT"); }
330330

331331
if(esp_wifi_ap_get_sta_list(&clients) == ESP_OK) {
332332
bytes += out.print(",STA:");

Diff for: libraries/WiFi/src/WiFiAP.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
4848
* @param max_connection Max simultaneous connected clients, 1 - 4.
4949
*/
50-
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
50+
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder, wifi_auth_mode_t auth_mode, wifi_cipher_type_t cipher)
5151
{
52-
return AP.begin() && AP.create(ssid, passphrase, channel, ssid_hidden, max_connection, ftm_responder);
52+
return AP.begin() && AP.create(ssid, passphrase, channel, ssid_hidden, max_connection, ftm_responder, auth_mode, cipher);
5353
}
5454

5555
/**

Diff for: libraries/WiFi/src/WiFiAP.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
#include "soc/soc_caps.h"
2626
#if SOC_WIFI_SUPPORTED
2727

28-
28+
#include "esp_wifi_types.h"
2929
#include "WiFiType.h"
3030
#include "WiFiGeneric.h"
3131

32-
32+
#define WIFI_AP_DEFAULT_AUTH_MODE WIFI_AUTH_WPA2_PSK
33+
#define WIFI_AP_DEFAULT_CIPHER WIFI_CIPHER_TYPE_CCMP // Disable by default enabled insecure TKIP and use just CCMP.
3334

3435
// ----------------------------------------------------------------------------------------------
3536
// ------------------------------------ NEW AP Implementation ----------------------------------
@@ -43,7 +44,7 @@ class APClass: public NetworkInterface {
4344
bool begin();
4445
bool end();
4546

46-
bool create(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
47+
bool create(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false, wifi_auth_mode_t auth_mode = WIFI_AP_DEFAULT_AUTH_MODE, wifi_cipher_type_t cipher = WIFI_AP_DEFAULT_CIPHER);
4748
bool clear();
4849

4950
bool bandwidth(wifi_bandwidth_t bandwidth);
@@ -71,9 +72,9 @@ class WiFiAPClass
7172
public:
7273
APClass AP;
7374

74-
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
75-
bool softAP(const String& ssid, const String& passphrase = emptyString, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false) {
76-
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder);
75+
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false, wifi_auth_mode_t auth_mode = WIFI_AP_DEFAULT_AUTH_MODE, wifi_cipher_type_t cipher = WIFI_AP_DEFAULT_CIPHER);
76+
bool softAP(const String& ssid, const String& passphrase = emptyString, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false, wifi_auth_mode_t auth_mode = WIFI_AP_DEFAULT_AUTH_MODE, wifi_cipher_type_t cipher = WIFI_AP_DEFAULT_CIPHER) {
77+
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder, auth_mode, cipher);
7778
}
7879

7980
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);

0 commit comments

Comments
 (0)