Passare indirizzi mac con array

Ciao
Sto' provando a passare l indirizzo mac via vettore, ma non riesco a capire dove sbaglio
sotto le righe incriminate nel setup e nel loop
Cosa e' che non so'?

broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

sotto il messaggio di errore

D:\Arduino sketches\folder esp32\ESP32_oled_rtc_sd_MST_v2\ESP32_oled_rtc_sd_MST_v2.ino: In function 'void setup()':
D:\Arduino sketches\folder esp32\ESP32_oled_rtc_sd_MST_v2\ESP32_oled_rtc_sd_MST_v2.ino:173:22: error: expected primary-expression before ']' token
     broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };
                      ^
D:\Arduino sketches\folder esp32\ESP32_oled_rtc_sd_MST_v2\ESP32_oled_rtc_sd_MST_v2.ino: In function 'void loop()':
D:\Arduino sketches\folder esp32\ESP32_oled_rtc_sd_MST_v2\ESP32_oled_rtc_sd_MST_v2.ino:318:22: error: expected primary-expression before ']' token
     broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };
                      ^
Multiple libraries were found for "SD.h"
  Used: C:\Users\stefano\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\SD
  Not used: C:\Users\stefano\AppData\Local\Arduino15\libraries\SD
  Not used: C:\Users\stefano\Documents\Arduino\libraries\SD
exit status 1

Compilation error: expected primary-expression before ']' token

sotto lo sketch

/**************************************************************************
 This is an example for our Monochrome OLEDs based on SSD1306 drivers

 Pick one up today in the adafruit shop!
 ------> http://www.adafruit.com/category/63_98

 This example is for a 128x64 pixel display using I2C to communicate
 3 pins are required to interface (two I2C and one reset).

 Adafruit invests time and resources providing this open
 source code, please support Adafruit and open-source
 hardware by purchasing products from Adafruit!

 Written by Limor Fried/Ladyada for Adafruit Industries,
 with contributions from the open source community.
 BSD license, check license.txt for more information
 All text above, and the splash screen below must be
 included in any redistribution.
 **************************************************************************/

//mst

#include <SPI.h>               //SD
#include <Wire.h>              //RTC3231 OLED
#include <Adafruit_GFX.h>      //OLED
#include <Adafruit_SSD1306.h>  //OLED
#include "FS.h"                //SD
#include "SD.h"                //SD

//sezione tx ESP32
#include <esp_now.h>  //ESP32
#include <WiFi.h>     //ESP32

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

//uint8_t broadcastAddress1[] = { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 };
//uint8_t broadcastAddress2[] = { 0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };
//uint8_t broadcastAddress3[] = { 0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0 };
//uint8_t broadcastAddress4[] = { 0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0 };
//uint8_t broadcastAddress5[] = { 0x04, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

uint8_t mac_Add[5][6] = {
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 },
  { 0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 },
  { 0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0 },
  { 0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0 },
  { 0x04, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 },
};

uint8_t broadcastAddress[] = { 0, 0, 0, 0, 0, 0 };

//uint8_t broadcastAddress1[] = { mac_Add[0][0], mac_Add[0][1], mac_Add[0][2], mac_Add[0][3], mac_Add[0][4], mac_Add[0][5] };
//uint8_t broadcastAddress2[] = { mac_Add[1][0], mac_Add[1][1], mac_Add[1][2], mac_Add[1][3], mac_Add[1][4], mac_Add[1][5] };
//uint8_t broadcastAddress3[] = { mac_Add[2][0], mac_Add[2][1], mac_Add[2][2], mac_Add[2][3], mac_Add[2][4], mac_Add[3][5] };
//uint8_t broadcastAddress4[] = { mac_Add[3][0], mac_Add[3][1], mac_Add[3][2], mac_Add[3][3], mac_Add[3][4], mac_Add[3][5] };
//uint8_t broadcastAddress5[] = { mac_Add[4][0], mac_Add[4][1], mac_Add[4][2], mac_Add[4][3], mac_Add[4][4], mac_Add[4][5] };


typedef struct test_struct {
  byte id;
} test_struct;

test_struct test_1;

esp_now_peer_info_t peerInfo;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  char macStr[30];
  Serial.print("Packet to: ");
  // Copies the sender mac address to a string
  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(macStr);
  Serial.print(" send status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

//sezione OLED

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES 10  // Number of snowflakes in the animation example

#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] = {
  0b00000000, 0b11000000,
  0b00000001, 0b11000000,
  0b00000001, 0b11000000,
  0b00000011, 0b11100000,
  0b11110011, 0b11100000,
  0b11111110, 0b11111000,
  0b01111110, 0b11111111,
  0b00110011, 0b10011111,
  0b00011111, 0b11111100,
  0b00001101, 0b01110000,
  0b00011011, 0b10100000,
  0b00111111, 0b11100000,
  0b00111111, 0b11110000,
  0b01111100, 0b11110000,
  0b01110000, 0b01110000,
  0b00000000, 0b00110000
};

//orologio RTC DS3231

#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

//sezione SD

byte chipSDSelect;
File datafile;

//sezione delay con millis() timer

unsigned long previousMillis;  // will store last time
long sampling_delay;           //intervallo di campionamento
byte SD_delay;
byte rx_delay;
byte id_sens;
byte num_sensori;

