Moderator: igrr
martinayotte wrote:For the LED, can you draw how you wired it up, because, as you mentioned earlier, GPIO2 with LED is tricky since it is used for BOOT mode : You can not wire it as usual with cathode to GND and anode to GPIO via resistor, it will bring ESP into special boot mode. You need to connect it in reverse way, cathode to GPIO and anode to VCC via resistor. (In such case, you also need to switch all digitalWrite(), LOW means ON and HIGH mean OFF. So, update sketch accordingly.)
With that tip and code, it flashes the LED briefly when powered, then AP starts up fine, but no reaction of LED when device connects or disconnects.
Here's the current circuit and code (I know that the LED needs a resistor, but I'm risking the life of the LED for quick &convenient prototyping) :
/* 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, HIGH);
//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() {
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, HIGH);
prevMillis = millis();
}
}
if (devices == 0) {
alreadyBlinked = 0;
}
else if (alreadyBlinked == 0) {
digitalWrite(16, LOW);
prevMillis = millis();
alreadyBlinked = 1;
}
server.handleClient();
}
but I'm risking the life of the LED for quick &convenient prototyping
Be careful, it is not only the life of the LED that you are risking, but also the GPIO of your ESP.
For the sketch, I don't understand : just before posting the above sketch, it was working for me, LED become ON for 1 second when client connected, the only problem I've faced is that it was not always returning with device_count equals zero after disconnect.
Can you try simple Blink sketch to make sure the LED code is Ok ?