mode selector convert espNOW

sebasdt
Posts: 5
Joined: Fri Jul 24, 2020 8:18 am

mode selector convert espNOW

Postby sebasdt » Sat Oct 17, 2020 2:05 pm

The idea behind this is:
I have made a Led matrix and want to "easily" change modes or set a value something, another person has done this(diod-dev https://github.com/Diod-dev/New_Visualizer_Skeleton) but it's done with serial communication and not espnow

The slave esp32 reads and acts on incoming messages from the master esp32, in the format of '< (letter) (3 digit number) >'.
For example, I would like to set the brightness to 50% then would send <B128>.

here are the example codes:
master

Code: Select all

void setup{
Serial.begin(115200); // Serial monitor output
  Serial2.begin(115200);
  pinMode(ledPin, OUTPUT);
}
void loop() {

}

int updateCurrentBrightness() {
  currentBrightness = inputMasterBrightness.toInt();
  return currentBrightness;
}

void sendRequest(int req) {
  switch (req) {
  case 0:
    currentMode = req;
    Serial2.write('<');
    Serial2.write('f');
    Serial2.write('0');
    Serial2.write('0');
    Serial2.write('0');
    Serial2.write('>');
    break;
  case 1:
    currentMode = req;
    Serial2.write('<');
    Serial2.write('o');
    Serial2.write('0');
    Serial2.write('0');
    Serial2.write('0');
    Serial2.write('>');
    break;
  case 2:
    currentMode = req;
    Serial2.write('<');
    Serial2.write('s');
    for (int i = 0; i < inputHue.length(); i++) {
      Serial2.write(inputHue[i]);
    }
    Serial2.write('>');
    break;
  case 3:
    currentMode = req;
    Serial2.write('<');
    Serial2.write('t');
    for (int i = 0; i < inputSat.length(); i++) {
      Serial2.write(inputSat[i]);
    }
    Serial2.write('>');
    break;
  case 4:
    currentMode = req;
    Serial2.write('<');
    Serial2.write('b');
    for (int i = 0; i < inputVal.length(); i++) {
      Serial2.write(inputVal[i]);
    }
    Serial2.write('>');
    break;
  case 5:
    currentMode = req;
    sendMVMode(req);
    break;
  case 6:
    currentMode = req;
    sendMVMode(req);
    break;
  case 7:
    currentMode = req;
    sendMVMode(req);
    break;
  case 8:
    currentMode = req;
    sendMVMode(req);
    break;
  case 9:
    currentMode = req;
    sendMVMode(req);
    break;
  case 10:
    currentMode = req;
    sendMVMode(req);
    break;
  case 11:
    currentMode = req;
    sendMVMode(req);
    break;
  case 12:
    currentMode = req;
    sendMVMode(req);
    break;
  case 13:
    currentMode = req;
    sendMVMode(req);
    break;
  case 14:
    currentMode = req;
    sendMVMode(req);
    break;
  case 15:
    currentMode = req;
    sendMVMode(req);
    break;
  case 16:
    currentMode = req;
    sendMVMode(req);
    break;
  case 17:
    currentMode = req;
    sendAmbMode(req);
    break;
  case 18:
    currentMode = req;
    sendAmbMode(req);
    break;
  case 19:
    currentMode = req;
    sendAmbMode(req);
    break;
  case 20:
    currentMode = req;
    sendAmbMode(req);
    break;
  case 21:
    currentMode = req;
    sendAmbMode(req);
    break;
  case 22:
    currentMode = req;
    sendAmbMode(req);
    break;
  case 23:
    //currentMode = req;
    Serial2.write('<');
    Serial2.write('z');
    for (int i = 0; i < inputMasterBrightness.length(); i++) {
      Serial2.write(inputMasterBrightness[i]);
    }
    Serial2.write('>');
    break;
  case 98:
    currentMode = req;
    Serial2.write('<');
    Serial2.write('x');
    Serial2.write('0');
    Serial2.write('0');
    Serial2.write('0');
    Serial2.write('>');
    break;
  case 99:
    Serial2.write('<');
    Serial2.write('y');
    for (int i = 0; i < inputAudioMultiplier.length(); i++) {
      Serial2.write(inputAudioMultiplier[i]);
    }
    Serial2.write('>');
    break;
  }
}

void sendMVMode(int req) {
  currentMode = req;
  Serial2.write('<');
  Serial2.write('m');
  sendMode = currentMode - 4;
  sendModeStr = (String)sendMode;
  for (int i = 0; i < sendModeStr.length(); i++) {
    Serial2.write(sendModeStr[i]);
  }
  Serial2.write('>');
}

void sendAmbMode(int req) {
  currentMode = req;
  Serial2.write('<');
  Serial2.write('a');
  sendMode = currentMode - 16;
  sendModeStr = (String)sendMode;
  for (int i = 0; i < sendModeStr.length(); i++) {
    Serial2.write(sendModeStr[i]);
  }
  Serial2.write('>');
}
slave

Code: Select all

// This file handles all incoming messages from ESP-32
// Reads and acts on incoming messages from ESP - 32, in the format of '< (letter) (3 digit number) >'. For exmaple, <b200>

// Variables for solid color
uint8_t solidHue = 0;
uint8_t solidSat = 255;
uint8_t solidVal = 255;

const byte numChars = 10;
char receivedChars[10];
char tempChars[3];

// TODO: use 'categories' instead of letters. 
// variables to hold parsed data
//char category[1] = { 0 };
//int instruction = 0;

bool newCommand = false;

int audioMultiplier; // temp input variable before recording this input in variable 'mult'

void setup{
Serial.begin(115200); // Serial monitor output
  Serial2.begin(115200); 
  pinMode(ledPin, OUTPUT);
}

void doThingsWithCommands() {
  if (receivedChars[0] == 'a') { // Chooses an ambient pattern and displays it
    for (int i = 0; i < 3; i++) // Record the next 3 characters (numbers) to a holding string 'tempChars'
      tempChars[i] = receivedChars[i + 1];
    ambPattern = atoi(tempChars); // convert 'tempChars' to integer.
    patternMode = 3; // Used in normalOperation()
    Serial.println(ambPattern);
  }
  else if (receivedChars[0] == 'b') {  // Sets the brightness when displaying a solid color
    patternMode = 4; // Used in normalOperation() to display a solid color
    for (int i = 0; i < 3; i++)
      tempChars[i] = receivedChars[i + 1];
    solidVal = atoi(tempChars); // 'atoi' converts string of characters to integer
  }
  else if (receivedChars[0] == 'f') { // The off button is set, last pattern mode is saved.
    patternModeOld = patternMode;
    patternMode = 0; // Used in normalOperation() to turn all LEDs off
  }
  else if (receivedChars[0] == 'm') { // Chooses a music-visualizing pattern and displays it
    for (int i = 0; i < 3; i++)
      tempChars[i] = receivedChars[i + 1];
    MVPattern = atoi(tempChars);
    patternMode = 2; // Used in normalOperation() to display a single music-visualizing pattern
    Serial.println(patternMode);
  }
  if (receivedChars[0] == 'o') {
    Serial.println(patternModeOld);
    patternMode = patternModeOld; // Used in normalOperation(), returns to last patternMode
  }
  else if (receivedChars[0] == 's') {
    patternMode = 4; // Used in normalOperation() to display a solid color
    for (int i = 0; i < 3; i++)
      tempChars[i] = receivedChars[i + 1];
    solidHue = atoi(tempChars); 
  }
  else if (receivedChars[0] == 't') {
    patternMode = 4; // Used in normalOperation() to display a solid color
    for (int i = 0; i < 3; i++)
      tempChars[i] = receivedChars[i + 1];
    solidSat = atoi(tempChars);
  }
  else if (receivedChars[0] == 'x') {
    patternMode = 1; // Used in normalOperation() to enter mode of changing music-visualization patterns to the music
  }
  else if (receivedChars[0] == 'y') {
    for (int i = 0; i < 3; i++)
      tempChars[i] = receivedChars[i + 1];
    audioMultiplier = atoi(tempChars);
    mult = (double)audioMultiplier / 100;
  }
  else if (receivedChars[0] == 'z') {
    for (int i = 0; i < 3; i++)
      tempChars[i] = receivedChars[i + 1];
    masterBrightness = atoi(tempChars);
  }
  else {}
}

// Reads incoming message from ESP-32, in the format of '< (letter) (3 digit number) >'. For exmaple, (<b200>)
void recWithStartEndMarkers() {
  static boolean recInProgress = false; // is a message currently being received?
  static byte ndx = 0; // index variable as receivedChars[] array populates
  char startMarker = '<'; // the first character sent by ESP-32 in a message
  char endMarker = '>'; // the last character sent by ESP-32 in a message
  char rc; // rc = each character as it comes in

  // While serial1 data is available and newCommand == false (the endMarker '>' hasn't been received yet)
  while (Serial1.available() && newCommand == false) {
    rc = Serial1.read(); // rc = new incoming character
    if (recInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        //if (ndx >= numChars) // THESE 2 LINES FUCK UP THE LEDS
        //  ndx = numChars - 1;
      }
      else {
        receivedChars[ndx] = '\0';
        recInProgress = false;
        ndx = 0;
        newCommand = true;
      }
    }
    else if (rc == startMarker)
      recInProgress = true;
    else {}
  }
}