void setup() {

  Serial.begin(115200);  // Start the serial interface

  Wire.begin();  // Start the I2C interface

  //sezione delay con millis() timer

  sampling_delay = 3000;  //millis intervallo delle interrogazioni delle stazioni
  SD_delay = 2;           //ritardo scrittura valori su SD
  rx_delay = 7;           //ritardo ciclo ricezione dati
  previousMillis = 0;

  id_sens = 0;
  num_sensori = 3;

  // sezione tx

  WiFi.mode(WIFI_STA);

  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
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // register peers
  for (id_sens = 0; id_sens < num_sensori - 1; id_sens++) {

    broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    memcpy(peerInfo.peer_addr, broadcastAddress, 6);

    if (esp_now_add_peer(&peerInfo) != ESP_OK) {
      Serial.println("Failed to add peer");
      return;
    }
  }


  //sezione OLED

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.

  display.display();

  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  delay(2000);  // Pause for 2 seconds

  display.clearDisplay();  // Clear the buffer

  display.display();

  delay(2000);

  //sezione RTC

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  //sezione SD

  chipSDSelect = 5;
  pinMode(chipSDSelect, OUTPUT);
  SD.begin(chipSDSelect);
  Serial.println("Initializing SD card...1");

  delay(500);

  if (!SD.begin(chipSDSelect))  // see if the card is present and can be initialized:
  {
    Serial.println("Card failed, or not present");  // don't do anything more
    digitalWrite(5, HIGH);
    while (1)
      ;
  } else {
    Serial.println("SD card initialized...2");
  }
}


void loop() {

  if (millis() - previousMillis >= sampling_delay) {
    previousMillis = millis();  //save the last time

    //sezione RTC

    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");

    if (now.hour() < 10) {
      Serial.print('0');
    }
    Serial.print(now.hour(), DEC);
    Serial.print(':');

    if (now.minute() < 10) {
      Serial.print('0');
    }
    Serial.print(now.minute(), DEC);
    Serial.print(':');

    if (now.second() < 10) {
      Serial.print('0');
    }
    Serial.print(now.second(), DEC);
    Serial.println();

    //sezione OLED
    // Not all the characters will fit on the display. This is normal.
    // Library will draw what it can and the rest will be clipped.
    display.clearDisplay();

    display.setTextSize(2);               // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);  // Draw white text
    //display.setCursor(0, 0);              // Start at top-left corner
    display.cp437(true);  // Use full 256 char 'Code Page 437' font

    display.setCursor(0, 0);  // Start at top-left corner
    display.println(now.hour());
    display.setCursor(30, 0);  // Start at top-left corner
    display.println("ora");

    display.setCursor(0, 20);  // Start at top-left corner
    display.println(now.minute());
    display.setCursor(30, 20);  // Start at top-left corner
    display.println("min");

    display.setCursor(0, 40);  // Start at top-left corner
    display.println(now.second());
    display.setCursor(30, 40);  // Start at top-left corner
    display.println("sec");

    display.display();

    //sezione tx

    // Set values to send
    
    broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    test_1.id = id_sens++;

    esp_err_t result_1 = esp_now_send(broadcastAddress, (uint8_t *)&test_1, sizeof(test_1));

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

    //scrivo su SD

    // Check to see if the file exists:
    if (SD.exists("/test.txt")) {
      Serial.println(".txt exists.");
    } else {
      Serial.println(".txt doesn't exist.");
    }

    datafile = SD.open("/test.txt", FILE_APPEND);  //apre file .txt e appende i dati alla fine del file

    if (datafile)  //if the file is available, write to it:
    {
      datafile.print(now.hour());      //scrive ora
      datafile.print(':');             //separatore
      datafile.print(now.minute());    //scrive ora
      datafile.print(':');             //separatore
      datafile.println(now.second());  //scrive ora

      datafile.close();  //chiude file

      Serial.println("scrivo su file");


      if (id_sens == num_sensori) {
        id_sens = 0;
      }
    }
  }
}  //fine loop

in questo sopra, che è nel loop(), manca qualcosina no!?...più che altro non è "formulata" correttamente...

con questo sotto, che è fuori dal loop() e dal setup(), ti funziona?

uint8_t broadcastAddress[] = { 0, 0, 0, 0, 0, 0 };

non riesco a vederlo, ma e' nel setup()

// register peers
  for (id_sens = 0; id_sens < num_sensori; id_sens++) {

    broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    memcpy(peerInfo.peer_addr, broadcastAddress, 6);

    if (esp_now_add_peer(&peerInfo) != ESP_OK) {
      Serial.println("Failed to add peer");
      return;
    }
  }

non mi da' errore

prova questo...ho commentato righe 173 e 175 aggiungendo riga 176; ho commentato riga 318 ed ho aggiunto riga 320...vedi se ti è più chiaro.

/**************************************************************************
  This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

  This example is for a 128x64 pixel display using I2C to communicate
  3 pins are required to interface (two I2C and one reset).

  Adafruit invests time and resources providing this open
  source code, please support Adafruit and open-source
  hardware by purchasing products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries,
  with contributions from the open source community.
  BSD license, check license.txt for more information
  All text above, and the splash screen below must be
  included in any redistribution.
 **************************************************************************/

//mst

#include <SPI.h>               //SD
#include <Wire.h>              //RTC3231 OLED
#include <Adafruit_GFX.h>      //OLED
#include <Adafruit_SSD1306.h>  //OLED
#include "FS.h"                //SD
#include "SD.h"                //SD

//sezione tx ESP32
#include <esp_now.h>  //ESP32
#include <WiFi.h>     //ESP32

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

//uint8_t broadcastAddress1[] = { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 };
//uint8_t broadcastAddress2[] = { 0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };
//uint8_t broadcastAddress3[] = { 0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0 };
//uint8_t broadcastAddress4[] = { 0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0 };
//uint8_t broadcastAddress5[] = { 0x04, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

uint8_t mac_Add[5][6] = {
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 },
  { 0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 },
  { 0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0 },
  { 0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0 },
  { 0x04, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 },
};

uint8_t broadcastAddress[] = { 0, 0, 0, 0, 0, 0 };

//uint8_t broadcastAddress1[] = { mac_Add[0][0], mac_Add[0][1], mac_Add[0][2], mac_Add[0][3], mac_Add[0][4], mac_Add[0][5] };
//uint8_t broadcastAddress2[] = { mac_Add[1][0], mac_Add[1][1], mac_Add[1][2], mac_Add[1][3], mac_Add[1][4], mac_Add[1][5] };
//uint8_t broadcastAddress3[] = { mac_Add[2][0], mac_Add[2][1], mac_Add[2][2], mac_Add[2][3], mac_Add[2][4], mac_Add[3][5] };
//uint8_t broadcastAddress4[] = { mac_Add[3][0], mac_Add[3][1], mac_Add[3][2], mac_Add[3][3], mac_Add[3][4], mac_Add[3][5] };
//uint8_t broadcastAddress5[] = { mac_Add[4][0], mac_Add[4][1], mac_Add[4][2], mac_Add[4][3], mac_Add[4][4], mac_Add[4][5] };


typedef struct test_struct {
  byte id;
} test_struct;

test_struct test_1;

esp_now_peer_info_t peerInfo;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  char macStr[30];
  Serial.print("Packet to: ");
  // Copies the sender mac address to a string
  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(macStr);
  Serial.print(" send status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

//sezione OLED

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES 10  // Number of snowflakes in the animation example

#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] = {
  0b00000000, 0b11000000,
  0b00000001, 0b11000000,
  0b00000001, 0b11000000,
  0b00000011, 0b11100000,
  0b11110011, 0b11100000,
  0b11111110, 0b11111000,
  0b01111110, 0b11111111,
  0b00110011, 0b10011111,
  0b00011111, 0b11111100,
  0b00001101, 0b01110000,
  0b00011011, 0b10100000,
  0b00111111, 0b11100000,
  0b00111111, 0b11110000,
  0b01111100, 0b11110000,
  0b01110000, 0b01110000,
  0b00000000, 0b00110000
};

//orologio RTC DS3231

#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

//sezione SD

byte chipSDSelect;
File datafile;

//sezione delay con millis() timer

unsigned long previousMillis;  // will store last time
long sampling_delay;           //intervallo di campionamento
byte SD_delay;
byte rx_delay;
byte id_sens;
byte num_sensori;

void setup() {

  Serial.begin(115200);  // Start the serial interface

  Wire.begin();  // Start the I2C interface

  //sezione delay con millis() timer

  sampling_delay = 3000;  //millis intervallo delle interrogazioni delle stazioni
  SD_delay = 2;           //ritardo scrittura valori su SD
  rx_delay = 7;           //ritardo ciclo ricezione dati
  previousMillis = 0;

  id_sens = 0;
  num_sensori = 3;

  // sezione tx

  WiFi.mode(WIFI_STA);

  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
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // register peers
  for (id_sens = 0; id_sens < num_sensori - 1; id_sens++) {

    //broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    //memcpy(peerInfo.peer_addr, broadcastAddress, 6);
    memcpy(peerInfo.peer_addr, mac_Add[id_sens], (sizeof(mac_Add[id_sens]) / sizeof(mac_Add[id_sens][0])));

    if (esp_now_add_peer(&peerInfo) != ESP_OK) {
      Serial.println("Failed to add peer");
      return;
    }
  }


  //sezione OLED

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.

  display.display();

  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  delay(2000);  // Pause for 2 seconds

  display.clearDisplay();  // Clear the buffer

  display.display();

  delay(2000);

  //sezione RTC

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  //sezione SD

  chipSDSelect = 5;
  pinMode(chipSDSelect, OUTPUT);
  SD.begin(chipSDSelect);
  Serial.println("Initializing SD card...1");

  delay(500);

  if (!SD.begin(chipSDSelect))  // see if the card is present and can be initialized:
  {
    Serial.println("Card failed, or not present");  // don't do anything more
    digitalWrite(5, HIGH);
    while (1)
      ;
  } else {
    Serial.println("SD card initialized...2");
  }
}


void loop() {

  if (millis() - previousMillis >= sampling_delay) {
    previousMillis = millis();  //save the last time

    //sezione RTC

    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");

    if (now.hour() < 10) {
      Serial.print('0');
    }
    Serial.print(now.hour(), DEC);
    Serial.print(':');

    if (now.minute() < 10) {
      Serial.print('0');
    }
    Serial.print(now.minute(), DEC);
    Serial.print(':');

    if (now.second() < 10) {
      Serial.print('0');
    }
    Serial.print(now.second(), DEC);
    Serial.println();

    //sezione OLED
    // Not all the characters will fit on the display. This is normal.
    // Library will draw what it can and the rest will be clipped.
    display.clearDisplay();

    display.setTextSize(2);               // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);  // Draw white text
    //display.setCursor(0, 0);              // Start at top-left corner
    display.cp437(true);  // Use full 256 char 'Code Page 437' font

    display.setCursor(0, 0);  // Start at top-left corner
    display.println(now.hour());
    display.setCursor(30, 0);  // Start at top-left corner
    display.println("ora");

    display.setCursor(0, 20);  // Start at top-left corner
    display.println(now.minute());
    display.setCursor(30, 20);  // Start at top-left corner
    display.println("min");

    display.setCursor(0, 40);  // Start at top-left corner
    display.println(now.second());
    display.setCursor(30, 40);  // Start at top-left corner
    display.println("sec");

    display.display();

    //sezione tx

    // Set values to send

    //broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    memcpy(broadcastAddress, mac_Add[id_sens], (sizeof(mac_Add[id_sens]) / sizeof(mac_Add[id_sens][0])));

    test_1.id = id_sens++;

    esp_err_t result_1 = esp_now_send(broadcastAddress, (uint8_t *)&test_1, sizeof(test_1));

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

    //scrivo su SD

    // Check to see if the file exists:
    if (SD.exists("/test.txt")) {
      Serial.println(".txt exists.");
    } else {
      Serial.println(".txt doesn't exist.");
    }

    datafile = SD.open("/test.txt", FILE_APPEND);  //apre file .txt e appende i dati alla fine del file

    if (datafile)  //if the file is available, write to it:
    {
      datafile.print(now.hour());      //scrive ora
      datafile.print(':');             //separatore
      datafile.print(now.minute());    //scrive ora
      datafile.print(':');             //separatore
      datafile.println(now.second());  //scrive ora

      datafile.close();  //chiude file

      Serial.println("scrivo su file");


      if (id_sens == num_sensori) {
        id_sens = 0;
      }
    }
  }
}  //fine loop

ciao

ero in viaggio per tornare al lavoro
con le modifiche suggerite compila senza errori
non conosco bene il C, non mi sembrava malvagio quello scritto
vedo di proseguire con la creazione dello sketch e finire questo progetto ci lavoro da molto, causa ignoranza ovviamente
in questi gg provo a spedire gli id dei moduli e vedo se arrivano

grazie

che compilava senza errori lo sapevo anch'io, l'avevo fatto prima di inviartelo per verificare se c'erano altre cose, la cosa importante è: hai capito cos'ho fatto?...hai capito qual'era il tipo di errore?
in arduino si usa il C++; da come hai scritto quelle 2 righe "sbagliate" mi sa che ti sei confuso con python...nel quale le liste si creano in quel modo.

ciao
grazie per la correzzione
mi devo studiare le istruzioni il C++ non e' il mio quotidiano sono solo un appassionato, che si diverte

In pratica in C/C++ è impossibile quella istruzione perchè non stai copiando un singolo elemento ma chiedi di copiare un array intero (solo con funzioni tipo memcpy è possibile farlo).
La cosa è possibile SOLO in fase di inizializzazione dell'array, infatti questo ti compila:

uint8_t broadcastAddress1[] = { mac_Add[0][0], mac_Add[0][1], mac_Add[0][2], 
                                mac_Add[0][3], mac_Add[0][4], mac_Add[0][5] };

Per risolvere o li fai uno per uno:

    broadcastAddress[0] = mac_Add[id_sens][0];
    broadcastAddress[1] = mac_Add[id_sens][1];
    broadcastAddress[2] = mac_Add[id_sens][2];
    broadcastAddress[3] = mac_Add[id_sens][3];
    broadcastAddress[4] = mac_Add[id_sens][4];
    broadcastAddress[5] = mac_Add[id_sens][5];

oppure ancora meglio con for (in alternativa a memcpy)

   for(byte i=0;i<=5;i++)  broadcastAddress[i] = mac_Add[id_sens][i];

P.S. ovviamente come ti ha corretto il codice @andreaber è meglio perchè fa un passaggio in meno tra i (tanti) vari array che hai creato

ciao
grazie adesso ho compreso
ovviamente ero convinto di poter fare l operazione a prescindere

mi studio la sintassi di memcpy al limite vado di for
questo post me lo devo salvare

ciao
Ho un solo modulo con mac 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0
Rieccomi con uno sviluppo, sotto l output lato trasmettitore:

id_sens 0
test_1.id 0
Sent with success
Packet to: a0:a3:b3:2f:84:c0 send status:	Delivery Success
2024/1/13 (Saturday) 22:37:31
.txt exists.
scrivo su file
id_sens 1
test_1.id 1
Sent with success
Packet to: 24:0a:c4:ae:ae:44 send status:	Delivery Fail
2024/1/13 (Saturday) 22:37:34
.txt exists.
scrivo su file
id_sens 2
test_1.id 2
Sent with success
Packet to: 80:7d:3a:58:b4:3a send status:	Delivery Fail
2024/1/13 (Saturday) 22:37:37
.txt exists.
scrivo su file
id_sens 3
test_1.id 3
Sent with success
Packet to: 24:0a:c4:a0:ae:44 send status:	Delivery Fail
2024/1/13 (Saturday) 22:55:25
.txt exists.
scrivo su file
id_sens 4
test_1.id 4
Error sending the data
2024/1/13 (Saturday) 22:55:28
.txt exists.
scrivo su file

con 0 1 2 3 capisco il

Delivery Fail

ma non

Sent with success

inoltre non comprendo perche' con id_sens 4 ho questo?

id_sens 4
test_1.id 4
Error sending the data

sotto lo sketch

/**************************************************************************
  This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

  This example is for a 128x64 pixel display using I2C to communicate
  3 pins are required to interface (two I2C and one reset).

  Adafruit invests time and resources providing this open
  source code, please support Adafruit and open-source
  hardware by purchasing products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries,
  with contributions from the open source community.
  BSD license, check license.txt for more information
  All text above, and the splash screen below must be
  included in any redistribution.
 **************************************************************************/

//mst

#include <SPI.h>               //SD
#include <Wire.h>              //RTC3231 OLED
#include <Adafruit_GFX.h>      //OLED
#include <Adafruit_SSD1306.h>  //OLED
#include "FS.h"                //SD
#include "SD.h"                //SD

//sezione tx ESP32
#include <esp_now.h>  //ESP32
#include <WiFi.h>     //ESP32

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

//uint8_t broadcastAddress1[] = { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 };
//uint8_t broadcastAddress2[] = { 0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };
//uint8_t broadcastAddress3[] = { 0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0 };
//uint8_t broadcastAddress4[] = { 0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0 };
//uint8_t broadcastAddress5[] = { 0x04, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

uint8_t mac_Add[5][6] = {
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 },
  { 0x24, 0xA0, 0xC4, 0xAE, 0xAE, 0x44 },
  { 0x24, 0x0A, 0xA0, 0xAE, 0xAE, 0x44 },
  { 0x24, 0x0A, 0xC4, 0xA0, 0xAE, 0x44 },
  { 0x24, 0x0A, 0xC4, 0xAE, 0xA0, 0x44 },
};

uint8_t broadcastAddress[] = { 0, 0, 0, 0, 0, 0 };

//uint8_t broadcastAddress1[] = { mac_Add[0][0], mac_Add[0][1], mac_Add[0][2], mac_Add[0][3], mac_Add[0][4], mac_Add[0][5] };
//uint8_t broadcastAddress2[] = { mac_Add[1][0], mac_Add[1][1], mac_Add[1][2], mac_Add[1][3], mac_Add[1][4], mac_Add[1][5] };
//uint8_t broadcastAddress3[] = { mac_Add[2][0], mac_Add[2][1], mac_Add[2][2], mac_Add[2][3], mac_Add[2][4], mac_Add[3][5] };
//uint8_t broadcastAddress4[] = { mac_Add[3][0], mac_Add[3][1], mac_Add[3][2], mac_Add[3][3], mac_Add[3][4], mac_Add[3][5] };
//uint8_t broadcastAddress5[] = { mac_Add[4][0], mac_Add[4][1], mac_Add[4][2], mac_Add[4][3], mac_Add[4][4], mac_Add[4][5] };


typedef struct test_struct {
  byte id;
} test_struct;

test_struct test_1;

esp_now_peer_info_t peerInfo;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  char macStr[30];
  Serial.print("Packet to: ");
  // Copies the sender mac address to a string
  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(macStr);
  Serial.print(" send status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

//OLED

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//RTC DS3231

#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

//SD

byte chipSDSelect;
File datafile;

//sezione delay con millis() timer

unsigned long previousMillis;  // will store last time
long sampling_delay;           //intervallo di campionamento
byte SD_delay;
byte rx_delay;
byte id_sens;
byte num_sensori;

void setup() {

  Serial.begin(115200);  // Start the serial interface

  Wire.begin();  // Start the I2C interface

  //sezione delay con millis() timer

  sampling_delay = 3000;  //millis intervallo delle interrogazioni delle stazioni
  SD_delay = 2;           //ritardo scrittura valori su SD
  rx_delay = 7;           //ritardo ciclo ricezione dati
  previousMillis = 0;

  id_sens = 0;
  num_sensori = 5;

  //TX

  WiFi.mode(WIFI_STA);

  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
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // register peers
  for (id_sens = 0; id_sens < num_sensori - 1; id_sens++) {

    //broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    //memcpy(peerInfo.peer_addr, broadcastAddress, 6);
    memcpy(peerInfo.peer_addr, mac_Add[id_sens], (sizeof(mac_Add[id_sens]) / sizeof(mac_Add[id_sens][0])));  //dal forum arduino

    if (esp_now_add_peer(&peerInfo) != ESP_OK) {
      Serial.println("Failed to add peer");
      return;
    }
  }

  //OLED

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.

  display.display();

  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  delay(2000);  // Pause for 2 seconds

  display.clearDisplay();  // Clear the buffer

  display.display();

  delay(2000);

  //RTC

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  //SD

  chipSDSelect = 5;
  pinMode(chipSDSelect, OUTPUT);
  SD.begin(chipSDSelect);
  Serial.println("Initializing SD card...1");

  delay(500);

  if (!SD.begin(chipSDSelect))  // see if the card is present and can be initialized:
  {
    Serial.println("Card failed, or not present");  // don't do anything more
    digitalWrite(5, HIGH);
    while (1)
      ;
  } else {
    Serial.println("SD card initialized...2");
  }
}

void loop() {

  if (millis() - previousMillis >= sampling_delay) {
    previousMillis = millis();  //save the last time

    //TX
    // Set values to send

    //broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    memcpy(broadcastAddress, mac_Add[id_sens], (sizeof(mac_Add[id_sens]) / sizeof(mac_Add[id_sens][0])));  //dal forum arduino

    test_1.id = id_sens;

    Serial.print("id_sens ");
    Serial.println(id_sens);
     Serial.print("test_1.id ");
    Serial.println(test_1.id);

    esp_err_t result_1 = esp_now_send(broadcastAddress, (uint8_t *)&test_1, sizeof(test_1));

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

    //RTC

    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");

    if (now.hour() < 10) {
      Serial.print('0');
    }
    Serial.print(now.hour(), DEC);
    Serial.print(':');

    if (now.minute() < 10) {
      Serial.print('0');
    }
    Serial.print(now.minute(), DEC);
    Serial.print(':');

    if (now.second() < 10) {
      Serial.print('0');
    }
    Serial.print(now.second(), DEC);
    Serial.println();

    //OLED
    // Not all the characters will fit on the display. This is normal.
    // Library will draw what it can and the rest will be clipped.
    display.clearDisplay();

    display.setTextSize(2);               // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);  // Draw white text
    //display.setCursor(0, 0);              // Start at top-left corner
    display.cp437(true);  // Use full 256 char 'Code Page 437' font

    display.setCursor(0, 0);  // Start at top-left corner
    display.println(now.hour());
    display.setCursor(30, 0);  // Start at top-left corner
    display.println("ora");

    display.setCursor(0, 20);  // Start at top-left corner
    display.println(now.minute());
    display.setCursor(30, 20);  // Start at top-left corner
    display.println("min");

    display.setCursor(0, 40);  // Start at top-left corner
    display.println(now.second());
    display.setCursor(30, 40);  // Start at top-left corner
    display.println("sec");

    display.display();

    //SD

    // Check to see if the file exists:
    if (SD.exists("/test.txt")) {
      Serial.println(".txt exists.");
    } else {
      Serial.println(".txt doesn't exist.");
    }

    datafile = SD.open("/test.txt", FILE_APPEND);  //apre file .txt e appende i dati alla fine del file

    if (datafile)  //if the file is available, write to it:
    {
      datafile.print(now.hour());      //scrive ora
      datafile.print(':');             //separatore
      datafile.print(now.minute());    //scrive ora
      datafile.print(':');             //separatore
      datafile.println(now.second());  //scrive ora
      datafile.close();                //chiude file

      Serial.println("scrivo su file");
    }

    id_sens++;
    if (id_sens == num_sensori) {
      id_sens = 0;
    }
  }
}  //fine loop

ciao ...sei sicuro dei MAC ADDRESS che hai?

ciao
Solo il primo e' collegato gli altri lo saranno
Con:

num_sensori = 5;

id_sens 3
test_1.id 3
Sent with success
Packet to: 24:0a:c4:a0:ae:46 send status:	Delivery Fail
2024/1/14 (Sunday) 12:26:01
.txt exists.
scrivo su file
4



id_sens 4
test_1.id 4
Error sending the data
2024/1/14 (Sunday) 12:26:04
.txt exists.
scrivo su file
5

e poi ricomincia

Con

num_sensori = 6;

id_sens 3
test_1.id 3
Sent with success
Packet to: 24:0a:c4:a0:ae:46 send status:	Delivery Fail
2024/1/14 (Sunday) 12:29:11
.txt exists.
scrivo su file
4



id_sens 4
test_1.id 4
Sent with success
Packet to: 24:0a:c4:ae:a0:47 send status:	Delivery Fail
2024/1/14 (Sunday) 12:29:14
.txt exists.
scrivo su file
5



id_sens 5
test_1.id 5
Error sending the data
2024/1/14 (Sunday) 12:29:17
.txt exists.
scrivo su file
6

rileggendo meglio il tuo precedente messaggio e questo capisco che gli slave non ci sono, forse uno, e quindi ti domandi come fa ad innviare correttamente se non c'è il dispositivo fisico a ricevere...mentre l'ultimo di dice "error sending data".
Se effettivamanente hai un solo slave disponibile ed il suo MAC è il primo nella lista...prova a spostarlo al terzo e poi all'ultimo posto e verifica cosa succede...

ciao
rieccomi con un aggiornamento
fatto quello che viene suggerito
sotto la matrice degli indirizzi

uint8_t mac_Add[5][6] = {
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x41 }, 
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x42 }, 
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x43 },
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x44 }, 
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 }, //scheda collegata
};

avro' 5 sensori con id_sens da 0 a 4

se indico 6 come numero sensori, con id_sens 4 ottengo

19:40:30.613 -> id_sens 4
19:40:30.613 -> test_1.id 4
19:40:30.613 -> Sent with success
19:40:30.613 -> Packet to: a0:a3:b3:2f:84:c0 send status:	Delivery Success
19:40:30.784 -> 2024/1/20 (Saturday) 19:40:08
19:40:30.816 -> .txt exists.
19:40:30.816 -> scrivo su file

se indico 5 come numero sensori, con id_sens 4 ottengo

19:55:21.897 -> id_sens 4
19:55:21.897 -> test_1.id 4
19:55:21.897 -> Error sending the data

con id_sens da 0 a 3 ottengo

19:40:24.599 -> Sent with success
19:40:24.599 -> Packet to: a0:a3:b3:2f:84:43 send status:	Delivery Fail

grazie
stefano

Io non ho capito la domanda :roll_eyes:

Ma se i sensori sono 5, perché dovresti mettere 6?
Forse perché stai sbagliando questo ciclo for?
Ammesso che il codice sia ancora lo stesso, c'è un -1 di troppo

