I am trying to change some peer channel to a default value, i implemented the following code:
bool changeToDefaultChannel(){
esp_now_del_peer(slave.peer_addr);
esp_wifi_set_channel(CHANNEL_DEFAULT, WIFI_SECOND_CHAN_NONE);
esp_now_peer_info_t slave_aux;
memcpy(slave_aux.peer_addr, MAC_slave, 6);
slave_aux.channel = CHANNEL_DEFAULT; // pick a channel
slave_aux.encrypt = 0; // no encryption
if (esp_now_add_peer(&slave_aux) != ESP_OK) {
Serial.println("Error al actualizar el canal del peer");
return false;
}else{
Serial.println("Se cambió correctamente de canal la ESP32");
return true;
}
}
In this code the i wanted to change the slave channel to a channel_default, first i delete the peer and then i add it again with the other channel, i use esp_wifi_set_channel to change the esp channel too. (i do the same code in the slave device to change the master to the default channel). I get this error "E (167155) ESPNOW: Peer interface is invalid", i dont know how to solve this (i asked to chat GPT and it told me nonsenses)
esp_now_peer_info_tis a struct that consists of theifidx- Wi-Fi interface that peer uses to send/receive ESPNOW data. The message telling you exactly that, you have an invalid peer interface. If you create an instance ofesp_now_peer_info_twithesp_now_peer_info_t slave_aux;without initialise it, you may get junk inifidxvalue. It is a good practise to always initalise a struct that you created:or
You now at least have a valid
ifidxvalue of 0, you can then decide to set it toWIFI_IF_STA(0 = default) orWIFI_IF_APif necessary.BTW, to ask chatGPT for help is like to ask to be spoon-feed, you might survive for one meal, but it won't get you far. Do research yourself, try to find out what the error message mean and read the document is like learning how to cook, it will benefit you for the rest of your life. There is simply no short cut...