Moderator: igrr
Here's what I tried last night, it failed to work, all it did was keep the LED on at all times and keep AP mode off.
/* Create a WiFi access point */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
extern "C" {
#include "user_interface.h"
}
#define WIFI_MODE_AP
/* Set these to your desired credentials. */
const char *ssid = "Proximity Trigger 1";
const char *password = "thereisnospoon";
//Reference station counter as "devices"
unsigned char devices;
// boolean ledState = false;
int alreadyBlinked = 0;
unsigned int prevMillis = 0;
ESP8266WebServer server(80);
void handleRoot() {
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
//Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.begin();
}
void loop() {
devices = wifi_softap_get_station_num();
if (devices >= 1) {
if(alreadyBlinked == 0)
{
digitalWrite(2, HIGH);
if ((millis() - prevMillis) > 1000) { // 1000 millis = 1 second
prevMillis = millis();
digitalWrite(2, LOW);
alreadyBlinked = 1;
}
}
else {
if (alreadyBlinked == 0)
{
digitalWrite(2, HIGH);
if ((millis() - prevMillis) > 1000) { // 1000 millis = 1 second
prevMillis = millis();
digitalWrite(2, LOW);
alreadyBlinked = 1;
}
}
server.handleClient();
}
}
}
derek bernsen wrote:keep AP mode off.
What do you mean by that ? Do you mean the AP server not running ? it is simply because you didn't place the handleClient() at the right place, it should not be inside you IFs, it should be called on every loop().
And, again, all the IF logic is contradicting.
Let's revamp your example : as soon one device connect, LED is turn ON, and will be turned OFF after the delay. LED won't turn ON again until this current client is disconnecting and a new one is connecting only after the disconnect. Then, the code should look like :
void loop() {
devices = wifi_softap_get_station_num();
if (devices == 0) {
alreadyBlinked = 0;
}
else if (alreadyBlinked == 0) {
digitalWrite(2, HIGH);
prevMillis = millis();
alreadyBlinked = 1;
}
if (alreadyBlinked > 0 && (millis() - prevMillis) > 1000) {
digitalWrite(2, LOW);
}
server.handleClient();
}
Again thanks for soooo much support, we might have to call you Mr. ESP from now on.
Richard.
https://epartsconnect.com
Live realtime stock market prediction website. https://www.stocksignalslive.com my latest creation. Uses AI and machine learning.
New site featuring ESP8266 and ESP32 projects. tutorials, and news.
http://EverythingESP.com
ESP8266.com Founder and Administrator
The Mind Factory (get more from your 3D printer)
Home of the ESP8266, ESP8285, and ESP32 microcontrollers....