Cotestatnt, quel for mi pare corretto

Stefa24 quel array ha una virgola di troppo al fondo. Ma non credo sia quello il problema.
Posta il pezzo di codice con il for che fa quel test.
Comunque se hai un array di 5 elementi e vai oltre il C/C++ te lo fa fare, da solo un warning in compilazione.

Ok, ma la presenza della virgola cosa cambia?
Quel ciclo for crea solo confusione e infatti @stefa24 dice che per avere una trasmissione con successo sull'unico indirizzo collegato, ovvero l'ultimo, deve mettere la variabile num_sensori == 6 .
Immagino sia questo il senso della sua ultima richiesta? :face_with_diagonal_mouth:

1 Like

Boh, immagino nulla. Se dai nelle quadre il numero elementi, ma il compilatore trova un elemento in più contando i valori di inizializzazione, immagino dia warning. E poi mantenga 5 elementi. Come ho scritto non credo sia quello il problema.

se non ho capito male...gli ESP32 slave NON ci sono, solo uno forse, i MAC sono "inventati"...quello di cui si meraviglia è che, a seconda se invia una richiesta ESP_NOW a 3 o 4 o 5 elementi ha risposte "diverse"...però se non ci sono fisicamente gli ESP non so cosa dire...io ne ho 3 da provare e non 6 come da suo programma..

ciao
si e' questo che non comprendo

il fatto di avere un solo esp collegato non credo cambi la situazione, perche' potrei trovarmi nella realta' con 5 unita' collegate ma qualcuna potrebbe avere le batterie scariche

sotto l output che ottengo adesso con num_sensori = 5 come da sketch sotto, e sulla unita' ricevente ricevo 4 come deve essere
uso ide

Version: 2.2.1
Date: 2023-08-31T14:35:44.802Z
CLI Version: 0.34.0

Copyright © 2024 Arduino SA

potrebbe essere questo il problema, domani provo con ide tradizionale

21:39:59.002 -> 4
21:39:59.002 -> 
21:39:59.002 -> 
21:39:59.002 -> 
21:40:01.769 -> id_sens 4
21:40:01.769 -> test_1.id 4
21:40:01.769 -> Sent with success
21:40:01.769 -> Packet to: a0:a3:b3:2f:84:c0 send status:	Delivery Success
21:40:01.955 -> 2024/1/21 (Sunday) 21:39:38
21:40:02.001 -> .txt exists.
21:40:02.001 -> scrivo su file
21:40:02.001 -> 5
21:40:02.001 -> 
21:40:02.001 -> 
21:40:02.001 -> 
21:40:04.749 -> id_sens 0
21:40:04.749 -> test_1.id 0
21:40:04.749 -> Sent with success
21:40:04.788 -> Packet to: a0:a3:b3:2f:84:41 send status:	Delivery Fail
21:40:04.958 -> 2024/1/21 (Sunday) 21:39:41
21:40:05.005 -> .txt exists.
21:40:05.005 -> scrivo su file

grazie

sotto lo sketch

/**************************************************************************
  This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

  This example is for a 128x64 pixel display using I2C to communicate
  3 pins are required to interface (two I2C and one reset).

  Adafruit invests time and resources providing this open
  source code, please support Adafruit and open-source
  hardware by purchasing products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries,
  with contributions from the open source community.
  BSD license, check license.txt for more information
  All text above, and the splash screen below must be
  included in any redistribution.
 **************************************************************************/

//mst

#include <SPI.h>               //SD
#include <Wire.h>              //RTC3231 OLED
#include <Adafruit_GFX.h>      //OLED
#include <Adafruit_SSD1306.h>  //OLED
#include "FS.h"                //SD
#include "SD.h"                //SD

//sezione tx ESP32
#include <esp_now.h>  //ESP32
#include <WiFi.h>     //ESP32

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

//uint8_t broadcastAddress1[] = { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 };
//uint8_t broadcastAddress2[] = { 0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };
//uint8_t broadcastAddress3[] = { 0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0 };
//uint8_t broadcastAddress4[] = { 0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0 };
//uint8_t broadcastAddress5[] = { 0x04, 0x0A, 0xC4, 0xAE, 0xAE, 0x44 };

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS

uint8_t mac_Add[5][6] = {
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x41 }, 
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x42 }, 
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x43 },
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0x44 }, 
  { 0xA0, 0xA3, 0xB3, 0x2F, 0x84, 0xC0 } //scheda collegata
};

uint8_t broadcastAddress[] = { 0, 0, 0, 0, 0, 0 };

//uint8_t broadcastAddress1[] = { mac_Add[0][0], mac_Add[0][1], mac_Add[0][2], mac_Add[0][3], mac_Add[0][4], mac_Add[0][5] };
//uint8_t broadcastAddress2[] = { mac_Add[1][0], mac_Add[1][1], mac_Add[1][2], mac_Add[1][3], mac_Add[1][4], mac_Add[1][5] };
//uint8_t broadcastAddress3[] = { mac_Add[2][0], mac_Add[2][1], mac_Add[2][2], mac_Add[2][3], mac_Add[2][4], mac_Add[3][5] };
//uint8_t broadcastAddress4[] = { mac_Add[3][0], mac_Add[3][1], mac_Add[3][2], mac_Add[3][3], mac_Add[3][4], mac_Add[3][5] };
//uint8_t broadcastAddress5[] = { mac_Add[4][0], mac_Add[4][1], mac_Add[4][2], mac_Add[4][3], mac_Add[4][4], mac_Add[4][5] };


