Is it possible to use ESP-NOW and conenct to a WiFi network
Posted: Tue Apr 27, 2021 10:29 pm
I would like to ask some about something that did not work out for me. I am using PlatformIO. I have been trying to use one ESP32 to communicate with an ESP8266 using ESP-NOW and report back to a Wifi network that the ESP32 will connect to. This is a code that only initializes the ESP-NOW, without connecting to a Wifi network on the ESP32 board, it worked fine for me while communicating with the ESP8266:
Now, if I want it to connect to a network, I place the following line right before the "esp_now_init()", after adding this line, it successfully connects to the network, but the ESP-NOW stops sending nor receiving any messages :
Here are my questions, is it even possible to connect to a Wifi network and use ESP-NOW at the same time? if it is possible, how can I get it to work? I am thankful for this forum and your hard work in it.
- void setup() {
- Serial.begin(9600);
- WiFi.mode(WIFI_STA);
- // Get Mac Add
- Serial.print("Mac Address: ");
- Serial.println(WiFi.macAddress());
- // Initializing the ESP-NOW
- if (esp_now_init() != 0) {
- Serial.println("Problem during ESP-NOW init");
- return;
- }
- esp_now_register_recv_cb(onDataReceiver);
- esp_now_register_send_cb(onSent);
- esp_now_peer_info_t* peer = new esp_now_peer_info_t;
- memcpy(peer->peer_addr, slaveAddr, 6);
- peer->channel = 4;
- peer->encrypt = false;peer->ifidx = ESP_IF_WIFI_STA;
- esp_now_add_peer(peer);
- esp_now_send(slave1, dataToSend, sizeof(dataToSend));
- }
- WiFi.begin(networkSSID, networkPassword)