No WiFi when powered via VIN

Hi, this is my first forum post, I have some experience with Arduino and ESP modules but have never encountered this issue before.

My sketch basically creates an AP which I connect to VIA the devices static IP address, the basic HTML page allows me to control WS2812 LED's.

The problem:
When powered via PC USB all is well and the sketch works as it should.
However, when powered via the boards VIN pin at various voltages from my bench power supply, the board powers up but the SSID does not show.

I have also tried to power via USB and powered by a power bank, still, no SSID shows.

Note: this sketch works as it should with a generic NodeMCU when powered via VIN pin.

Any help would be appreciated.

Thanks!

hi @blur23

could you post a schematic of your wiring?
what's the voltage at which you power using VIN?
do you have some sort of

while(!Serial)

in your setup() method?

it would be useful if you posted your full sketch here

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!

Then the code will be stuck in that loop when the board does not have a Serial connection when not connected to the PC no matter how you power it

1 Like

This suddenly makes so much sense to me.
Thank you so much!!

1 Like

that's exactly why I asked :smile:

usually I do this

while(!Serial && millis() < 3000);

it introduces an additional timeout so that in case there's no open Serial port it will snap out of it.

enjoy :slight_smile:

1 Like

thank you for your patience with a very noob question :slight_smile:

we're here to help, and we've all been noobs :slight_smile: