#include #include #include // REPLACE WITH THE MAC Address of your receiver uint8_t broadcastAddress[] = {0x3C,0x61,0x05,0x30,0x9C,0xD4}; //anzupassen!!! uint8_t newMACAddress[] = {0x3C,0x61,0x05,0x32,0x22,0x4C}; //anzupassen!!! // Variable to store if sending data was successful String success; //Structure example to send data //Must match the receiver structure typedef struct struct_message { uint16_t mstrg1 =10; uint16_t mstrg2 =20; uint16_t mstrg3 =30; uint16_t mstrg4 =40; uint16_t mstrg5 =50; uint16_t mstrg6 =60; //Ersten 5 Bit Geschwindigkeit 6. Weiche, 7.Anforderung Tankinhalt, 8.Anforderung Reifenzustand uint16_t prg1 =70; uint16_t prg2 =80; uint16_t prg3 =90; uint16_t prg4 =190; uint16_t prg5 =110; uint16_t prg6 =120; } struct_message; uint16_t mstrg[4][16]; uint16_t temp[4][16]; uint16_t inmstrg[4][16]; // Create a struct_message called myData struct_message myData; struct_message myData_hier; // Create a struct_message to hold incoming sensor readings struct_message incomingData; // Callback when data is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); if (status ==0){ success = "Delivery Success :)"; } else{ success = "Delivery Fail :("; } } // Callback when data is received /*void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&myData_hier, incomingData, sizeof(incomingData)); Serial.print("Bytes received: "); Serial.println(len); Serial.println(myData_hier.mstrg2); Serial.println(myData_hier.prg2); }*/ void OnDataRecv(const uint8_t * mac, const uint8_t *temp, int len) { memcpy(&inmstrg, temp, sizeof(temp)); Serial.print("Bytes received: "); Serial.println(len); for ( int i = 0; i < 4; ++i ) { // loop through columns of current row for ( int j = 0; j < 16; ++j ) Serial.print (inmstrg[ i ][ j ] ); Serial.println( ) ; // start new line of output } } esp_now_peer_info_t peerInfo; void setup() { // Init Serial Monitor Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); //Chance Mac Adress esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]); Serial.println(WiFi.macAddress()); // Init ESP-NOW 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 memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK){ Serial.println("Failed to add peer"); return; } // Register for a callback function that will be called when data is received esp_now_register_recv_cb(OnDataRecv); } void loop() { // Send message via ESP-NOW for ( int i = 0; i < 16; ++i ) { mstrg[0][i]=2; } // esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); /* esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &mstrg, sizeof(mstrg)); if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } */ delay(20); }