Hello all,
i would like o make a mac adress detector with neopixels(ws2812b etc)
i tried to combine two different codes but i failed, can anyone help me?
My goal is when i came to home, half of the neopixel strip will be on or animate, and when my wife came other half will do same or different animation.
im using nodemcu board for this.
my code is:
/*
Friend Detector by Ricardo Oliveira, forked by Skickar 9/30/2018
A Node MCU microcontroller + mini bread board + 4 pin RGB LED to detect when devices belonging to a target are nearby.
The function of this code is to read nearby Wi-Fi traffic in the form of packets. These packets are compared
to a list of MAC addresses we wish to track, and if the MAC address of a packet matches one on the list, we turn
on a colored LED that is linked to the user owning the device. For example, when my roommate comes home, the
transmissions from his phone will be detected and cause the blue LED to turn on until his phone is no longer detected.
It can detect more than one phone at a time, meaning if my phone (red) and my roommate's phone (blue) are both home,
the LED will show purple. */
#include "Adafruit_NeoPixel.h"
#include "./esppl_functions.h"
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN D6
#define NUMPIXELS 16
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
/* 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] = {
{0x12, 0x34, 0x56, 0x78, 0x90, 0x12}
,{0x98, 0x76, 0x54, 0x32, 0x10, 0x98}
};
/*
* This is your friend's name list
* put them in the same order as the MAC addresses
*/
String friendname[LIST_SIZE] = {
"Target 1"
,"Target 2"
};
// start variables package - Skickar 2018 hardware LED for NodeMCU on mini breadboard //
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
Serial.begin(115200);
esppl_init(cb);
}
/* 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 = 0; /* 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. */
/* end exparimental variable package */
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 = 1000; // here we set it to 1000 if we detect a packet that matches our list
if (i == 1){
{
for(int i=0;i<8;i++){ //The first half of the strip
pixels.setPixelColor(i, pixels.Color(255,0,0)); //Set the LEDs red (Assume RGB and not GRB)
}
}
}
else {
for(int k=8;k<16;k++){ //The second half of the strip
pixels.setPixelColor(k, pixels.Color(0,0,255)); //Set the LEDs blue (Assume RGB and not GRB)
}
}
}
else { // this is for if the packet does not match any we are tracking
if (cooldown > 0) {
cooldown--; } //subtract one from the cooldown timer if the value of "cooldown" is more than one
else { // If the timer is at zero, then run the turnoff function to turn off any LED's that are on.
pixels.clear(); } } } }
void loop() { // I didn't write this part but it sure looks fancy.
esppl_sniffing_start();
while (true) {
for (int i = ESPPL_CHANNEL_MIN; i <= ESPPL_CHANNEL_MAX; i++ ) {
esppl_set_channel(i);
while (esppl_process_frames()) {
//
}
}
}
pixels.show();
}