Skip to content

Added ESPNow Multi-Slave example #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 27, 2017
Merged

Conversation

arvindr21
Copy link
Contributor

Added a basic example for ESPNow, where a master discovers a slave(s) dynamically and sends data without connecting to them using ESPNow Technology.

Example Gist

/**
   ESPNOW - Basic communication - Master
   Date: 26th September 2017
   Author: Arvind Ravulavaru <https://github.com/arvindr21>
   Purpose: ESPNow Communication between a Master ESP32 and multiple ESP32 Slaves
   Description: This sketch consists of the code for the Master module.
   Resources: (A bit outdated)
   a. https://espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf
   b. http://www.esploradores.com/practica-6-conexion-esp-now/

   << This Device Master >>

   Flow: Master
   Step 1 : ESPNow Init on Master and set it in STA mode
   Step 2 : Start scanning for Slave ESP32 (we have added a prefix of `slave` to the SSID of slave for an easy setup)
   Step 3 : Once found, add Slave as peer
   Step 4 : Register for send callback
   Step 5 : Start Transmitting data from Master to Slave(s)

   Flow: Slave
   Step 1 : ESPNow Init on Slave
   Step 2 : Update the SSID of Slave with a prefix of `slave`
   Step 3 : Set Slave in AP mode
   Step 4 : Register for receive callback and wait for data
   Step 5 : Once data arrives, print it in the serial monitor

   Note: Master and Slave have been defined to easily understand the setup.
         Based on the ESPNOW API, there is no concept of Master and Slave.
         Any devices can act as master or salve.


  // Sample Serial log with 1 master & 2 slaves
      Found 12 devices 
      1: Slave:24:0A:C4:81:CF:A4 [24:0A:C4:81:CF:A5] (-44)
      3: Slave:30:AE:A4:02:6D:CC [30:AE:A4:02:6D:CD] (-55)
      2 Slave(s) found, processing..
      Processing: 24:A:C4:81:CF:A5 Status: Already Paired
      Processing: 30:AE:A4:2:6D:CD Status: Already Paired
      Sending: 9
      Send Status: Success
      Last Packet Sent to: 24:0a:c4:81:cf:a5
      Last Packet Send Status: Delivery Success
      Send Status: Success
      Last Packet Sent to: 30:ae:a4:02:6d:cd
      Last Packet Send Status: Delivery Success

*/

@me-no-dev
Copy link
Member

does the slave know that it has been attached? I wonder if we can in a way hide the SSID or switch to STA mode once they are configured, so you do not have to blast as many APs as there are devices.

@arvindr21
Copy link
Contributor Author

arvindr21 commented Sep 27, 2017

I understand what you are asking. I was trying for the same.

Based on the available poor docs, this is what I found:

screen shot 2017-09-27 at 10 19 02

Source: http://www.esploradores.com/practica-6-conexion-esp-now/

I was successfully able to get the setup working with Master in STA and Slave in AP or AP + STA only. Not sure if hiding SSID of slave after receiving 1st packet of data will help or not. Need to test.

@me-no-dev
Copy link
Member

at the same time the slave will not know if master dropped and the master will have no way to reconnect back again (unless slave mac is cached) so maybe the current behavior is what we should use...

@arvindr21
Copy link
Contributor Author

Yes, but I am testing a few scenarios, which will help us achieve the hidden SSID setup. I will probably have a different sketch for that. Don't want to mix that with this.

What say?

@me-no-dev
Copy link
Member

cool with me

@me-no-dev me-no-dev merged commit a66b544 into espressif:master Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants