Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By derek bernsen
#30583 I mean to say, with the newest code and my prior code, the AP server does not start up, also the LED stays lit at all times.

Here is the current code on the ESP-01 that includes your code:

Code: Select all/* 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 == 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();
}
 

   

 



I apologize for being so ignorant about arduino programming, and thank you for your time helping so far.
I have read somewhere that some LEDs confuse the ESP-01, perhaps that may have something to do with it.
I hope we can get this project working!
User avatar
By martinayotte
#30599 Some good news and some bad ... :(

First, it seems that wifi_softap_get_station_num() doesn't like to be called too often, so I moved it inside the 1 second If. Second, it seems that wifi_softap_get_station_num() is not coherent with real number of connections, after disconnect, it was still at 1, so I've decided to use wifi_softap_get_station_info() instead and counting the number of client myself. It is a bit better, but it still buggy too. But maybe you can try to see if it is working for you.

Code: Select allvoid loop() {
  if ((millis() - prevMillis) > 1000) {
    prevMillis = millis();
    devices = 0;
    struct station_info *stat_info = wifi_softap_get_station_info();
    while (stat_info != NULL) {
      stat_info = STAILQ_NEXT(stat_info, next);
      devices++;
    }
    if (alreadyBlinked > 0) {
      digitalWrite(16, LOW);
      prevMillis = millis();
    }
  }
  if (devices == 0) {
    alreadyBlinked = 0;
  }
  else if (alreadyBlinked == 0) {           
    digitalWrite(16, HIGH);
    prevMillis = millis();
    alreadyBlinked = 1;
  }
  server.handleClient();
}