Uint8_t not updating from reading EEPROM?

Hi all newbe here, hate to ask something that is probably simple but if I have this code :

uint8_t mac[25] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t friendmac[LIST_SIZE][ESPPL_MAC_LEN] = {
{mac[1], mac[2], mac[3], mac[4], mac[5], mac[6]},
{mac[7], mac[8], mac[9], mac[10], mac[11], mac[12]},
{mac[13], mac[14], mac[15], mac[16], mac[17], mac[18]},
{mac[19], mac[20], mac[21], mac[22], mac[23], mac[24]}
};

Why can't I update those value if I put this in the setup:
mac[1] = EEPROM.read(1);
mac[2] = EEPROM.read(2);
mac[3] = EEPROM.read(3);
mac[4] = EEPROM.read(4);
mac[5] = EEPROM.read(5);
mac[6] = EEPROM.read(6);

Hello,

I don't understand your question, but I suppose that you expected friendmac to be updated when you set the values of mac. For this, you have to make friendmac a list of pointers to the addresses of the values stored in mac

For example

// friendmac is now a list of pointers to the addresses of the values stored in mac
uint8_t * friendmac[LIST_SIZE][ESPPL_MAC_LEN] = { 
{&mac[1], &mac[2], &mac[3], ...

Then access the values like this

for (uint8_t i = 0; i < LIST_SIZE; i++)
{
	for (uint8_t j = 0; j < ESPPL_MAC_LEN; j++)
	{
		Serial.print( *friendmac[i][j] ); // dereference the pointer to get the value at this address
		Serial.print( " " );
	}
	Serial.println();
}

But ask yourself, do you really need mac ?

Can't you simply do something like this instead:

uint8_t friendmac[LIST_SIZE][ESPPL_MAC_LEN];
...
for (uint8_t i = 0; i < LIST_SIZE; i++)
{
	for (uint8_t j = 0; j < ESPPL_MAC_LEN; j++)
	{
		friendmac[i][j] = EEPROM.read( j + (i * ESPPL_MAC_LEN) );
	}
}

I'm just trying to modify someone else's sketch. Sketch finds/sniffs hard coded wifi MAC addresses and alerts you if they are found.

I'm just trying to change the hard coded MAC addresses to --> EEPROM pulled/read MAC addresses.

He has a small library that he wrote for this to work, I'm starting to think I may need to change stuff in the 2 library pages to be able to pull MAC addresses from the EEPROM.?

This is his code: ESP8266 Friend Detector - Hackster.io

Hey so I tried using what you suggested:

uint8_t * friendmac[LIST_SIZE][ESPPL_MAC_LEN] = {
  {&mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &mac[6]},
  {&mac[7], &mac[8], &mac[9], ...
};

I get his error:

In function 'void cb(esppl_frame_info*)':
error: cannot convert 'uint8_t** {aka unsigned char**}' to 'uint8_t* {aka unsigned char*}' for argument '2' to 'bool maccmp(uint8_t*, uint8_t*)'
     if (maccmp(info->sourceaddr, friendmac[i]) || maccmp(info->receiveraddr, friendmac[i])) {
                                              ^
error: cannot convert 'uint8_t** {aka unsigned char**}' to 'uint8_t* {aka unsigned char*}' for argument '2' to 'bool maccmp(uint8_t*, uint8_t*)'
     if (maccmp(info->sourceaddr, friendmac[i]) || maccmp(info->receiveraddr, friendmac[i])) {
                                                                                          ^
exit status 1
cannot convert 'uint8_t** {aka unsigned char**}' to 'uint8_t* {aka unsigned char*}' for argument '2' to 'bool maccmp(uint8_t*, uint8_t*)'

Here is the: void cb(esppl_frame_info *info)

void cb(esppl_frame_info *info) {
  for (int i = 0; i < LIST_SIZE; i++) {
    if (maccmp(info->sourceaddr, friendmac[i]) || maccmp(info->receiveraddr, friendmac[i])) {
      Serial.printf("\n%s is here! :)", friendname[i].c_str());
      Serial.println("");
      cooldown = 1000;
      if (i == 1) {
        blue();
      }
      else {
        red();
      }
    }
    else {
      if (cooldown > 0) {
        cooldown--;
      }
      else {
        turnoff();
      }
    }
  }
}

Thank you for all your help by the way :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.