EspNow concepts
Posted: Fri Jun 15, 2018 4:38 pm
I have a hard time understanding ESPNOW.
In principle it would be quite easy: select the same channel on *both* devices, transmit on one device on this channel, and receive on another device on this channel. ESPNOW (apparently) does 2 transmissions behind the scenes, one from the sender (data), one reply from the receiver (confirmation). The only complexity would seem to be the slave-list where ESPNOW driver saves info on the slave, like its channel. Also there needs to be a way to get slave addresses. Sofar so good.
However I have downloaded 2 "sketches", one is the master and one is the slave. The master sketch has a "channel" setting (in esp_now_peer_info_t which enters esp_now_add_peer()), the slave sketch doesn't. However, changing the channel doesn't interrupt the connection as expected (and I have no reason to suspect the setting is being ignored).
So that's a big question mark. How do the master and slave connect? What happens behind the scenes? Docs are very thin and talk to those that really know Wifi. Does something depend on Wifi transmissions/protocol and not ESPNOW (because both sketches use `WiFi.mode(WIFI_STA);`)??
In principle it would be quite easy: select the same channel on *both* devices, transmit on one device on this channel, and receive on another device on this channel. ESPNOW (apparently) does 2 transmissions behind the scenes, one from the sender (data), one reply from the receiver (confirmation). The only complexity would seem to be the slave-list where ESPNOW driver saves info on the slave, like its channel. Also there needs to be a way to get slave addresses. Sofar so good.
However I have downloaded 2 "sketches", one is the master and one is the slave. The master sketch has a "channel" setting (in esp_now_peer_info_t which enters esp_now_add_peer()), the slave sketch doesn't. However, changing the channel doesn't interrupt the connection as expected (and I have no reason to suspect the setting is being ignored).
So that's a big question mark. How do the master and slave connect? What happens behind the scenes? Docs are very thin and talk to those that really know Wifi. Does something depend on Wifi transmissions/protocol and not ESPNOW (because both sketches use `WiFi.mode(WIFI_STA);`)??
Code: Select all
The slave has only this sequence:
WiFi.mode(WIFI_STA);
esp_now_init();
esp_now_register_recv_cb(rx_callback);
The master uses this sequence:
WiFi.mode(WIFI_STA);
esp_now_init();
esp_now_add_peer(...); // channel set
esp_now_register_send_cb(sent_callback);
esp_now_send(...);