I manage to make it work a while ago. I don't remember how I solved the problem. I think it has to do with the call order of functions.
Here's the setup code (Slave and master don't have the same meaning for me):
Note that you could use memcpy instead of loops.
Master Side (Slave is a custom Object)
Code: Select all
WiFi.mode(WIFI_MODE_STA);
WiFi.disconnect();
esp_now_init();
esp_now_register_recv_cb(OnDataRecv);
esp_now_register_send_cb(OnDataSent);
esp_now_set_pmk(key);
esp_wifi_set_protocol( WIFI_IF_AP, WIFI_PROTOCOL_LR);
for(int j=0;j<6;j++){
slave.info.peer_addr[j] = slave.macAddress[j];
}
for(int j=0;j<16;j++){
slave.info.lmk[j] = key[j];
}
slave.info.channel = 12;
slave.info.encrypt = 1;
esp_now_add_peer(&slave[i].info);
Slave Side (master is a custom object)
Code: Select all
for(int i=0;i<=6;i++){
master.peer_addr[i] = masterMac[i];
}
for(int i=0;i<16;i++){
master.lmk[i] = key[i];
}
master.channel = 12;
master.encrypt = 1;
WiFi.mode(WIFI_STA);
WiFi.disconnect();
esp_now_init();
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
esp_now_set_pmk(key);
esp_wifi_set_protocol( WIFI_IF_AP, WIFI_PROTOCOL_LR);
esp_now_add_peer(&master);