• Система автоматизации с открытым исходным кодом на базе esp8266/esp32 микроконтроллеров и приложения IoT Manager. Наша группа в Telegram

Нужна помощь ESP8266 и программой по поиску устройств.

Зёбра

New member
Не могу понять вообще куда тут вписывать МАК адреса устройств.

/*
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 "./esppl_functions.h"
#include <ESP8266WiFi.h>
#define LIST_SIZE 4
/*
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] = {
{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} //blue
, {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} //green
, {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} //red
, {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA} //yelow
};
/*
This is your friend's name list
put them in the same order as the MAC addresses
*/
String friendname[LIST_SIZE] = {
"Sharp aquos s2" //blue
, "Nexus 5" //green
, "HTC" //red
, "Onda" //yelow
};
// start variables package - Skickar 2018 hardware LED for NodeMCU on mini breadboard //
void setup() {
delay(500);
pinMode(D5, OUTPUT); // sets the pins to output mode
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
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 TimerBlue = 0;
int TimerGreen = 0;
int TimerRed = 0;
int TimerYellow = 0;
void red() {
digitalWrite(D7, HIGH);
} // Turn ON the red LED
void blue() {
digitalWrite(D5, HIGH);
} // Turn ON the blue LED
void green() {
digitalWrite(D6, HIGH);
} // Turn ON the green LED
void yellow(){
digitalWrite(D8, HIGH);
}
void turnoff() {
digitalWrite(D7, LOW), digitalWrite(D5, LOW), digitalWrite(D6, LOW), digitalWrite(D8, LOW);
}
/* end exparimental variable package */
bool maccmp(uint8_t *mac1, uint8_t *mac2) {
for (int i = 0; i < ESPPL_MAC_LEN; i++) {
if (mac1 != mac2) {
return false;
}
}
return true;
}
void check(){
if (TimerBlue > 0) {
TimerBlue--;
}
if (TimerGreen > 0) {
TimerGreen--;
}
if (TimerRed > 0){
TimerRed--;
}
if (TimerYellow > 0){
TimerYellow--;
}
if (TimerBlue <= 0){
digitalWrite(D5, LOW);
}
if (TimerGreen <= 0){
digitalWrite(D6, LOW);
}
if (TimerRed <= 0){
digitalWrite(D7, LOW);
}
if (TimerYellow <= 0){
digitalWrite(D8, LOW);
}
}
void cb(esppl_frame_info *info) {
for (int i = 0; i < LIST_SIZE; i++) {
if (maccmp(info->sourceaddr, friendmac) || maccmp(info->receiveraddr, friendmac)) {
Serial.printf("\n%s is here! :)", friendname.c_str());
if (i == 0) {
TimerBlue = 1000;
TimerGreen--;
TimerRed--;
TimerYellow--;
blue();
check();
} // Here we turn on the blue LED until turnoff() is called
else if(i == 1){
TimerGreen = 1000;
TimerBlue--;
TimerRed--;
TimerYellow--;
green();
check();
}else if(i == 2){
TimerRed = 1000;
TimerBlue--;
TimerGreen--;
TimerYellow--;
red();
check();
}else if (i ==3){
TimerYellow = 1000;
TimerBlue--;
TimerGreen--;
TimerRed--;
yellow();
check();
}
}else{
check();
}
}
}

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()) {
//
}
}
}
}
 

CodeNameHawk

Moderator
Команда форума
Есть много чего в интернете, начните с изучения языка С, читайте любые книги, чем больше тем лучше.
 

Зёбра

New member
Прошил плату, просто подключил питание к ней. Индикации на самой плате ни какой!

Вот вывод прошивки. Все нормально прошилось!
1732369246472.png
 
Сверху Снизу