This is my first time using the Arduino Nano 33 IoT board. I want to connect it to the Arduino IoT Cloud, but when I upload a code that uses a cloud connection, the Arduino Nano 33 IoT keeps connecting and disconnecting. I also tried uploading the ready-made Arduino sketch, but it only made the connect/disconnect issue more frequent.
I already updated the WIFININA firmware and download the Arduino Agent.
I know that the WiFi connection is working because of the connectToWifi.ino file is working fine for me. Please share your knowledge if you have any experience with the Arduino Nano 33 IoT board or using the Arduino IoT Cloud. What could've been the problem, and how can I fix it? I appreciate any help you can provide.
Board: Arduino Nano 33 IOT
Operating System: Windows 10
File: connectToWifi.ino
#include <WiFiNINA.h>
//please enter your sensitive data in the Secret tab
char ssid[] = "**************"; // your network SSID (name)
char pass[] = "*************"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the Wi-Fi radio's status
int ledState = LOW; //ledState used to set the LED
unsigned long previousMillisInfo = 0; //will store last time Wi-Fi information was updated
unsigned long previousMillisLED = 0; // will store the last time LED was updated
const int intervalInfo = 5000; // interval at which to update the board information
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial);
// set the LED as output
pinMode(LED_BUILTIN, OUTPUT);
// attempt to connect to Wi-Fi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to network: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.println("You're connected to the network");
Serial.println("---------------------------------------");
}
void loop() {
unsigned long currentMillisInfo = millis();
// check if the time after the last update is bigger the interval
if (currentMillisInfo - previousMillisInfo >= intervalInfo) {
previousMillisInfo = currentMillisInfo;
Serial.println("Board Information:");
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print your network's SSID:
Serial.println();
Serial.println("Network Information:");
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
Serial.println("---------------------------------------");
}
unsigned long currentMillisLED = millis();
// measure the signal strength and convert it into a time interval
int intervalLED = WiFi.RSSI() * -10;
// check if the time after the last blink is bigger the interval
if (currentMillisLED - previousMillisLED >= intervalLED) {
previousMillisLED = currentMillisLED;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(LED_BUILTIN, ledState);
}
}