Skip to content

Commit

Permalink
Merge branch 'master' into network_flush_to_clear
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasssvaz authored Apr 4, 2024
2 parents 06e2528 + cff2a18 commit 5cb167f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ void setup() {
Serial.begin(115200);
while (!Serial) delay(10);

// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
while(!WiFi.STA.started()) delay(100);

Serial.println("ESP-NOW Example - Broadcast Master");
Serial.println("Wi-Fi parameters:");
Serial.println(" Mode: STA");
Serial.println(" MAC Address: " + WiFi.macAddress());
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);

// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);

// Register the broadcast peer
if (!broadcast_peer.begin()) {
Serial.println("Failed to initialize broadcast peer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public:
return true;
}

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

// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
while(!WiFi.STA.started()) delay(100);

Serial.println("ESP-NOW Example - Broadcast Slave");
Serial.println("Wi-Fi parameters:");
Serial.println(" Mode: STA");
Serial.println(" MAC Address: " + WiFi.macAddress());
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);

// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);

// Initialize the ESP-NOW protocol
if (!ESP_NOW.begin()) {
Serial.println("Failed to initialize ESP-NOW");
Expand Down
13 changes: 7 additions & 6 deletions libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ public:
void onSent(bool success) {
bool broadcast = memcmp(addr(), ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0;
if (broadcast) {
log_v("Broadcast message reported as sent %s", success ? "successfully" : "unsuccessfully");
log_i("Broadcast message reported as sent %s", success ? "successfully" : "unsuccessfully");
}
else {
log_v("Unicast message reported as sent %s to peer " MACSTR, success ? "successfully" : "unsuccessfully", MAC2STR(addr()));
log_i("Unicast message reported as sent %s to peer " MACSTR, success ? "successfully" : "unsuccessfully", MAC2STR(addr()));
}
}
};
Expand Down Expand Up @@ -253,16 +253,17 @@ void setup() {
Serial.begin(115200);
while (!Serial) delay(10);

// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
while(!WiFi.STA.started()) delay(100);

Serial.println("ESP-NOW Network Example");
Serial.println("Wi-Fi parameters:");
Serial.println(" Mode: STA");
Serial.println(" MAC Address: " + WiFi.macAddress());
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);

// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);

// Generate yhis device's priority based on the 3 last bytes of the MAC address
WiFi.macAddress(self_mac);
self_priority = self_mac[3] << 16 | self_mac[4] << 8 | self_mac[5];
Expand Down
2 changes: 2 additions & 0 deletions libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void setup() {
Serial.println(ESPNOW_WIFI_CHANNEL);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE);

while(!(WiFi.STA.started() || WiFi.AP.started())) delay(100);

Serial.print("MAC Address: ");
Serial.println(ESPNOW_WIFI_MODE == WIFI_AP ? WiFi.softAPmacAddress() : WiFi.macAddress());

Expand Down
7 changes: 5 additions & 2 deletions libraries/ESP_NOW/src/ESP32_NOW.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class ESP_NOW_Peer {

//optional callbacks to be implemented by the upper class
virtual void onReceive(const uint8_t * data, size_t len, bool broadcast) {
log_i("Received %d bytes from " MACSTR " %s", len, MAC2STR(mac), broadcast ? "broadcast" : "");
log_i("Received %d bytes from " MACSTR " %s", len, MAC2STR(mac), broadcast ? "(broadcast)" : "");
}

virtual void onSent(bool success) {
log_i("Message transmission to peer " MACSTR " %s", MAC2STR(mac), success ? "successful" : "failed");
}
virtual void onSent(bool success) { log_i("Message reported as sent %s", success ? "successfully" : "unsuccessfully"); }
};

class ESP_NOW_Class : public Print {
Expand Down
9 changes: 5 additions & 4 deletions libraries/Network/src/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ int NetworkManager::hostByName(const char* aHostname, IPAddress& aResult)

const char *servname = "0";
struct addrinfo *res;
const struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
};
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;

err = lwip_getaddrinfo(aHostname, servname, &hints, &res);
if (err == ERR_OK)
{
Expand Down
22 changes: 11 additions & 11 deletions libraries/WiFi/src/AP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ bool APClass::end(){
return true;
}

bool APClass::create(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder){
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){
if(!ssid || *ssid == 0) {
log_e("SSID missing!");
return false;
Expand All @@ -226,8 +226,8 @@ bool APClass::create(const char* ssid, const char* passphrase, int channel, int
_wifi_strncpy((char*)conf.ap.ssid, ssid, 32);
conf.ap.ssid_len = strlen(ssid);
if(passphrase != NULL && passphrase[0] != 0){
conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
conf.ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP; // Disable by default enabled insecure TKIP and use just CCMP.
conf.ap.authmode = auth_mode;
conf.ap.pairwise_cipher = cipher;
_wifi_strncpy((char*)conf.ap.password, passphrase, 64);
}
}
Expand Down Expand Up @@ -318,15 +318,15 @@ size_t APClass::printDriverInfo(Print & out) const{

if(info.ap.authmode == WIFI_AUTH_OPEN){ bytes += out.print(",OPEN"); }
else if(info.ap.authmode == WIFI_AUTH_WEP){ bytes += out.print(",WEP"); }
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WWPA_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WWPA2_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WWPA_WPA2_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WPA_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WPA2_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WPA_WPA2_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_ENTERPRISE){ bytes += out.print(",WEAP"); }
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WWPA3_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WWPA2_WPA3_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WWAPI_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",WOWE"); }
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WWPA3_ENT_SUITE_B_192_BIT"); }
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WPA3_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WPA2_WPA3_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WAPI_PSK"); }
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",OWE"); }
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WPA3_ENT_SUITE_B_192_BIT"); }

if(esp_wifi_ap_get_sta_list(&clients) == ESP_OK) {
bytes += out.print(",STA:");
Expand Down
4 changes: 2 additions & 2 deletions libraries/WiFi/src/WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
* @param max_connection Max simultaneous connected clients, 1 - 4.
*/
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
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)
{
return AP.begin() && AP.create(ssid, passphrase, channel, ssid_hidden, max_connection, ftm_responder);
return AP.begin() && AP.create(ssid, passphrase, channel, ssid_hidden, max_connection, ftm_responder, auth_mode, cipher);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions libraries/WiFi/src/WiFiAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED


#include "esp_wifi_types.h"
#include "WiFiType.h"
#include "WiFiGeneric.h"


#define WIFI_AP_DEFAULT_AUTH_MODE WIFI_AUTH_WPA2_PSK
#define WIFI_AP_DEFAULT_CIPHER WIFI_CIPHER_TYPE_CCMP // Disable by default enabled insecure TKIP and use just CCMP.

// ----------------------------------------------------------------------------------------------
// ------------------------------------ NEW AP Implementation ----------------------------------
Expand All @@ -43,7 +44,7 @@ class APClass: public NetworkInterface {
bool begin();
bool end();

bool create(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
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);
bool clear();

bool bandwidth(wifi_bandwidth_t bandwidth);
Expand Down Expand Up @@ -71,9 +72,9 @@ class WiFiAPClass
public:
APClass AP;

bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
bool softAP(const String& ssid, const String& passphrase = emptyString, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false) {
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder);
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);
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) {
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder, auth_mode, cipher);
}

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

0 comments on commit 5cb167f

Please sign in to comment.