Issues with Arduino MKR WiFi 1010

Hi all. I am currently working on a project to control an RGB LED strip with an arduino MKR WiFi 1010. I am connecting to my wifi network, using WIFININA and the WiFi.begin(ssid, password) function, which works perfectly fine, but only when I open my serial monitor. The arduino is connected via the micro usb plug. However, when I plug the chip into a usb adapter, the it won't connect to the wifi network. This seems strange to me and doesn't make sense why the program only starts when the serial monitor is opened. Any suggestions on how to get the chip to start the program without having to open the serial monitor? Thanks in advance :slight_smile:

Here's my code:

#include <SPI.h>
#include <WiFiNINA.h>
#include <FastLED.h>
#include <aREST.h>
#include <WiFiUdp.h>

aREST rest = aREST();

#define DATA_PIN 5
#define NUM_LEDS 36

char ssid[] = "Seip";        
char pass[] = "connect.me";

int status = WL_IDLE_STATUS;

WiFiServer server(80);
WiFiClient client;
WiFiUDP udp;
CRGB leds[NUM_LEDS];

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }
  
  // Function to be exposed
  rest.function("rgb", setPixelColor);
  rest.function("beginWifi", beginWifiServer);
  rest.function("time", getWifiTime);

  //Opposite of beginAP is WiFi.begin
  status = WiFi.begin(ssid, pass);
  
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();

  udp.begin(2390);

  FastLED.addLeds<WS2812B, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
  String clientRequest = "";
  WiFiClient client = server.available();   // listen for incoming clients

  //getIPTime();
 
  while (client.connected()) {
    rest.handle(client);
  }
  client.stop();
}

int beginWifiServer(String command) {
  WiFi.end();
  WiFi.begin("Seip", "connect.me");
  server.begin();
  printWifiStatus();
  return 1;
}

int getWifiTime(String command) {
  return WiFi.getTime();
}

//http://192.168.4.1/rgb?param=1,2,3
int setPixelColor(String rgb) {
  int colors[3] = {255, 255, 0};

  int beginningIndex = 0;
  int colorIndex = 0;
  while(rgb.indexOf(",", beginningIndex) != -1){
    int index = rgb.indexOf(",", beginningIndex);
    colors[colorIndex] = rgb.substring(beginningIndex, index).toInt();
    beginningIndex = index + 1;
    colorIndex++;
  }
  colors[colorIndex] = rgb.substring(beginningIndex, rgb.length()).toInt();

  for(int i = 0; i < 24; i++){
    leds[i] = CRGB(colors[1], colors[0], colors[2]);
  }
  FastLED.show();
  // set single pixel color
  return 1;
}

These lines of your code:

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

[/quote]
Cause your program to stop there and wait in an infinite loop until the Serial Monitor is open. The reason you might want this is because, without it, you won't see anything that is printed to Serial between the time your program starts and when you manage to get Serial Monitor open. However, when you are wanting to run your program without Serial Monitor open, you need to remove these lines from your code (or comment them out so you can easily re-enable them later for debugging).

Wow.... Nevermind.... Lol. I can't even read my own code today. while(!Serial) was the problem :expressionless: