Hi, i wish to use my ESP8266 to send data at two different esp board..
I choose the board writing on Serial monitor "A" or "B"..
I've tried to do that using this sketch
#include <ESP8266WiFi.h>
#include <espnow.h>
// here are the MAC adress
uint8_t broadcastAddressA[]={0x24, 0x6F, 0x28, 0x97, 0x42, 0x80};
uint8_t broadcastAddressB[]={0xfc, 0xf5, 0xc4, 0x65, 0x13, 0x5c};
uint8_t broadcastAddress[6]=;
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
char a[85];
boolean tratt;
} struct_message;
// Create a struct_message called myData
struct_message myDataSend;
// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
Serial.print("Last Packet Send Status: ");
if (sendStatus == 0){
Serial.println("Delivery success");
}
else{
Serial.println("Delivery fail");
}
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
return;
}
//i've setted to COMBO couse i need to use it also for datarecive
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
}
void loop() {
Serial.println("INSERT LETTER");
int incomingByte=0;
if (Serial.available() > 0) {
incomingByte = Serial.read(); // read the incoming byte:
Serial.println("INCOMMING BYTE= ");
Serial.println(incomingByte);
if (incomingByte == 65){ //in ASCII 65 = A maiuscolo
memcpy(broadcastAddressA, broadcastAddress, sizeof broadcastAddressA);
richiestatrattamento();
}
if (incomingByte == 66){ //in ASCII 66 = B maiuscolo
memcpy(broadcastAddressB, broadcastAddress, sizeof broadcastAddressB);
richiestatrattamento();
}
//Serial.println((broadcastAddress, (uint8_t *));
}
delay(10000);
}
void richiestatrattamento() {
// Register peer
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
esp_now_register_send_cb(OnDataSent);
myDataSend.tratt= true;
// Send message via ESP-NOW
esp_now_send(broadcastAddress, (uint8_t *) &myDataSend, sizeof(myDataSend));
delay(1000);
}
I have two problems.. first this code
memcpy(broadcastAddressA, broadcastAddress, sizeof broadcastAddressA);
for copy MAC adress doesent work ![]()
How can i copy the right adress in to the variable?
And second i don't know why after reading the letter it gives me and print the right result
it gives me another value read that i didn't send..
19:29:42.435 -> INSERT LETTER
19:29:42.435 -> INCOMMING BYTE=
19:29:42.473 -> 65
19:29:52.424 -> INSERT LETTER
19:29:52.424 -> INCOMMING BYTE=
19:29:52.462 -> 10
19:30:02.439 -> INSERT LETTER
19:30:12.467 -> INSERT LETTER
Why?? I've checked on ascii table and it's a wired character...
Thank you very much