Hello,
i am trying to get an arduino r4 wifi to connected to my wifi. when i first got it, i uploaded the code and i got a notification it connected but disconnected right after.
and now when i run code to scan for wifi it finds no wifi networks at all. on top of which it wont connect to any wifi network either.
Welcome to the forum
Please post the code that you are having trouble with, using code tags when you do
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
here is the code from the arduino website from the examples im using
#include "Arduino_LED_Matrix.h"
#include "WiFiS3.h"
#define relay 2
ArduinoLEDMatrix matrix;
const uint32_t hi[] = {
0xcdfcdfcc,
0x4fc4fc4c,
0xc4cdfcdf,
66
};
char ssid[] = "SSID"; //Enter your WIFI SSID
char pass[] = "PASS"; //Enter your WIFI password
int keyIndex = 0; // your network key index number (needed only for WEP)
String output = "off";
String header;
// Current time
unsigned long currentTime = millis();
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
Serial.begin(9600); // initialize serial communication
matrix.begin();
pinMode(relay, OUTPUT); // set the Relay pin mode
digitalWrite(relay, HIGH);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Network named: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin(); // start the web server on port 80
printWifiStatus(); // you're connected now, so print out the status
}
void loop() {
webServer();
LEDMatrix();
}
void LEDMatrix() {
matrix.loadFrame(hi);
}
void webServer() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
currentTime = millis();
previousTime = currentTime;
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// turns the relay on and off
if (header.indexOf("GET /on") >= 0) {
output = "on";
digitalWrite(relay, LOW);
} else if (header.indexOf("GET /off") >= 0) {
output = "off";
digitalWrite(relay, HIGH);
}
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".on { background-color: #FF0000; border: 5px; color: white; padding: 16px 40px; border-radius: 20px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".off {background-color: #000000;border: 5px; color: white; padding: 16px 40px; border-radius: 20px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head>");
// Web Page Heading
client.println("<body><h1>SriTu Hobby IOT system</h1>");
client.println("<p>Relay " + output + "</p>");
if (output == "off") {
client.println("<p><a href=\"/on\"><button class=\"off\">OFF</button></a></p>");
} else {
client.println("<p><a href=\"/off\"><button class=\"on\">ON</button></a></p>");
}
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
// print where to go in a browser:
Serial.print("Now open this URL on your browser --> http://");
Serial.println(ip);
}
and here is the scanner one
/*
This example prints the board's MAC address, and
scans for available WiFi networks using the NINA module.
Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified.
BSSID and WiFi channel are printed
Circuit:
* Uno R4 WiFi
This example is based on ScanNetworks
created 1 Mar 2017
by Arturo Guadalupi
Find the full UNO R4 WiFi Network documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#scan-networks-advanced
*/
#include <WiFiS3.h>
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);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// scan for existing networks:
Serial.println();
Serial.println("Scanning available networks...");
listNetworks();
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC: ");
printMacAddress(mac);
}
void loop() {
delay(10000);
// scan for existing networks:
Serial.println("Scanning available networks...");
listNetworks();
}
void listNetworks() {
// scan for nearby networks:
Serial.println("** Scan Networks **");
int numSsid = WiFi.scanNetworks();
if (numSsid == -1)
{
Serial.println("Couldn't get a WiFi connection");
while (true);
}
// print the list of networks seen:
Serial.print("number of available networks: ");
Serial.println(numSsid);
// print the network number and name for each network found:
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
Serial.print(thisNet + 1);
Serial.print(") ");
Serial.print("Signal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tChannel: ");
Serial.print(WiFi.channel(thisNet));
byte bssid[6];
Serial.print("\t\tBSSID: ");
printMacAddress(WiFi.BSSID(thisNet, bssid));
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
Serial.print("\t\tSSID: ");
Serial.println(WiFi.SSID(thisNet));
Serial.flush();
}
Serial.println();
}
void printEncryptionType(int thisType) {
// read the encryption type and print out the name:
switch (thisType) {
case ENC_TYPE_WEP:
Serial.print("WEP");
break;
case ENC_TYPE_WPA:
Serial.print("WPA");
break;
case ENC_TYPE_WPA2:
Serial.print("WPA2");
break;
case ENC_TYPE_WPA3:
Serial.print("WPA3");
break;
case ENC_TYPE_NONE:
Serial.print("None");
break;
case ENC_TYPE_AUTO:
Serial.print("Auto");
break;
case ENC_TYPE_UNKNOWN:
default:
Serial.print("Unknown");
break;
}
}
void print2Digits(byte thisByte) {
if (thisByte < 0xF) {
Serial.print("0");
}
Serial.print(thisByte, HEX);
}
void printMacAddress(byte mac[]) {
for (int i = 0; i < 6; i++) {
if (i > 0) {
Serial.print(":");
}
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
}
Serial.println();
}
well sadly a new issue arose, when i updated what i thought was the wifi firmware again i seem to have screwed up and now the r4 wifi just turns off when turning on. so i cant do anything with the device anymore