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
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;
}