ESP-NOW from Another Tab

chuck808
Posts: 7
Joined: Sun Jan 31, 2021 12:57 pm

ESP-NOW from Another Tab

Postby chuck808 » Thu Mar 11, 2021 4:37 pm

Hello,

Using:-
ESP-WROOM-32 Dev Kit
Arduino IDE
FastLED Library
RGB LED's

I am trying to send RGB LED data from a master to a [dumb] slave node, which seems to work Ok as long as the sketch is contained within the main.ino file. However, I am using multiple tabs for the proper sketch to control the LED's, sequencing, constants and so on. If I try to pass the values to the main.ino file it loses some of the data to be sent, so I am attempting to include the ESP-NOW functions in the LightShow.cpp tab.

In LightShow.cpp I created a typedef struct -

Code: Select all

//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
    int a;
    int b;
    int c;
    int d;
    bool e;
} struct_message;

// Create a struct_message called ledsOut to hold LED data to send
struct_message ledsOut;
Then pass the LED data to the struct -

Code: Select all

switch (step) {       
        case 1:
          // set team Red LEDs
          for(int i=0;i<team_size;i++) {
            leds[i+position*team_size] = CRGB::Red;
            ledsOut.a = (leds[i+position*team_size] = CRGB::Red);
            serial_print_val("This is the value sent to ESP-NOW", ledsOut.a);
          }
          break;
When I run the sketch, I can see that data is sent to the struct using serial_print_val()

However, if I then add the esp-now init to void setup() or esp_err_t result = esp_now_send() in the main.ino I get errors. This is confusing me as I thought that Arduino ran through the code in order and and anything declared globally was accessible by all the tabs.

Obviously I screwed up somewhere, could anyone point me in the right direction please.

Regards

Who is online

Users browsing this forum: No registered users and 186 guests