PAX-Counter mit Display und Warn-LED

/* This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details. */
#include <ESP8266WiFi.h>
#include <WiFi_Sniffer.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd1(0x27, 16, 2);

String matrixausgabe_text  = " "; // Ausgabetext als globale Variable

volatile int matrixausgabe_index = 0;// aktuelle Position in Matrix

IPAddress myOwnIP; // ownIP for mDNS 

int PAX = 0 ;
unsigned int Sniff_channel = 1;
//------------ WiFi-Sniffer,  This software is based on the work of Andreas Spiess, https://github.com/SensorsIot/Wi-Fi-Sniffer-as-a-Human-detector//                            and Ray Burnette: https://www.hackster.io/rayburne/esp8266-mini-sniff-f6b93a 
int WiFiPaxCounter(int MinRSSI,  int timeout, int8 mychannel,String myMAC,int mydisplay) {
  int mycount=0;
  int randMAC=0;
  int ChanMin = 1, ChanMax =13; // europe channel 1-13, Japan 1-14
  if (mychannel > 0) {
    ChanMax = mychannel; 
    ChanMin = mychannel;
  };
  if (mychannel < 0) {
    randMAC = mychannel;
  };
  wifi_set_promiscuous_rx_cb(promisc_cb);   // Set up promiscuous callback
  Sniff_channel = ChanMin;
  wifi_set_channel(Sniff_channel);
  wifi_promiscuous_enable(true);
  for (Sniff_channel = ChanMin; Sniff_channel <= ChanMax; Sniff_channel++) {
    wifi_set_channel(Sniff_channel);
    delay(300);            // 300 ms per channel
  }
  wifi_promiscuous_enable(false);
  mycount = SnifferCountDevices(MinRSSI,timeout,myMAC,randMAC,mydisplay); // Anzeige/zaehlen der Clients 
  return mycount;
}



void setup(){ // Einmalige Initialisierung
  Serial.begin(115200);
  WiFi.mode(WIFI_STA); // Pax-counter
  pinMode( 0 , OUTPUT);



  //------------ eigenen WLAN - Accespoint aufbauen 
  WiFi.softAP("MeinOctiWLAN","12345678");
  Serial.print("\nAccessPoint SSID:"); 
  Serial.print("MeinOctiWLAN");
  Serial.println ("  IP:"+ WiFi.softAPIP().toString());
  myOwnIP = WiFi.softAPIP();
  matrixausgabe_text = String("Mein Netz:") + String("MeinOctiWLAN") + String( " IP:") + WiFi.softAPIP().toString();
  matrixausgabe_index=0;

  lcd1.init();  
  lcd1.backlight();   
  start();

}

void loop() { // Kontinuierliche Wiederholung 
  PAX = WiFiPaxCounter(-100,120,0,"all mac",true) ;
  lcd1.clear(); 
  lcd1.setCursor(0,0); 
  lcd1.print(String(String(PAX))+" Client(s) nahe");
  if (( ( PAX ) > ( 10 ) ))
  {
    digitalWrite( 0 , HIGH );
    lcd1.setCursor(0,1);
    lcd1.print("Personenzahl OK!");
    delay( 20000 );
  }
  else
  {
    digitalWrite( 0 , LOW );
    lcd1.setCursor(0,1); 
    lcd1.print("Zu viele Leute!");
    delay( 20000 );
  }
}

void start()
{
  lcd1.clear();   
  lcd1.setCursor(0,0);   
  lcd1.print("   PAXCounter");   
  lcd1.setCursor(0,1);   
  lcd1.print("Naturbez Bildung");
  lcd1.backlight();   
  delay(2000);   
  lcd1.noBacklight();    
  delay(1000);   
  lcd1.backlight();    
  delay(2000);   
  lcd1.noBacklight();
  delay(1000);   
  lcd1.backlight();      
  delay(2000);   
  lcd1.noBacklight();     
  delay(1000);   
  lcd1.backlight();     
  delay(1000);
}