void parseData() {
  if (newCommand == true) {
    for (int i = 0; i < 4; i++) 
      Serial.print(receivedChars[i]);
    
    Serial.println();

    doThingsWithCommands();

    newCommand = false;
  }
}

void talkToESP() {
  recWithStartEndMarkers(); // constantly looking out for new messages
  parseData(); // after a message is received, act on it
}

ESP_Sprite
Posts: 4106
Joined: Thu Nov 26, 2015 4:08 am

Re: mode selector convert espNOW

Postby ESP_Sprite » Sun Oct 18, 2020 3:00 am

Okay; do you have a question?

sebasdt
Posts: 5
Joined: Fri Jul 24, 2020 8:18 am

Re: mode selector convert espNOW

Postby sebasdt » Sun Oct 18, 2020 9:35 am

oh sorry, I thought that I added the questions.

but anyway, I want to convert the code I provided from serial communication to espNOW.
what need to know if it's possible to send the format or characters (<b000>) via espNOW and how.
what would be the max number that I could send with espnow?

an idea I had was that you put the "ready to send format" in a char or string array and somehow send it over espnow

ESP_Sprite
Posts: 4106
Joined: Thu Nov 26, 2015 4:08 am

Re: mode selector convert espNOW

Postby ESP_Sprite » Tue Oct 20, 2020 1:55 am

Yes, that's perfectly possible. Per here you can send 250 bytes at a time; to send more, you'd need to implement some kind of fragmentation scheme.

sebasdt
Posts: 5
Joined: Fri Jul 24, 2020 8:18 am

Re: mode selector convert espNOW

Postby sebasdt » Fri Oct 23, 2020 1:08 pm

sorry for the long wait.
But in the meanwhile, I have found working codes for sending and receiving https://techtutorialsx.com/2019/10/27/e ... w-message/ also tried to learn how structs work and how to put data in them. searched it up and found this video about this topic. https://www.youtube.com/watch?v=1fi2CPGcdA8