typedef struct test_struct {
  byte id;
} test_struct;

test_struct test_1;

esp_now_peer_info_t peerInfo;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  char macStr[30];
  Serial.print("Packet to: ");
  // Copies the sender mac address to a string
  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(macStr);
  Serial.print(" send status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

//OLED

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//RTC DS3231

#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

//SD

byte chipSDSelect;
File datafile;

//sezione delay con millis() timer

unsigned long previousMillis;  // will store last time
long sampling_delay;           //intervallo di campionamento
byte SD_delay;
byte rx_delay;
byte id_sens;
byte num_sensori;

void setup() {

  Serial.begin(115200);  // Start the serial interface

  Wire.begin();  // Start the I2C interface

  //sezione delay con millis() timer

  sampling_delay = 3000;  //millis intervallo delle interrogazioni delle stazioni
  SD_delay = 2;           //ritardo scrittura valori su SD
  rx_delay = 7;           //ritardo ciclo ricezione dati
  previousMillis = 0;

  id_sens = 0;
  num_sensori = 5;

  //TX

  WiFi.mode(WIFI_STA);

  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
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // register peers
  for (id_sens = 0; id_sens < num_sensori -1; id_sens++) {

    //broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    //memcpy(peerInfo.peer_addr, broadcastAddress, 6);
    memcpy(peerInfo.peer_addr, mac_Add[id_sens], (sizeof(mac_Add[id_sens]) / sizeof(mac_Add[id_sens][0])));  //dal forum

    if (esp_now_add_peer(&peerInfo) != ESP_OK) {
      Serial.println("Failed to add peer");
      return;
    }
  }

  //OLED

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.

  display.display();

  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  delay(2000);  // Pause for 2 seconds

  display.clearDisplay();  // Clear the buffer

  display.display();

  delay(2000);

  //RTC

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  //SD

  chipSDSelect = 5;
  pinMode(chipSDSelect, OUTPUT);
  SD.begin(chipSDSelect);
  Serial.println("Initializing SD card...1");

  delay(500);

  if (!SD.begin(chipSDSelect))  // see if the card is present and can be initialized:
  {
    Serial.println("Card failed, or not present");  // don't do anything more
    digitalWrite(5, HIGH);
    while (1)
      ;
  } else {
    Serial.println("SD card initialized...2");
  }
}

void loop() {

  if (millis() - previousMillis >= sampling_delay) {
    previousMillis = millis();  //save the last time

    //TX
    // Set values to send

    //broadcastAddress[] = { mac_Add[id_sens][0], mac_Add[id_sens][1], mac_Add[id_sens][2], mac_Add[id_sens][3], mac_Add[id_sens][4], mac_Add[id_sens][5] };

    memcpy(broadcastAddress, mac_Add[id_sens], (sizeof(mac_Add[id_sens]) / sizeof(mac_Add[id_sens][0])));  //dal forum arduino

    test_1.id = id_sens;

    Serial.print("id_sens ");
    Serial.println(id_sens);
    Serial.print("test_1.id ");
    Serial.println(test_1.id);

    esp_err_t result_1 = esp_now_send(broadcastAddress, (uint8_t *)&test_1, sizeof(test_1));

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

    //RTC

    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");

    if (now.hour() < 10) {
      Serial.print('0');
    }
    Serial.print(now.hour(), DEC);
    Serial.print(':');

    if (now.minute() < 10) {
      Serial.print('0');
    }
    Serial.print(now.minute(), DEC);
    Serial.print(':');

    if (now.second() < 10) {
      Serial.print('0');
    }
    Serial.print(now.second(), DEC);
    Serial.println();

    //OLED
    // Not all the characters will fit on the display. This is normal.
    // Library will draw what it can and the rest will be clipped.
    display.clearDisplay();

    display.setTextSize(2);               // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);  // Draw white text
    //display.setCursor(0, 0);              // Start at top-left corner
    display.cp437(true);  // Use full 256 char 'Code Page 437' font

    display.setCursor(0, 0);  // Start at top-left corner
    display.println(now.hour());
    display.setCursor(30, 0);  // Start at top-left corner
    display.println("ora");

    display.setCursor(0, 20);  // Start at top-left corner
    display.println(now.minute());
    display.setCursor(30, 20);  // Start at top-left corner
    display.println("min");

    display.setCursor(0, 40);  // Start at top-left corner
    display.println(now.second());
    display.setCursor(30, 40);  // Start at top-left corner
    display.println("sec");

    display.display();

    //SD

    // Check to see if the file exists:
    if (SD.exists("/test.txt")) {
      Serial.println(".txt exists.");
    } else {
      Serial.println(".txt doesn't exist.");
    }

    datafile = SD.open("/test.txt", FILE_APPEND);  //apre file .txt e appende i dati alla fine del file

    if (datafile)  //if the file is available, write to it:
    {
      datafile.print(now.hour());      //scrive ora
      datafile.print(':');             //separatore
      datafile.print(now.minute());    //scrive ora
      datafile.print(':');             //separatore
      datafile.println(now.second());  //scrive ora
      datafile.close();                //chiude file

      Serial.println("scrivo su file");
    }
    id_sens++;
    Serial.println(id_sens);
    Serial.println();
    Serial.println();
    Serial.println();
  }

  if (id_sens == num_sensori) {
    id_sens = 0;
  }
}  //fine loop