30
30
#define ESPNOW_WIFI_CHANNEL 1
31
31
32
32
#if ESPNOW_WIFI_MODE_STATION // ESP-NOW using WiFi Station mode
33
- #define ESPNOW_WIFI_IF WIFI_IF_STA
34
- #define GET_IF_MAC WiFi.macAddress
33
+ #define ESPNOW_WIFI_MODE WIFI_STA // WiFi Mode
34
+ #define ESPNOW_WIFI_IF WIFI_IF_STA // WiFi Interface
35
35
36
36
// Set the MAC address of the device that will receive the data
37
37
// For example: F6:12:FA:42:B6:E8
38
38
const MacAddress peer_mac ({0xF6 , 0x12 , 0xFA , 0x42 , 0xB6 , 0xE8 });
39
39
#else // ESP-NOW using WiFi AP mode
40
- #define ESPNOW_WIFI_IF WIFI_IF_AP
41
- #define GET_IF_MAC WiFi.softAPmacAddress
40
+ #define ESPNOW_WIFI_MODE WIFI_AP // WiFi Mode
41
+ #define ESPNOW_WIFI_IF WIFI_IF_AP // WiFi Interface
42
42
43
43
// Set the MAC address of the device that will receive the data
44
44
// For example: F4:12:FA:40:64:4C
@@ -51,22 +51,15 @@ void setup() {
51
51
Serial.begin (115200 );
52
52
53
53
Serial.print (" WiFi Mode: " );
54
-
55
- #if ESPNOW_WIFI_MODE_STATION
56
- Serial.println (" STA" );
57
- WiFi.mode (WIFI_STA);
58
- // ToDo: Set the channel using WiFi.setChannel() when using Station mode
59
- esp_wifi_set_channel (ESPNOW_WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE);
60
- #else
61
- Serial.println (" AP" );
62
- WiFi.softAP (WiFi.getHostname (), NULL , ESPNOW_WIFI_CHANNEL, 1 );
63
- #endif
54
+ Serial.println (ESPNOW_WIFI_MODE == WIFI_AP ? " AP" : " Station" );
55
+ WiFi.mode (ESPNOW_WIFI_MODE);
64
56
65
57
Serial.print (" Channel: " );
66
58
Serial.println (ESPNOW_WIFI_CHANNEL);
59
+ WiFi.setChannel (ESPNOW_WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE);
67
60
68
61
Serial.print (" MAC Address: " );
69
- Serial.println (GET_IF_MAC ());
62
+ Serial.println (ESPNOW_WIFI_MODE == WIFI_AP ? WiFi. softAPmacAddress () : WiFi. macAddress ());
70
63
71
64
// Start the ESP-NOW communication
72
65
Serial.println (" ESP-NOW communication starting..." );
0 commit comments