I started to make code of what I have learned from the video and stumbled upon a compiler error. while trying to send the struct via espnow

This is al new for me, don't know what it really means.
I think that the way I'm trying to send the struct variable is causing problems.

Code: Select all

Arduino\simple_mode_espnow_struct\simple_mode_espnow_struct.ino: In function 'void sendData()':
simple_mode_espnow_struct:296:78: error: expected primary-expression before ',' token
      esp_err_t result = esp_now_send(peer_addr, (uint8_t *) &send_Mode_struct, sizeof(send_Mode_struct));
                                                                              ^
exit status 1
expected primary-expression before ',' token
here is the code I made and where the problem is.

Code: Select all

// Import required libraries//

#include <esp_now.h>
#include <WiFi.h>

#define CHANNEL 3
#define NUM_SLAVES 20                   // ESP-Now can handle a maximum of 20 slaves
#define PRINTSCANRESULTS 0
const int DATASIZE = 48;
String modes;

int slaveCount = 0;                     // Keeps count of no. of slaves with the defined prefix
esp_now_peer_info_t slaves[NUM_SLAVES]; // Stores the information of each of the slave that is added as a peer

void initESPNow();
void manageSlaves();
void scanForSlaves();
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);
void onDataRecv(const uint8_t *mac_add, const uint8_t *data, int data_len);
void sendData();//to send the "normal" data

int number(int a, int b) {
  int n = random(a, b);
  return n;
}
char *alphabet[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "L", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

typedef struct {
  char *b;//begin character <
  char *Mode; //mode letter (alphabet)
  int Value; // value for the mode 0-255
  char *e; //end character >
} send_Mode_struct;

send_Mode_struct sendMode;
void setup() {

  // Serial port for debugging purposes
  Serial.begin(115200); // Serial monitor output
  pinMode(2, OUTPUT);

  //Set device in STA mode to begin with
  WiFi.mode(WIFI_MODE_STA);

  // This is the mac address of the Master in Station Mode
  Serial.print("STA MAC: ");
  Serial.println(WiFi.macAddress());

  // Init ESPNow with a fallback logic
  initESPNow();

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(onDataSent);
  esp_now_register_recv_cb(onDataRecv);

  scanForSlaves();
  manageSlaves();

  // send_Mode_struct sendMode;
  int i = number(0, 26);
  sendMode.b = "<";
  sendMode.Mode = alphabet[i];
  sendMode.Value = number(0, 255);
  sendMode.e = ">";

  // put your setup code here, to run once:
  delay(500);
  printStruct();
  Serial.println("setup done");
}

void loop() {
  // put your main code here, to run repeatedly:
  sendRandom();
  delay(500);
  printStruct();
  delay(1000);
}

void sendRandom() {

  //send_Mode_struct sendMode;
  Serial.println("picking random number and letter");
  int i = number(0, 26);
  sendMode.Mode = alphabet[i];
  sendMode.Value = number(0, 255);
  Serial.println("done picking random number letter");
}

void printStruct()
{
  //send_Mode_struct sendMode;
  Serial.println("sending mode");
  Serial.printf(sendMode.b);
  Serial.printf(sendMode.Mode);
  Serial.print(sendMode.Value);
  Serial.printf(sendMode.e);
  Serial.println("");
  Serial.println("done sending modes");
}
// Init ESP Now with fallback
void initESPNow()
{
  WiFi.disconnect();
  if (esp_now_init() == ESP_OK)
  {
    Serial.println("ESPNow Init Success");
  }
  else
  {
    Serial.println("ESPNow Init Failed");
    ESP.restart();
  }
}

// Scan for slaves in AP mode
void scanForSlaves()
{
  int8_t scanResults = WiFi.scanNetworks();

  //reset slaves
  memset(slaves, 0, sizeof(slaves));
  slaveCount = 0;

  Serial.println("");

  if (scanResults == 0)
  {
    Serial.println("No WiFi devices in AP Mode found");
  }
  else
  {
    Serial.print("Found ");
    Serial.print(scanResults);
    Serial.println(" devices ");

    for (int i = 0; i < scanResults; i++)
    {
      // Print SSID and RSSI for each device found
      String SSID = WiFi.SSID(i);
      int32_t RSSI = WiFi.RSSI(i);
      String BSSIDstr = WiFi.BSSIDstr(i);

      if (PRINTSCANRESULTS)
      {
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.print(SSID);
        Serial.print(" [");
        Serial.print(BSSIDstr);
        Serial.print("]");
        Serial.print(" (");
        Serial.print(RSSI);
        Serial.print(")");
        Serial.println("");
      }

      delay(10);

      // Check if the current device starts with `Slave`
      if (SSID.indexOf("Slave") == 0)
      {
        // SSID of interest
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.print(SSID);
        Serial.print(" [");
        Serial.print(BSSIDstr);
        Serial.print("]");
        Serial.print(" (");
        Serial.print(RSSI);
        Serial.print(")");
        Serial.println("");

        // Get BSSID => Mac Address of the Slave
        int mac[6];

        if (6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x%c",  &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]))
        {
          for (int j = 0; j < 6; j++)
          {
            slaves[slaveCount].peer_addr[j] = (uint8_t)mac[j];
          }
        }

        slaves[slaveCount].channel = CHANNEL; // pick a channel
        slaves[slaveCount].encrypt = 0; // no encryption
        slaveCount++;
      }
    }
  }

  if (slaveCount > 0)
  {
    Serial.print(slaveCount); Serial.println(" Slave(s) found, processing..");
  }
  else
  {
    Serial.println("No Slave Found, trying again.");
  }

  // clean up ram
  WiFi.scanDelete();
}

// Check if the slave is already paired with the master.
// If not, pair the slave with master
void manageSlaves()
{
  if (slaveCount > 0)
  {
    for (int i = 0; i < slaveCount; i++)
    {
      const esp_now_peer_info_t *peer = &slaves[i];
      const uint8_t *peer_addr = slaves[i].peer_addr;
      Serial.print("Processing: ");

      for (int j = 0; j < 6; j++)
      {
        Serial.print((uint8_t) slaves[i].peer_addr[j], HEX);
        if (j != 5)
        {
          Serial.print(":");
        }
      }

      Serial.print(" Status: ");

      // check if the peer exists
      bool exists = esp_now_is_peer_exist(peer_addr);
      if (exists)
      {
        // Slave already paired.
        Serial.println("Already Paired");
      }
      else
      {
        // Slave not paired, attempt pair
        esp_err_t addStatus = esp_now_add_peer(peer);
        if (addStatus == ESP_OK)
        {
          // Pair success
          Serial.println("Pair success");
        }
        else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT)
        {
          // How did we get so far!!
          Serial.println("ESPNOW Not Init");
        }
        else if (addStatus == ESP_ERR_ESPNOW_ARG)
        {
          Serial.println("Add Peer - Invalid Argument");
        }
        else if (addStatus == ESP_ERR_ESPNOW_FULL)
        {
          Serial.println("Peer list full");
        }
        else if (addStatus == ESP_ERR_ESPNOW_NO_MEM)
        {
          Serial.println("Out of memory");
        }
        else if (addStatus == ESP_ERR_ESPNOW_EXIST)
        {
          Serial.println("Peer Exists");
        }
        else
        {
          Serial.println("Not sure what happened");
        }
        delay(1000);
      }
    }
  }
  else
  {
    // No slave found to process
    Serial.println("No Slave found to process");
  }
}




// send data
void sendData() {
  // pos++;

  for (int i = 0; i < slaveCount; i++) {
    const uint8_t *peer_addr = slaves[i].peer_addr;
    if (i == 0) { // print only for first slave
      Serial.print("Sending: ");
      printStruct();
    }

     esp_err_t result = esp_now_send(peer_addr, (uint8_t *) &send_Mode_struct, sizeof(send_Mode_struct));
    Serial.print("Send Status: ");
    if (result == ESP_OK) {
      Serial.println("Success");
    } else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
      // How did we get so far!!
      Serial.println("ESPNOW not Init.");
    } else if (result == ESP_ERR_ESPNOW_ARG) {
      Serial.println("Invalid Argument");
    } else if (result == ESP_ERR_ESPNOW_INTERNAL) {
      Serial.println("Internal Error");
    } else if (result == ESP_ERR_ESPNOW_NO_MEM) {
      Serial.println("ESP_ERR_ESPNOW_NO_MEM");
    } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) {
      Serial.println("Peer not found.");
    } else {
      Serial.println("Not sure what happened");
    }
    delay(100);
  }
}

