How to disconnect clients from the access point after 2 minutes

borgias511
Posts: 3
Joined: Mon Mar 04, 2019 10:10 am

How to disconnect clients from the access point after 2 minutes

Postby borgias511 » Mon Mar 04, 2019 10:44 am

Hi

(sorry for my english)

I m beginner and I make a game where client connect to myaccess point. I want that after 2 min all client are disconnected and new client can connect

i tried to reboot server with server.stop but it does not work !!!

Code: Select all

#include "SPIFFS.h"
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#include <ESPmDNS.h>
 
// Set SSID nom réseau
const char* ssid= "toto";
// Set password
const char* password = "tata";

// Set Access Point IP
IPAddress   apIP(10, 10, 10, 1);
int max_connection =1; // nb client max

#define PIN 25 // pin connecté
#define NUMPIXELS 20 // Nb de Led
// Variables to store the most recent color sent to us by the client (i.e a web browser)
int red = 255;
int green = 255;
int blue = 255;

// Variables to store the current color of the pixels (we will compare with above to see if we need to update the color)
int currentRed = red;
int currentGreen = green;
int currentBlue = blue;

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 10; // delay for half a second   
 
AsyncWebServer server(80);
 
void setup(){
  Serial.begin(115200);
  pixels.begin(); // This initializes the NeoPixel library.
 
  if(!SPIFFS.begin()){
        Serial.println("Erreur de récupération des fichiers sur SPIFFS");
        return;
  }
  
 // Set Access Point configuration
    WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));   // ss réseau FF FF FF 00
    WiFi.softAP(ssid,password, max_connection);
 
  server.on("/html", HTTP_GET, [](AsyncWebServerRequest *request){ // Page de menu par défaut
    request->send(SPIFFS, "/vib.html", "text/html");
  });


  server.on("/UN", HTTP_GET, [](AsyncWebServerRequest *request){ // page UN
    request->send(SPIFFS, "/vib.html", "text/html");
      currentRed = 100;
      currentGreen = 255;
      currentBlue = 120;
  });
 
 
AdvertiseServices("toto");
  server.begin(); 
}
 
void loop(){
 
    turquoise (0,currentRed,currentGreen,currentBlue,delayval );
    retour(NUMPIXELS,0,0,0);
     }

void AdvertiseServices(const char *MyName)
{
  if (MDNS.begin(MyName))
  {
    Serial.println(F("mDNS responder started"));
    Serial.print(F("I am: "));
    Serial.println(MyName);
 
    // Add service to MDNS-SD
    MDNS.addService("n8i-mlp", "tcp", 23);
  }
  else
  {
    while (1) 
    {
      Serial.println(F("Error setting up MDNS responder"));
      delay(1000);
    }
  }
}
Have you an idea ?
Thanks

Who is online

Users browsing this forum: No registered users and 63 guests