Go Down

Topic: How to store a retrieved connected client MAC address into EEPROM? (Read 466 times) previous topic - next topic

myele

Hi all I have this sketch below which reads connected wifi users MAC addresses, I would like to save these MAC address in to esp8266 EEPROM memory.  How would I do that?

Code: [Select]
.....
....
....

void loop() {
  delay(5000);
  client_status();
  delay(4000);
}

void client_status() {

  unsigned char number_client;
  struct station_info *stat_info;
 
//  struct ip_addr *IPaddress;
  struct ip4_addr *IPaddress;
  IPAddress address;
  int i=1;
 
  number_client= wifi_softap_get_station_num();
  stat_info = wifi_softap_get_station_info();
 
  Serial.print(" Total Connected Clients are = ");
  Serial.println(number_client);
 
    while (stat_info != NULL) {
   
      IPaddress = &stat_info->ip;
      address = IPaddress->addr;
     
      Serial.print(stat_info->bssid[0],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[1],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[2],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[3],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[4],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[5],HEX);Serial.print(" ");
     
      stat_info = STAILQ_NEXT(stat_info, next);
      i++;
      Serial.println();
    }
   
  delay(500);
}

UKHeliBob

If the ESP8266 EEPROM library supports the EEPROM.put() function you can use that and retrieve it again using EEPROM.get() but where in your program is the MAC address ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

myele

Sorry Im a newbee, just learning slowly.  Yes esp8266 supports         
EEPROM.write(0,something);
EEPROM.commit();
and
EEPROM.read(0);


this is the mac address:

Code: [Select]
      Serial.print(stat_info->bssid[0],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[1],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[2],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[3],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[4],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[5],HEX);Serial.print(" ");


0 through 6 is the mac address, mac addresses have 6 sets of 2 letter or number e.g: 01 AB 22 AC 33 81

Code: [Select]
(stat_info->bssid[0],HEX)(stat_info->bssid[1],HEX)(stat_info->bssid[2],HEX)(stat_info->bssid[3],HEX)(stat_info->bssid[4],HEX)(stat_info->bssid[5],HEX)

So my goal is to save the move to EEPROM

UKHeliBob

Quote
EEPROM.write(0,something);
EEPROM.commit();
and
EEPROM.read(0);
Note that I actually suggested using the put() and get() functions not write() and read() as put() and get() allow you to save and read data of any type. 

What data type is the bssid array ?

If you had posted a complete sketch then I would not need to ask
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

myele

esp8266 does have put() get(), its my understanding the it only uses write() read().

Data is a simple MAC address which is a 6 sets of HEX

I needed up trying this and it works:

Code: [Select]
      EEPROM.write(11, stat_info->bssid[0]);
      EEPROM.write(12, stat_info->bssid[1]);
      EEPROM.write(13, stat_info->bssid[2]);
      EEPROM.write(14, stat_info->bssid[3]);
      EEPROM.write(15, stat_info->bssid[4]);
      EEPROM.write(16, stat_info->bssid[5]);
      EEPROM.commit();

myele

Now my issue is that I can only save one MAC/BSSID, it just keeps rewriting over those EEPROM memory spots. 

I would like to check if the new MAC address is different and if so to save the new one to the 2nd set of EEPROM memory spots

so first MAC address SAVE to:

Code: [Select]

      EEPROM.write(11, stat_info->bssid[0]);
      EEPROM.write(12, stat_info->bssid[1]);
      EEPROM.write(13, stat_info->bssid[2]);
      EEPROM.write(14, stat_info->bssid[3]);
      EEPROM.write(15, stat_info->bssid[4]);
      EEPROM.write(16, stat_info->bssid[5]);
      EEPROM.commit();


2nd MAC address SAVE TO:

Code: [Select]

      EEPROM.write(21, stat_info->bssid[0]);
      EEPROM.write(22, stat_info->bssid[1]);
      EEPROM.write(23, stat_info->bssid[2]);
      EEPROM.write(24, stat_info->bssid[3]);
      EEPROM.write(25, stat_info->bssid[4]);
      EEPROM.write(26, stat_info->bssid[5]);
      EEPROM.commit();


PS here is the full code of the sketch that looks up the clients connected to esp8266 and reports back their MAC address which I'm trying to modify to save MAC/BSSID addresses to EEPROM

Code: [Select]
/*
 * Getting MAC and IP Address of Connected devices to ESP8266
 * with Soft AP Mode
 */
 
#include <ESP8266WiFi.h>
 
extern "C" {
  #include<user_interface.h>
}
 
/* configuration  wifi */
const char *ssid = "SSID";
const char *pass = "password";
 
void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
 
  WiFi.softAP(ssid,pass);
 
  IPAddress myIP = WiFi.softAPIP();
 
  Serial.print("AP IP address: ");
  Serial.println(myIP);
}
 
void loop() {
  delay(5000);
  client_status();
  delay(4000);
}
 
void client_status() {
 
  unsigned char number_client;
  struct station_info *stat_info;
 
  struct ip_addr *IPaddress;
  IPAddress address;
  int i=1;
 
  number_client= wifi_softap_get_station_num();
  stat_info = wifi_softap_get_station_info();
 
  Serial.print(" Total Connected Clients are = ");
  Serial.println(number_client);
 
    while (stat_info != NULL) {
   
      IPaddress = &stat_info->ip;
      address = IPaddress->addr;
     
      Serial.print("client= ");
     
      Serial.print(i);
      Serial.print(" IP adress is = ");
      Serial.print((address));
      Serial.print(" with MAC adress is = ");
     
      Serial.print(stat_info->bssid[0],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[1],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[2],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[3],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[4],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[5],HEX);Serial.print(" ");
     
      stat_info = STAILQ_NEXT(stat_info, next);
      i++;
      Serial.println();
    }
   
  delay(500);
}

KASSIMSAMJI


before writing to eeprom, you should read that particular address

see if it matches the data you want to store in
Code: [Select]

if ( current_data != EEPROM.read(address_) ) {
EEPROM.write(address_ , current_data );

}

Electrical Engineer

myele

before writing to eeprom, you should read that particular address

see if it matches the data you want to store in
Code: [Select]

if ( current_data != EEPROM.read(address_) ) {
EEPROM.write(address_ , current_data );

}


Thank you for this, I added to my sketch.

pert

esp8266 does have put() get(), its my understanding the it only uses write() read().
What does that mean? Just to be sure you know, the ESP8266 library does have put() and get().

before writing to eeprom, you should read that particular address

see if it matches the data you want to store in
Although this is very good advice for EEPROM.write() on the AVR, on the ESP8266 it's not actually needed, because the library does that for you:
https://github.com/esp8266/Arduino/blob/2.6.2/libraries/EEPROM/EEPROM.cpp#L118-L124


pert

Now my issue is that I can only save one MAC/BSSID, it just keeps rewriting over those EEPROM memory spots. 

I would like to check if the new MAC address is different and if so to save the new one to the 2nd set of EEPROM memory spots
@myele has started a new topic for discussion of this subject:
https://forum.arduino.cc/index.php?topic=653656

To avoid duplicate efforts, please confine any further discussion of that subject to the other thread.

Go Up