// callback when data is sent from Master to Slave
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
  char macStr[18];
  // sendTime = millis();
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

  Serial.print("Last Packet Sent to: ");
  Serial.println(macStr);
  Serial.print("Last Packet Send Status: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");


}

// callback when data is received from Slave to Master
void onDataRecv(const uint8_t *mac_add, const uint8_t *data, int data_len)
{
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]);

  Serial.print("Last Packet Recv from: ");
  Serial.println(macStr);
  Serial.print("Last Packet Recv Data: ");
  Serial.println(*data);
  Serial.println("");
}

ESP_Sprite
Posts: 4106
Joined: Thu Nov 26, 2015 4:08 am

Re: mode selector convert espNOW

Postby ESP_Sprite » Sun Oct 25, 2020 12:28 pm

Send_mode_struct is the name of the typedef, the 'blueprint' of variables of that type. You can't send that. You instantiate an actual variable, Send_Mode, later; did you mean to send that instead?

sebasdt
Posts: 5
Joined: Fri Jul 24, 2020 8:18 am

Re: mode selector convert espNOW

Postby sebasdt » Mon Oct 26, 2020 9:22 am

ESP_Sprite wrote: Send_mode_struct is the name of the typedef, the 'blueprint' of variables of that type. You can't send that. You instantiate an actual variable, Send_Mode, later; did you mean to send that instead?
yes, I did mean that thanks for the tip! I'm new to structs so I don't really know why some errors are appearing.
I attached a screenshot of both serial monitors (sender and receiver).
Somehow the sender and receiver aren't printing out the chars to the serial monitor.
the receiver isn't receiving anything even when the callback function is called the struct isn't filled.
espNOW s and r fail.png
espNOW s and r fail
espNOW s and r fail.png (110.1 KiB) Viewed 390 times
code I made is here below.
sender:

Code: Select all

/*
#include <esp_now.h>
#include <WiFi.h>

// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
  char b;
  char Mode;
  int Value;
  char e;

} struct_message;

// Create a struct_message called myData
struct_message myData;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("\r\nLast Packet Send Status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

  // Register peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // Add peer
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
   myData.b, "<";
  myData.Mode, "B";
  myData.Value = random(0, 255);
  myData.e, ">";
  printStruct();
  
  }
}

void loop() {
  // Set values to send
  myData.b, "<";
  myData.Mode, "B";
  myData.Value = random(0, 255);
  myData.e, ">";
  printStruct();
  // Send message via ESP-NOW
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));

  if (result == ESP_OK) {
    Serial.println("Sent with success");
  }
  else {
    Serial.println("Error sending the data");
  } 
  delay(2000);
}

void printStruct() {

  Serial.println(sizeof(myData));
  Serial.print("Char: ");
  Serial.println(myData. b);
  Serial.print("Char: ");
  Serial.println(myData.Mode);
  Serial.print("Int: ");
  Serial.println(myData.Value);
  Serial.print("Char: ");
  Serial.println(myData.e);
  Serial.println();
}

receiver:

Code: Select all

#include <esp_now.h>
#include <WiFi.h>

// Structure example to receive data
// Must match the sender structure
typedef struct sendModestruct {
  char b[21]; // 21if you need 20 characters
  char Mode[21]; // 21 if you need 20 characters
  int Value;
  char e[21]; // 21if you need 20 characters

} sendModestruct;

// Create a struct_message called myData
sendModestruct sendMode;

// callback function that will be executed when data is received
void onDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  Serial.print("data received: ");
  Serial.println(*incomingData);
  memcpy(&sendMode, incomingData, sizeof(sendMode));
  Serial.print("Bytes received: ");
  Serial.println(len);
  printStruct();
}

void setup() {
  // Initialize Serial Monitor
  // Initialize Serial Monitor
  Serial.begin(115200);

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  Serial.println(WiFi.macAddress());
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(onDataRecv);
}

void loop() {}
void printStruct()
{
  Serial.println("printing values");
  // Serial.println(sizeof(sendModestruct));
  Serial.print("char 1: ");
  Serial.println(sendMode.b);
  Serial.print("char 2:");
  Serial.println(sendMode.Mode);
  Serial.print("int: ");
  Serial.println(sendMode.Value);
  Serial.print("char 3:");
  Serial.println(sendMode.e);
  Serial.println("");
  Serial.println("done printing values");
}

ESP_Sprite
Posts: 4106
Joined: Thu Nov 26, 2015 4:08 am

Re: mode selector convert espNOW

Postby ESP_Sprite » Tue Oct 27, 2020 4:29 am

Your sender structure and your receiver structure are not the same.

sebasdt
Posts: 5
Joined: Fri Jul 24, 2020 8:18 am

Re: mode selector convert espNOW

Postby sebasdt » Wed Oct 28, 2020 9:19 am

Thanks! I don't know why I didn't see that right away. Such a nooby mistake.
Also, thank you all for the help so far! its really appreciated!

it's working now and converted the serial mode selection to espnow with no problems so far.
The next thing to do is select if the mode select needs to be activated. that would be simple. (last famous words)

basic explanation about the code.
Do whatever you want to do with this code but please reference the original creator of the code [urhttps://github.com/Diod-dev/New_Visualizer_Skeleton[/url]
Sender:
-Search on its own for receivers and add then to the send list.
-send the struct data every few seconds.

Receiver:
- setup as a receiver and receive data and process this.

here below are the sender and receiver codes.
sender:

Code: Select all

//the original creator of this code: https://github.com/Diod-dev/New_Visualizer_Skeleton
// Import required libraries//
#include <esp_now.h>
#include <WiFi.h>

#define CHANNEL 3
#define NUM_SLAVES 3                   // ESP-Now can handle a maximum of 20 slaves
#define PRINTSCANRESULTS 0



int slaveCount = 0;                     // Keeps count of no. of slaves with the defined prefix
esp_now_peer_info_t slaves[NUM_SLAVES]; // Stores the information of each of the slave that is added as a peer

void initESPNow();
void manageSlaves();
void scanForSlaves();
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);
void sendData();//to send the mode data

// Stores LED state
uint8_t currentBrightness;
int currentMode;
int currentPattern;
int inputAudioMultiplier;

int inputHue = 0;
int inputSat = 255;
int inputVal = 255;
int inputMasterBrightness;
int sendAnimation;


//char *alphabet[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "L", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};


int number(int a, int b) {
  int n = random(a, b);
  return n;
}

// Structure example to send data
// Must match the receiver structure
typedef struct sendModestruct {
  char b[4];
  char Mode[4];
  int Value;
  char e[4];

} sendModestruct;

// Create a struct_message called sendMode
sendModestruct sendMode;

void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200); // Serial monitor output

  //Set device in STA mode to begin with
  WiFi.mode(WIFI_STA);

  // This is the mac address of the Master in Station Mode
  Serial.print("STA MAC: ");
  Serial.println(WiFi.macAddress());

  // Init ESPNow with a fallback logic
  initESPNow();

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(onDataSent);

  scanForSlaves();
  manageSlaves();
}



void loop() {
  if (slaveCount > 0)
  {
    inputVal = random(0, 360);
    inputSat = random(0, 255);
    inputHue = random(0, 255);
    inputAudioMultiplier = random(0, 255);
    currentBrightness = random(0, 255);

    for (int i = 0; i < 35; i++) {
      Serial.println(i);
      sendRequest(i);
      delay(1000);
    }
  } else {
    scanForSlaves();
    manageSlaves();
    delay(2000);
  }
}
/*
  void fillRandom() {
  //sendModestruct sendMode;
  Serial.println("picking random number and letter");
  int i = number(0, 26);
  strcpy(sendMode.Mode, alphabet[i]);
  sendMode.Value = number(0, 255);
  Serial.println("done picking random number letter");
  Serial.println("");
  }
*/
void printStruct()
{
  Serial.println("printing values");
  // Serial.println(sizeof(sendModestruct));
  Serial.print("char 1: ");
  Serial.println(sendMode.b);
  Serial.print("char 2: ");
  Serial.println(sendMode.Mode);
  Serial.print("int: ");
  Serial.println(sendMode.Value);
  Serial.print("char 3: ");
  Serial.println(sendMode.e);
  Serial.println("");
  Serial.println("done printing values");
}


int updateCurrentBrightness() {
  currentBrightness = inputMasterBrightness;
  return currentBrightness;
}

void sendRequest(int req) {
  switch (req) {
    case 0:
      currentMode = req;//off command Also sets GPIO to LOW (blue light turns off)
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "f");
      sendMode.Value = 000;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 1: // on command Also sets GPIO to HIGH (blue light turns on)
      currentMode = req;
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "o");
      sendMode.Value = 000;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 2: //send solidcolor and so a hue value
      currentMode = req;
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "s");
      sendMode.Value = inputHue;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 3:// Send the Saturation
      currentMode = req;
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "t");
      sendMode.Value = inputSat;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 4: // Send a GET request for the Brightness
      currentMode = req;
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "b");
      sendMode.Value = inputVal;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 5: //music parttern 1
      currentMode = req;
      sendMVMode(req);
      break;
    case 6://music parttern 2
      currentMode = req;
      sendMVMode(req);
      break;
    case 7://music parttern 3
      currentMode = req;
      sendMVMode(req);
      break;
    case 8://music parttern 4
      currentMode = req;
      sendMVMode(req);
      break;
    case 9://music parttern 5
      currentMode = req;
      sendMVMode(req);
      break;
    case 10://music parttern 6
      currentMode = req;
      sendMVMode(req);
      break;
    case 11://music parttern 7
      currentMode = req;
      sendMVMode(req);
      break;
    case 12://music parttern 8
      currentMode = req;
      sendMVMode(req);
      break;
    case 13://music parttern 9
      currentMode = req;
      sendMVMode(req);
      break;
    case 14://music parttern 10
      currentMode = req;
      sendMVMode(req);
      break;
    case 15://music parttern 11
      currentMode = req;
      sendMVMode(req);
      break;

    case 17://demo parttern 1
      currentMode = req;
      sendAmbMode(req);
      break;
    case 18://demo parttern 2
      currentMode = req;
      sendAmbMode(req);
      break;
    case 19://demo parttern 3
      currentMode = req;
      sendAmbMode(req);
      break;
    case 20://demo parttern 4
      currentMode = req;
      sendAmbMode(req);
      break;
    case 21://demo parttern 5
      currentMode = req;
      sendAmbMode(req);
      break;
    case 22://demo parttern 6
      currentMode = req;
      sendAmbMode(req);
      break;
    case 23://demo parttern 7
      currentMode = req;
      sendAmbMode(req);
      break;
    case 24://demo parttern 8
      currentMode = req;
      sendAmbMode(req);
      break;
    case 25://demo parttern 9
      currentMode = req;
      sendAmbMode(req);
      break;
    case 26://demo parttern 10
      currentMode = req;
      sendAmbMode(req);
      break;
    case 27://demo parttern 11
      currentMode = req;
      sendAmbMode(req);
      break;

    case 30:  // Send the master brightness to the mothership
      //currentMode = req;
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "z");
      sendMode.Value = inputMasterBrightness;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 31:// case 98 makes the patterns automatically switching
      currentMode = req;
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "x");
      sendMode.Value = 000;
      strcpy(sendMode.e, ">");
      sendData();
      break;
    case 32: // Send the audio sensitivity
      strcpy(sendMode.b, "<");
      strcpy(sendMode.Mode, "y");
      sendMode.Value = inputAudioMultiplier;
      strcpy(sendMode.e, ">");
      sendData();
      break;
  }
}

void sendMVMode(int req) {
  currentMode = req;
  sendAnimation = currentMode - 4;
  strcpy(sendMode.b, "<");
  strcpy(sendMode.Mode, "m");
  sendMode.Value = sendAnimation;
  strcpy(sendMode.e, ">");
  sendData();
}


void sendAmbMode(int req) {
  currentMode = req;
  sendAnimation = currentMode - 16;
  strcpy(sendMode.b, "<");
  strcpy(sendMode.Mode, "a");
  sendMode.Value = sendAnimation;
  strcpy(sendMode.e, ">");
  sendData();
}


// Init ESP Now with fallback
void initESPNow()
{
  WiFi.disconnect();
  if (esp_now_init() == ESP_OK)
  {
    Serial.println("ESPNow Init Success");
  }
  else
  {
    Serial.println("ESPNow Init Failed");
    ESP.restart();
  }
}

