ESP-NOW help with encryption (PMK/LMK)

MStackoverflow
Posts: 14
Joined: Mon Oct 07, 2019 4:55 pm

ESP-NOW help with encryption (PMK/LMK)

Postby MStackoverflow » Mon Oct 07, 2019 6:20 pm

Hi,

I have to do a module for a project and security is needed. I want to encrypt the communication.

I've read the docs and I can't make the esp_now_peer_info_t::encrypt work.

I've made a peers on both sides (master/slave), put the same peer LMK, put the same PMK, set the slave into APSTA mode.
when I put

Code: Select all

slave.encrypt = true
, the Master says the message sent was successful but the slave does not receive it.

Can someone guide me through how encryption work?

MStackoverflow
Posts: 14
Joined: Mon Oct 07, 2019 4:55 pm

Re: ESP-NOW help with encryption (PMK/LMK)

Postby MStackoverflow » Mon Nov 25, 2019 11:04 pm

Hi, sorry for double posting.

Anyone can help me?

iParcelBox
Posts: 27
Joined: Sun Oct 27, 2019 3:12 pm

Re: ESP-NOW help with encryption (PMK/LMK)

Postby iParcelBox » Sun Feb 23, 2020 6:45 pm

Did you ever manage to resolve this? I'm having exactly the same issue - sender says message sent OK, but never received on the slave.

Ankit Siddhapura
Posts: 21
Joined: Sat Jun 30, 2018 1:04 pm

Re: ESP-NOW help with encryption (PMK/LMK)

Postby Ankit Siddhapura » Mon May 11, 2020 10:24 am

I am facing same issue.
Seems packet received at MAC layer and discarded before reaches to application layer.

Guys, did you find root cause or solution of this issue?

MStackoverflow
Posts: 14
Joined: Mon Oct 07, 2019 4:55 pm

Re: ESP-NOW help with encryption (PMK/LMK)

Postby MStackoverflow » Wed Aug 12, 2020 6:56 pm

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);

Who is online

Users browsing this forum: No registered users and 48 guests