ESP-NOW bi-directional communications --- send & receive

robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Thu Jan 11, 2018 4:21 am

Hello,
I'm trying to get 2 ESP32 Dev Boards to talk to each other.

I started with the master-slave examples from the Arduino IDE, and got that working fine. In that example 'master' is set to STA, and 'slave' is set to AP. 'Master' sends a message to 'slave', and 'slave' prints the message to serial.

When I try to send a message from the slave back to the master using the 'from' MAC address, it says:
Send Status: Peer not found.
I've registered send and receive callbacks for both boards.

I am a total newbie at this kind of communications programming, so I am probably missing something very obvious to most of you. I've been reading a lot for the past week and still haven't cracked this.

Do I need to use WIFI_AP_STA to be able to both send and receive messages? Or ?????

Any help or hints or pseudo-code would be greatly appreciated.

Thanks Robby in NC, USA

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby WiFive » Thu Jan 11, 2018 5:01 am

Did you esp_now_add_peer on both sides

robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Thu Jan 11, 2018 5:35 am

No I didn't. I'll try that right now.

I just realized that I posted this in the wrong forum --- SDK instead of Arduino. Can I change that?

Thanks, Robby

robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Thu Jan 11, 2018 6:03 am

Tried esp_now_add_peer in 'slave' module, now I get:

Send Status: Not sure what happened

I set:
peer.peer_addr to mac address of master
peer.channel to same channel as master ?? not sure if this should be different
peer.encrypt to 0

Wondering if I should delete this post and repost in ESP32 Arduino
Thanks, Robby

robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Thu Jan 11, 2018 7:26 pm

Re-posting in ESP Arduino
Robby

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby WiFive » Fri Jan 12, 2018 3:18 am


robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Fri Jan 12, 2018 5:58 am

Thanks. I've been looking at that for a while now and also the "esp-now_user_guide_.pdf", but some of the terminology, names and methods seem very different.

Haven't quite figured out what is meant by "state" --- is that wifi mode like AP or STA?

I have a 'supposedly' sucessful pair from the slave back to the master, but when I try to send a message back to the master, it fails.

Also I notice that the slave APmac and mac addresses are different. APmac is mac+1 . Master is paired with the APmac of slave and successfully sends messages to it.

Maybe the slave sends from regular mac and master doesn't recognize it???

Still reading, trying and cursing --- R

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP-NOW bi-directional communications --- send & receive

Postby chegewara » Fri Jan 12, 2018 6:44 am

Maybe its little offtopic but it can help to explain why AP mac is different than other:
http://esp-idf.readthedocs.io/en/latest ... ac-address

robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Fri Jan 12, 2018 7:03 am

Not off topic at all --- thanks.
I remembered reading something about that somewhere, but did not remember where.
I don't really understand why MAC addresses need to be changed, though.

I don't suppose that 0 or 1 added to MAC is the "state" that is mentioned here:
https://github.com/espressif/esp-idf/tr ... ifi/espnow ????

Thanks again -R

robbyr
Posts: 8
Joined: Thu Jan 11, 2018 3:58 am

Re: ESP-NOW bi-directional communications --- send & receive

Postby robbyr » Fri Jan 12, 2018 7:45 am

Well, a small success in figuring this out.

Turns out the esp-now code in the arduino examples that I copied did not check for:

ESP_ERR_ESPNOW_IF : current WiFi interface doesn't match that of peer

That is the error I'm getting.

Code: Select all

typedef struct esp_now_peer_info {
    uint8_t peer_addr[ESP_NOW_ETH_ALEN];	/**< ESPNOW peer MAC address that is also the MAC address of station or softap */
    uint8_t lmk[ESP_NOW_KEY_LEN];			/**< ESPNOW peer local master key that is used to encrypt data */
    uint8_t channel;						/**< Wi-Fi channel that peer uses to send/receive ESPNOW data. If the value is 0,
    										use the current channel which station or softap is on. Otherwise, it must be 
    										set as the channel that station or softap is on. */
    wifi_interface_t ifidx;					/**< Wi-Fi interface that peer uses to send/receive ESPNOW data */
    bool encrypt;						/**< ESPNOW data that this peer sends/receives is encrypted or not */
    void *priv;							/**< ESPNOW peer private data */
} esp_now_peer_info_t;
SoI guess that would be peer.ifidx which I have set to ESP_IF_WIFI_STA. That is what master is set to --- is that right???

Thanks -R

Who is online

Users browsing this forum: No registered users and 48 guests