// Scan for slaves in AP mode
void scanForSlaves()
{
  int8_t scanResults = WiFi.scanNetworks();

  //reset slaves
  memset(slaves, 0, sizeof(slaves));
  slaveCount = 0;

  Serial.println("");

  if (scanResults == 0)
  {
    Serial.println("No WiFi devices in AP Mode found");
  }
  else
  {
    Serial.print("Found ");
    Serial.print(scanResults);
    Serial.println(" devices ");

    for (int i = 0; i < scanResults; i++)
    {
      // Print SSID and RSSI for each device found
      String SSID = WiFi.SSID(i);
      int32_t RSSI = WiFi.RSSI(i);
      String BSSIDstr = WiFi.BSSIDstr(i);

      if (PRINTSCANRESULTS)
      {
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.print(SSID);
        Serial.print(" [");
        Serial.print(BSSIDstr);
        Serial.print("]");
        Serial.print(" (");
        Serial.print(RSSI);
        Serial.print(")");
        Serial.println("");
      }

      delay(10);

      // Check if the current device starts with `Slave`
      if (SSID.indexOf("Slave") == 0)
      {
        // SSID of interest
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.print(SSID);
        Serial.print(" [");
        Serial.print(BSSIDstr);
        Serial.print("]");
        Serial.print(" (");
        Serial.print(RSSI);
        Serial.print(")");
        Serial.println("");

        // Get BSSID => Mac Address of the Slave
        int mac[6];

        if (6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x%c",  &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]))
        {
          for (int j = 0; j < 6; j++)
          {
            slaves[slaveCount].peer_addr[j] = (uint8_t)mac[j];
          }
        }

        slaves[slaveCount].channel = CHANNEL; // pick a channel
        slaves[slaveCount].encrypt = 0; // no encryption
        slaveCount++;
      }
    }
  }

  if (slaveCount > 0)
  {
    Serial.print(slaveCount); Serial.println(" Slave(s) found, processing..");
  }
  else
  {
    Serial.println("No Slave Found, trying again.");
  }

  // clean up ram
  WiFi.scanDelete();
}

// Check if the slave is already paired with the master.
// If not, pair the slave with master
void manageSlaves()
{
  if (slaveCount > 0)
  {
    for (int i = 0; i < slaveCount; i++)
    {
      const esp_now_peer_info_t *peer = &slaves[i];
      const uint8_t *peer_addr = slaves[i].peer_addr;
      Serial.print("Processing: ");

      for (int j = 0; j < 6; j++)
      {
        Serial.print((uint8_t) slaves[i].peer_addr[j], HEX);
        if (j != 5)
        {
          Serial.print(":");
        }
      }

      Serial.print(" Status: ");

      // check if the peer exists
      bool exists = esp_now_is_peer_exist(peer_addr);
      if (exists)
      {
        // Slave already paired.
        Serial.println("Already Paired");
      }
      else
      {
        // Slave not paired, attempt pair
        esp_err_t addStatus = esp_now_add_peer(peer);
        if (addStatus == ESP_OK)
        {
          // Pair success
          Serial.println("Pair success");
        }
        else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT)
        {
          // How did we get so far!!
          Serial.println("ESPNOW Not Init");
        }
        else if (addStatus == ESP_ERR_ESPNOW_ARG)
        {
          Serial.println("Add Peer - Invalid Argument");
        }
        else if (addStatus == ESP_ERR_ESPNOW_FULL)
        {
          Serial.println("Peer list full");
        }
        else if (addStatus == ESP_ERR_ESPNOW_NO_MEM)
        {
          Serial.println("Out of memory");
        }
        else if (addStatus == ESP_ERR_ESPNOW_EXIST)
        {
          Serial.println("Peer Exists");
        }
        else
        {
          Serial.println("Not sure what happened");
        }
        delay(1000);
      }
    }
  }
  else
  {
    // No slave found to process
    Serial.println("No Slave found to process");
  }
}

// send data
void sendData() {
  for (int i = 0; i < slaveCount; i++) {
    const uint8_t *peer_addr = slaves[i].peer_addr;
    if (i == 0) { // print only for first slave
      Serial.print("Sending: ");
      printStruct();
    }
    esp_err_t result = esp_now_send(peer_addr, (uint8_t *) &sendMode, sizeof(sendMode));
    Serial.print("Send Status: ");
    if (result == ESP_OK) {
      Serial.println("Success");
    } else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
      // How did we get so far!!
      Serial.println("ESPNOW not Init.");
    } else if (result == ESP_ERR_ESPNOW_ARG) {
      Serial.println("Invalid Argument");
    } else if (result == ESP_ERR_ESPNOW_INTERNAL) {
      Serial.println("Internal Error");
    } else if (result == ESP_ERR_ESPNOW_NO_MEM) {
      Serial.println("ESP_ERR_ESPNOW_NO_MEM");
    } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) {
      Serial.println("Peer not found.");
    } else {
      Serial.println("Not sure what happened");
    }
    delay(100);
  }
}

// callback when data is sent from Master to Slave
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
  char macStr[18];
  // sendTime = millis();
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

  Serial.print("Last Packet Sent to: ");
  Serial.println(macStr);
  Serial.print("Last Packet Send Status: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
Receiver:

Code: Select all

//the original creator of this code: https://github.com/Diod-dev/New_Visualizer_Skeleton
// This file handles all incoming messages from ESP-32
// Reads and acts on incoming messages from ESP - 32 NOW, in the format of '< (letter) (3 digit number) >'. For exmaple, <b200>

/*
  << This Device Slave >>
   Sample Serial log:
     AP Config Success. Broadcasting with AP: Slave:3C:71:BF:52:D1:14
     AP MAC: 3C:71:BF:52:D1:15
     ESPNow Init Success
     Last Packet Recv from: 24:0a:c4:0a:6f:08
     Last Packet Recv Data: 1
*/

#include <esp_now.h>
#include <WiFi.h>

#define CHANNEL 1
#define SENDCHANNEL 1
#define WIFI_DEFAULT_CHANNEL 3

esp_now_peer_info_t peer;

void initESPNow();
void configDeviceAP();
void addPeer(uint8_t *peerMacAddress);
void onDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len);

// Variables for solid color
uint8_t solidHue = 0;
uint8_t solidSat = 255;
uint8_t solidVal = 255;

int patternMode = 1;
int patternModeOld;
int ambPattern;
int MVPattern;
int masterBrightness = 5;
double mult = 1.00;


char receivedChar[4];
char oldMode[4];
int Value;
bool newCommand = false;

typedef struct sendModestruct {
  char b[4]; // 10 if you need 9 characters
  char Mode[4]; // 21 if you need 20 characters
  int Value;
  char e[4]; // 5 if you need 4 characters

} sendModestruct;
sendModestruct sendMode;
void onDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  newCommand = true;
  Serial.print("Last Packet Recv from: ");
  Serial.println(macStr);
 // Serial.print("Packet received: ");
 // Serial.println(*incomingData);
  memcpy(&sendMode, incomingData, sizeof(sendMode));
 // Serial.print("Bytes received: ");
 // Serial.println(len);
  //  printStruct();
}



