salve a tutti,
sto cercando di caricare un array di un indirizzo MAC prendendo i singoli byte da un file di testo salvato su SD
sto usando arduino con M5STACK (esp32) ed espnow
con questo codice
#include <M5Stack.h>
#include <esp_now.h>
#include <WiFi.h>
esp_now_peer_info_t slave;
//uint8_t remoteMac[] = {0x50, 0x02, 0x91, 0xA0, 0x63, 0xFD};
uint8_t remoteMac[6];// PROVA MAC ADDRESS DA SD
int arrayC = 0;
const uint8_t maxDataFrameSize = 200;
// must match the controller struct
struct __attribute__((packed)) DataStruct {
int X;
int Y;
int Z;
};
DataStruct myData;
const esp_now_peer_info_t *peer = &slave;
uint8_t dataToSend[maxDataFrameSize];
unsigned long lastSentMillis;
unsigned long sendIntervalMillis = 10;
unsigned long sentMicros;
unsigned long ackMicros;
void setup() {
M5.begin();
Serial.begin(115200);
M5.update();
Serial.print("\r\n\r\n");
WiFi.mode(WIFI_STA);
Serial.println( WiFi.softAPmacAddress() );
readMAC();
WiFi.disconnect();
if (esp_now_init() == ESP_OK)
{
Serial.println("ESP NOW INIT!");
}
else
{
Serial.println("ESP NOW INIT FAILED....");
}
memcpy( &slave.peer_addr, &remoteMac, 6 );
slave.channel = 1; // canale
slave.encrypt = 0;
if ( esp_now_add_peer(peer) == ESP_OK)
{
Serial.println("Added Peer!");
Serial.println();
}
esp_now_register_send_cb(OnDataSent);
}
void readMAC() {
File fh = SD.open("/MAC.txt");
char netBuffer[15];
if (!fh)
{
Serial.println("SD open fail");
return;
}
int chPos = 0;
while (fh.available())
{
char ch = fh.read();
if (ch == '\r') {
chPos = 0;
// Serial.print("mac ");
sscanf(netBuffer, "%2x:%2x:%2x:%2x:%2x:%2x", &remoteMac[0], &remoteMac[1], &remoteMac[2], &remoteMac[3], &remoteMac[4], &remoteMac[5]);
}
else if (ch == '\n') {
// do nothing
}
else if (chPos < 14) {
netBuffer[chPos] = ch;
chPos++;
netBuffer[chPos] = 0;
}
}
fh.close();
int x;
Serial.print("\r\nmac ");
for (x = 0; x < 6; x++) {
Serial.print(remoteMac[x], HEX);
if (x < 5) Serial.print(":");
}
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
}
con un file salvato su sd dal nome MAC.txt che contiene una sola riga come la seguente:
50:02:91:A0:63:FD
nel monitor seriale ho un output interessante ma imperfetto :
mac 50:2:91:A0:63:0
e master e slave di espnow non si collegano....
se inverto queste righe master e slave si collegano ma non sto leggendo il MAC address da sd..
uint8_t remoteMac[] = {0x50, 0x02, 0x91, 0xA0, 0x63, 0xFD};
//uint8_t remoteMac[6];// PROVA MAC ADDRESS DA SD
cosa sto sbagliando??