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