ThatProject - ESP-NOW chat application, MAC address error.

-Rudy-
Posts: 31
Joined: Sun Feb 05, 2017 1:08 am

ThatProject - ESP-NOW chat application, MAC address error.

Postby -Rudy- » Mon May 24, 2021 4:16 pm

This is in relation to the ESP-NOW Chat App video on You Tube and code on Github. There is no way to open an issue in the project on Github so I am posting it here and leaving a comment at the You Tube video.

https://www.youtube.com/watch?v=Kpqz00_IzTc
https://www.youtube.com/watch?v=Kpqz00_IzTc

In the function ScanForPeer() an array is created to hold a the MAC address of the target ESP32. BSSIDstr is decoded and the values are put into char macAddr[6];

Instead of holding the values of 0x24, 0x0A, 0xC4, 0x10, 0xE8, 0x58 (the MAC for my AP) the macAddr[6] instead holds the characters 24:0A:

I added some print statements in the function in order to show this. The modified function is listed below.

Code: Select all

void ScanForPeer() {
  
  if(*peer.peer_addr != NULL){
    return;
  }
  
  int8_t scanResults = WiFi.scanNetworks(); 
  if (scanResults > 0) {
    for (int i = 0; i < scanResults; ++i) {
      String SSID = WiFi.SSID(i);
      String BSSIDstr = WiFi.BSSIDstr(i);
      vTaskDelay(10);
      
      if (SSID.indexOf("Peer") == 0) {
        int mac[6];
        if ( 6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x",  &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] ) ) {
          char macAddr[6];     
          sprintf(macAddr, "%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
          
Serial.print("macAddr: ");
for(int i = 0; i < 6; i++)
{
  Serial.print(macAddr[i]);
}
Serial.println("");

          esp_now_peer_info_t temp;
          memcpy( &temp.peer_addr, macAddr, 6 );
          
Serial.println("- - - - - - - - ");
Serial.print(temp.peer_addr[0],HEX);Serial.print(" ");
Serial.print(temp.peer_addr[1],HEX);Serial.print(" ");
Serial.print(temp.peer_addr[2],HEX);Serial.print(" ");
Serial.print(temp.peer_addr[3],HEX);Serial.print(" ");
Serial.print(temp.peer_addr[4],HEX);Serial.print(" ");
Serial.print(temp.peer_addr[5],HEX);  
Serial.println("");

String str = (char*)temp.peer_addr;
Serial.print(str); Serial.println(" str");
Serial.println("----------------\n");

          if(esp_now_is_peer_exist(temp.peer_addr)){
            Serial.println("Existed Peer!");
            continue;  
          }
      
          memcpy(&peer.peer_addr, macAddr, 6 );
          peer.channel = CHANNEL;
          peer.encrypt = 0;

          const esp_now_peer_info_t *peerNode = &peer;
          if(esp_now_add_peer(peerNode) != ESP_OK){
            Serial.println("Failed to add peer");
            continue;
          }

          updateTopStatus(LV_COLOR_SILVER, "- Connected -");
          checkPeerToSendMsg("Hello There~");
        }
      }
    }
  }

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ThatProject - ESP-NOW chat application, MAC address error.

Postby WiFive » Mon May 24, 2021 5:27 pm

It would be 17 chars long

Who is online

Users browsing this forum: No registered users and 91 guests