// TODO: use 'categories' instead of letters.
// variables to hold parsed data
//char category[1] = { 0 };
//int instruction = 0;



int audioMultiplier; // temp input variable before recording this input in variable 'mult'

void setup() {
  Serial.begin(115200); // Serial monitor output

  //Set device in AP mode to begin with
  WiFi.mode(WIFI_AP);

  // configure device AP mode
  configDeviceAP();

  // This is the mac address of the Slave in AP Mode
  Serial.print("AP MAC: ");
  Serial.println(WiFi.softAPmacAddress());

  // Init ESPNow with a fallback logic
  initESPNow();

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info.
  /// esp_now_register_send_cb(onDataSent);
  esp_now_register_recv_cb(onDataRecv);

}

void doThingsWithCommands() {
  if (receivedChar[0] == 'a') { // Chooses an ambient pattern and displays it
    Serial.println("a");
    ambPattern = Value;
    patternMode = 3; // Used in normalOperation()
    Serial.println(ambPattern);
  }
  else if (receivedChar[0] == 'b') {  // Sets the brightness when displaying a solid color
    Serial.println("b");
    Serial.println(Value);
    patternMode = 4; // Used in normalOperation() to display a solid color
    solidVal = Value;
  }
  else if (receivedChar[0] == 'f') { // The off button is set, last pattern mode is saved.
    Serial.println("f");

    patternModeOld = patternMode;
    patternMode = 0; // Used in normalOperation() to turn all LEDs off
  }
  else if (receivedChar[0] == 'm') { // Chooses a music-visualizing pattern and displays it
    Serial.println("m");
    Serial.println(Value);
    MVPattern = Value;
    patternMode = 2; // Used in normalOperation() to display a single music-visualizing pattern
    Serial.println(patternMode);
  }
  else if (receivedChar[0] == 'o') {
    Serial.println("o");
    Serial.println(patternModeOld);
    patternMode = patternModeOld; // Used in normalOperation(), returns to last patternMode
  }
  else if (receivedChar[0] == 's') {
    Serial.println("s");
    Serial.println(Value);
    patternMode = 4; // Used in normalOperation() to display a solid color
    solidHue = Value;
  }
  else if (receivedChar[0] == 't') {
    Serial.println("t");
    Serial.println(Value);
    patternMode = 4; // Used in normalOperation() to display a solid color
    solidSat = Value;
  }
  else if (receivedChar[0] == 'x') {
    Serial.println("x");
    patternMode = 1; // Used in normalOperation() to enter mode of changing music-visualization patterns to the music
  }
  else if (receivedChar[0] == 'y') {
    Serial.println("y");
    Serial.println(Value);
    audioMultiplier = Value;
    mult = (double)audioMultiplier / 100;
  }
  else if (receivedChar[0] == 'z') {
    Serial.println("z");
    Serial.println(Value);
    masterBrightness = Value;
  }
  else {}
}

void SelectMode() {
  if (newCommand == true) {
    Serial.println("new Mode beginning");
    oldMode[0] = sendMode.Mode[0];
    receivedChar[0] = sendMode.Mode[0];
    Value = sendMode.Value;

    doThingsWithCommands();
    newCommand = false;
    Serial.println("new Mode ending");
  }
}

void talkToESP() {

  SelectMode(); // after a message is received, act on it
  
}
void loop() {
  talkToESP();
delay(75); // simulate doing something else
}

void printStruct()
{
  Serial.println("printing values");
  // Serial.println(sizeof(sendModestruct));
  Serial.print("char 1: ");
  Serial.println(sendMode.b);
  Serial.print("char 2:");
  Serial.println(sendMode.Mode);
  Serial.print("int: ");
  Serial.println(sendMode.Value);
  Serial.print("char 3:");
  Serial.println(sendMode.e);
  Serial.println("");
  Serial.println("done printing values");
}


void initESPNow()
{
  WiFi.disconnect();
  if (esp_now_init() == ESP_OK) {
    Serial.println("ESPNow Init Success");
  }
  else
  {
    Serial.println("ESPNow Init Failed");
    ESP.restart();
  }
}

// config AP SSID
void configDeviceAP()
{
  String Prefix = "Slave:";
  String Mac = WiFi.macAddress();
  String SSID = Prefix + Mac;
  String Password = "123456789";
  bool result = WiFi.softAP(SSID.c_str(), Password.c_str(), CHANNEL, 0);
  if (!result)
  {
    Serial.println("AP Config failed.");
  }
  else
  {
    Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID));
  }
}

// Add Master as a peer
void addPeer(uint8_t *peerMacAddress)
{
  peer.channel = SENDCHANNEL;
  peer.ifidx = WIFI_IF_AP;
  peer.encrypt = 0;

  memcpy(peer.peer_addr, peerMacAddress, 6);
  esp_err_t addStatus = esp_now_add_peer(&peer);
  if (addStatus == ESP_OK)
  {
    // Pair success
    Serial.println("Pair success");
  }
  else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT)
  {
    // How did we get so far!!
    Serial.println("ESPNOW Not Init");
  }
  else if (addStatus == ESP_ERR_ESPNOW_ARG)
  {
    Serial.println("Add Peer - Invalid Argument");
  }
  else if (addStatus == ESP_ERR_ESPNOW_FULL)
  {
    Serial.println("Peer list full");
  }
  else if (addStatus == ESP_ERR_ESPNOW_NO_MEM)
  {
    Serial.println("Out of memory");
  }
  else if (addStatus == ESP_ERR_ESPNOW_EXIST)
  {
    Serial.println("Peer Exists");
  }
  else
  {
    Serial.println("Not sure what WENT WRONG");
  }
}

Who is online

Users browsing this forum: No registered users and 39 guests