Hi, thanks for your reply.
I do have while(!serial) in my setup:
void setup() {
Serial.begin(115200);
while (! Serial);
Serial.println("Started");
setupWifi();
addLightPattern(patternOff, "Off");
addLightPattern(patternRGB, "RGB");
addLightPattern(patternSnake, "Snake");
addLightPattern(patternJuggle, "Juggle");
addLightPattern(patternBpm, "BPM");
addLightPattern(patternRainbow, "Rainbow");
addLightPattern(patternSpectrum, "spectrum");
setupLed();
}
Here is the setUpWifi function:
void setupWifi()
{
SPIFFS.begin();
setupLed();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, netMsk);
String tmpId = name + getUniqueId();
myHostname = (char*)malloc(tmpId.length() + 1);
tmpId.toCharArray(myHostname, tmpId.length() + 1);
WiFi.softAP(myHostname, softAP_password);
delay(500); // Without delay I've seen the IP address blank
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());
Serial.print("Wifi name: ");
Serial.println(myHostname);
Serial.print("Hostname: ");
Serial.print(myHostname);
Serial.println(".local");
/* Setup the DNS server redirecting all the domains to the apIP */
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start(DNS_PORT, "*", apIP);
/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
server.on("/", handleRoot);
server.on("/wifi", handleWifi);
server.on("/css", handleCSS);
server.on("/wifisave", handleWifiSave);
server.on("/generate_204", handleRoot); //Android captive portal. Maybe not needed. Might be handled by notFound handler.
server.on("/fwlink", handleRoot); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
server.onNotFound ( handleNotFound );
server.begin(); // Web server start
Serial.println("HTTP server started");
loadCredentials(); // Load WLAN credentials from network
connect = strlen(ssid) > 0; // Request WLAN connect if there is a SSID
//Websocket setup
//Serial.setDebugOutput(true);
webSocket.begin();
webSocket.onEvent(webSocketEvent);
}
my void loop() also has a function called 'loopWifi()' I am not sure if that is causing any issues:
void loopWifi()
{
webSocket.loop();
if (connect) {
Serial.println ( "Connect requested" );
connect = false;
connectWifi();
lastConnectTry = millis();
}
{
int s = WiFi.status();
if (s == 0 && millis() > (lastConnectTry + 60000) ) {
// connect = true;
}
if (status != s) { // WLAN status change
Serial.print ( "Status: " );
Serial.println ( s );
status = s;
if (s == WL_CONNECTED) {
Serial.println ( "" );
Serial.print ( "Connected to " );
Serial.println ( ssid );
Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() );
// Setup MDNS responder
if (!MDNS.begin(myHostname)) {
Serial.println("Error setting up MDNS responder!");
} else {
Serial.println("mDNS responder started");
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
MDNS.addService("ws", "tcp", 81);
}
} else if (s == WL_NO_SSID_AVAIL) {
WiFi.disconnect();
}
}
}
//DNS
dnsServer.processNextRequest();
//HTTP
server.handleClient();
}
for now, my wiring diagram is simply voltage and ground to the VIN and GND pins. I've tried 7v and 12v to VIN. the LEDs are currently not connected while I try solve this issue.
Thanks for your help!