All I'm trying to do is make the numbers come from EEPROM. I have the EEPROM setup right and I can read and write. I tried something like this but it doesn't work:
Declare the destination array then read from the EEPROM in a for loop and put the values in the appropriate array level indexed by the for loop variable
The code in setup() was to initialize your array from EEPROM. You only need to do that once. And since you can read the data from EEPROM you don't really need to keep an array in RAM. Did you want the 'maccmp' function to return 'true' if the the MAC passed in matched one in EEPROM?
bool maccmp(uint8_t *mac) {
{
for (int n = 0; n < LIST_SIZE; n++)
{
boolean match = true; // Assume it's a match until we find a mismatch
for (int i = 0; i < ESPPL_MAC_LEN ; i++)
{
if (mac[i] != EEPROM.read(1 + (ESPPL_MAC_LEN * n) + i))
match = false;
} // end 'i'
if (match) // No mismatches in this entry
return true;
} // end 'n'
return false; // We went through all entries without a match
}
Here is original code I'm attempting to modify, not sure if 'maccmp' function should return 'true' for the MAC passed. Original sketch sniffs up wifi MAC address in the area and turns ON an LED light when one of the listed MAC address is found. BUT in my modified sketch I'm trying to retrieve 4 MAC address from the eeprom (not from a manually coded list of MAC address) and when 1 or more of those is found, to turn ON LED light.
#include "./esppl_functions.h"
void setup() {
delay(500);
pinMode(D3, OUTPUT); // sets the pins to output mode
pinMode(D4, OUTPUT);
Serial.begin(115200);
esppl_init(cb);
}
/* Define you friend's list size here
How many MAC addresses are you tracking?
*/
#define LIST_SIZE 2
/*
This is your friend's MAC address list
Format it by taking the mac address aa:bb:cc:dd:ee:ff
and converting it to 0xaa,0xbb,0xcc,0xdd,0xee,0xff
*/
uint8_t friendmac[LIST_SIZE][ESPPL_MAC_LEN] = {
{0xDC, 0xA9, 0x04, 0x71, 0x22, 0x33},
{0xDC, 0xA9, 0x04, 0x71, 0x1E, 0xE1}
};
/*
This is your friend's name list
put them in the same order as the MAC addresses
*/
String friendname[LIST_SIZE] = {
"MAC 1",
"MAC 2
};
/* You cannot use a time delay here to keep the LED on, so will need to use ratio of
detected packets to overall packets to keep LED on for longer. If you try to use a
delay to keep the light on for long enough to be useful, the watchdog timer kills the
process and it dies */
int cooldown = 1000; /* This variable will be a cooldown timer to keep the LED on for longer, we'll set it to 1000 if we
detect a packet from a device with a MAC address on the list, and then keep the LED on till we get 1000 packets that
are NOT from any device on the list. */
void red() {
digitalWrite(D3, HIGH); /// Make these both SAME eg D1 if you want all MACs to turn on same LED
} // Turn ON the red LED ///
void blue() {
digitalWrite(D4, HIGH); /// Make these both SAME eg D1 if you want all to MACs turn on same LED
} // Turn ON the blue LED ///
void turnoff() {
digitalWrite(D3, LOW), digitalWrite(D4, LOW);
}
bool maccmp(uint8_t *mac1, uint8_t *mac2) {
for (int i = 0; i < ESPPL_MAC_LEN; i++) {
if (mac1[i] != mac2[i]) {
return false;
}
}
return true;
}
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()); ////////////////////////////////////////////////
cooldown = 100; // how many unknow pockets before LED OFF (2800 about 1 min, 28000 is 10 mins)
if (i == 1) { //////////////////////////////////////////////////////////////////////////////////////////
blue();
} // Here we turn ON the blue LED until turnoff() is called
else {
red();
} // Here we turn ON the RED LED until turnoff is called. We can also use if i == 0, or another index
}
else { // this is for if the packet does not match any we are tracking
if (cooldown > 0) {
cooldown--;
} //subtract 1 from the cooldown timer if the value of "cooldown" is more than 1
else { // If the timer is at 0, then run the turnoff function to turn OFF any LED's that are still ON.
turnoff();
}
}
}
}
void loop() { // I didn't write this part but it sure looks fancy.
esppl_sniffing_start();
Serial.print(eeprom7);
while (true) {
for (int i = ESPPL_CHANNEL_MIN; i <= ESPPL_CHANNEL_MAX; i++ ) {
esppl_set_channel(i);
while (esppl_process_frames()) {
//
}
}
}
}