# Problems with the Uno R4 WiFi

**URL:** <https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714>\
**Category:** Networking, Protocols, and Devices\
**Created:** [July 25, 2023, 8:19pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714 "2023-07-25T20:19:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert\_sydes](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@robert\_sydes](https://forum.arduino.cc/u/robert_sydes)\
**Post date:** [July 25, 2023, 8:19pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/1 "2023-07-25T20:19:58Z")

</div>

# Introduction

I am testing out a sketch that was originally made for Uno WiFi Rev 2. The expected output is a web page displaying:

> testing  
> asdfghjk  
> [a random number]

## The original sketch (that works on the Uno WiFi Rev. 2)

```arduino
#include <SPI.h>
#include <WiFiNINA.h>

char ssid[] = [REDACTED]; // your network SSID (name)
char pass[] = [REDACTED]; // your network password
int status = WL_IDLE_STATUS;

IPAddress ip([REDACTED]);
IPAddress dns([REDACTED]);
IPAddress gateway([REDACTED]);
IPAddress subnet([REDACTED]);

WiFiServer server(80);
void setup() {
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
  Serial.println(ssid);
  WiFi.config(ip, dns, gateway, subnet);
  status = WiFi.begin(ssid, pass);
  if (status != WL_CONNECTED) {
    Serial.println("Couldn't get a WiFi connection");
    while (true)
      ;
  } else {
    server.begin();
    Serial.print("Connected to WiFi. My address:");
    Serial.println(WiFi.localIP());
  }
}

void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("client connected");
    // an HTTP request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the HTTP request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard HTTP response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close"); // the connection will be closed after completion of the response
          client.println("Refresh: 5"); // refresh the page automatically every 5 sec
          client.println();
          client.println("<html>");
          client.println("<body>");
          client.println("<p>testing</p>");
          client.println("<p>asdfghjk</p>");
          client.print("<p>");
          client.print(random());
          client.print("</p>");
          client.println("</body>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

```

# First problem

I modified the sketch to work with the Uno R4 WiFi, and tried it on both the offline IDE and the online Web Editor. `random()` does not seem to be recognized by either.

## My sketch, modified for the R4 WiFi

```arduino
#include "WiFiS3.h"

char ssid[] = [REDACTED]; // your network SSID (name)
char pass[] = [REDACTED]; // your network password
int status = WL_IDLE_STATUS;

IPAddress ip([REDACTED]);
IPAddress dns([REDACTED]);
IPAddress gateway([REDACTED]);
IPAddress subnet([REDACTED]);

WiFiServer server(80);
void setup() {
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
  Serial.println(ssid);
  WiFi.config(ip, dns, gateway, subnet);
  status = WiFi.begin(ssid, pass);
  if (status != WL_CONNECTED) {
    Serial.println("Couldn't get a WiFi connection");
    while (true)
      ;
  } else {
    server.begin();
    Serial.print("Connected to WiFi. My address:");
    Serial.println(WiFi.localIP());
  }
}

void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("client connected");
    // an HTTP request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the HTTP request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard HTTP response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close"); // the connection will be closed after completion of the response
          client.println("Refresh: 5"); // refresh the page automatically every 5 sec
          client.println();
          client.println("<html>");
          client.println("<body>");
          client.println("<p>testing</p>");
          client.println("<p>asdfghjk</p>");
          client.print("<p>");
          client.print(random());
          client.print("</p>");
          client.println("</body>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

```

## Error mesage displayed on the serial monitor, using the Arduino (Web) Editor

```arduino
/usr/local/bin/arduino-cli compile --fqbn arduino:renesas_uno:unor4wifi --build-cache-path /tmp --output-dir /tmp/3208599453/build --build-path /tmp/arduino-build-C75150C49F1B578B8AA60CC0E97B5CB6 /tmp/3208599453/sketch_apr7a

/tmp/3208599453/sketch_apr7a/sketch_apr7a.ino: In function 'void loop()':

/tmp/3208599453/sketch_apr7a/sketch_apr7a.ino:57:31: error: no matching function for call to 'random()'

client.print(random());

^

In file included from /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/api/Interrupts.h:8:0,

from /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/api/ArduinoAPI.h:29,

from /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/Arduino.h:4,

from /tmp/arduino-build-C75150C49F1B578B8AA60CC0E97B5CB6/sketch/sketch_apr7a.ino.cpp:1:

/home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/api/Common.h:166:6: note: candidate: long int random(long int)

long random(long);

^ ~~~~~

/home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/api/Common.h:166:6: note: candidate expects 1 argument, 0 provided

/home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/api/Common.h:167:6: note: candidate: long int random(long int, long int)

long random(long, long);

^ ~~~~~

/home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.0.1/cores/arduino/api/Common.h:167:6: note: candidate expects 2 arguments, 0 provided

Error during build: exit status 1

```

## Error mesage displayed on the serial monitor, using the Arduino (offline) IDE

```arduino
C:\Users\tcdd\Documents\Arduino\web_server_config_R4\web_server_config_R4.ino: In function 'void loop()':
C:\Users\tcdd\Documents\Arduino\web_server_config_R4\web_server_config_R4.ino:57:31: error: no matching function for call to 'random()'
           client.print(random());
                               ^
In file included from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/Interrupts.h:8:0,
                 from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/ArduinoAPI.h:29,
                 from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/Arduino.h:4,
                 from C:\Users\tcdd\AppData\Local\Temp\arduino\sketches\448DF2B19A5584EBAEC7593B04703CCD\sketch\web_server_config_R4.ino.cpp:1:
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/Common.h:166:6: note: candidate: long int random(long int)
 long random(long);
      ^ ~~~~~
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/Common.h:166:6: note: candidate expects 1 argument, 0 provided
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/Common.h:167:6: note: candidate: long int random(long int, long int)
 long random(long, long);
      ^ ~~~~~
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/Common.h:167:6: note: candidate expects 2 arguments, 0 provided

exit status 1

Compilation error: no matching function for call to 'random()'

```

# Second problem

I modified the sketch, disabling `random()`. It works on the Web Editor, but not the (offline) IDE; with the latter, the Arduino R4 WiFi won't connect to the network, and no error messages are displayed unless I enable compiler warnings.

## Version\* of R4 sketch with `random()` disabled

\*Works on the Web Editor, but not the offline IDE.

```arduino
#include "WiFiS3.h"

char ssid[] = [REDACTED]; // your network SSID (name)
char pass[] = [REDACTED]; // your network password
int status = WL_IDLE_STATUS;

IPAddress ip([REDACTED]);
IPAddress dns([REDACTED]);
IPAddress gateway([REDACTED]);
IPAddress subnet([REDACTED]);

WiFiServer server(80);
void setup() {
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
  Serial.println(ssid);
  WiFi.config(ip, dns, gateway, subnet);
  status = WiFi.begin(ssid, pass);
  if (status != WL_CONNECTED) {
    Serial.println("Couldn't get a WiFi connection");
    while (true)
      ;
  } else {
    server.begin();
    Serial.print("Connected to WiFi. My address:");
    Serial.println(WiFi.localIP());
  }
}

void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("client connected");
    // an HTTP request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the HTTP request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard HTTP response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close"); // the connection will be closed after completion of the response
          client.println("Refresh: 5"); // refresh the page automatically every 5 sec
          client.println();
          client.println("<html>");
          client.println("<body>");
          client.println("<p>testing</p>");
          client.println("<p>asdfghjk</p>");
          //client.print("<p>");
          //client.print(random());
          //client.print("</p>");
          client.println("</body>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

```

## Compiler warnings

```arduino
In file included from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiS3.h:26:0,
                 from C:\Users\tcdd\AppData\Local\Temp\.arduinoIDE-unsaved2023625-15952-1owok8z.9zk1\sketch_jul25a\sketch_jul25a.ino:1:
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiUdp.h:33:0: warning: "RX_BUFFER_DIM" redefined
 #define RX_BUFFER_DIM 1461
 
In file included from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiS3.h:24:0,
                 from C:\Users\tcdd\AppData\Local\Temp\.arduinoIDE-unsaved2023625-15952-1owok8z.9zk1\sketch_jul25a\sketch_jul25a.ino:1:
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiClient.h:33:0: note: this is the location of the previous definition
 #define RX_BUFFER_DIM 1024
 
In file included from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFi.h:7:0,
                 from C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiS3.h:23,
                 from C:\Users\tcdd\AppData\Local\Temp\.arduinoIDE-unsaved2023625-15952-1owok8z.9zk1\sketch_jul25a\sketch_jul25a.ino:1:
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiCommands.h:17:3: warning: 'file_op' defined but not used [-Wunused-variable]
 } file_op;
   ^ ~~~~~~
C:\Users\tcdd\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\WiFiS3\src/WiFiCommands.h:10:3: warning: 'ip_type' defined but not used [-Wunused-variable]
 } ip_type;
   ^ ~~~~~~

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 25, 2023, 8:24pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/2 "2023-07-25T20:24:17Z")

</div>

```arduino
client.print(random());

```

The random() function needs at least one parameter

---

<div class="post-metadata">

**Author:** ![robert\_sydes](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@robert\_sydes](https://forum.arduino.cc/u/robert_sydes)\
**Post date:** [July 25, 2023, 8:55pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/4 "2023-07-25T20:55:47Z")

</div>

Giving the function the parameters "0, 1023" (for example) solves the first problem. (But the second problem still applies.)

Why doesn't the Uno WiFi Rev 2 require parameters for the `random()` function, but the Uno R4 WiFi does?

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 25, 2023, 8:58pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/5 "2023-07-25T20:58:16Z")

</div>

What range of values does the Uno WiFi Rev 2 return when you use random() with no parameters ?

---

<div class="post-metadata">

**Author:** ![robert\_sydes](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@robert\_sydes](https://forum.arduino.cc/u/robert_sydes)\
**Post date:** [July 25, 2023, 10:37pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/6 "2023-07-25T22:37:37Z")

</div>

Here's what I get when I when I run this\* sketch for about a minute:  
[RANDOM.TXT](https://forum.arduino.cc/uploads/short-url/wz3FvtYzj8V0zTmULmPLYqlY0VY.TXT) (45.1 KB)

\*The sketch:

```arduino
#include <SPI.h>
#include <SD.h>

int x = 0;

File theFile;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  SD.begin(4);
}

void loop() {
  for (x = 0; x <= 60000; x++) {
    theFile = SD.open("random.txt", FILE_WRITE);

    theFile.println(random());

    theFile.close();

    delay(1);
  }

/*
I didn't get the following part right; the LED was supposed to turn on after a minute:
*/

  if (x >= 60000) {
    digitalWrite(LED_BUILTIN, HIGH);
    while (1) {
      ;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 26, 2023, 6:12am UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/7 "2023-07-26T06:12:38Z")

</div>

More importantly, what range of values do you want from the random() function ?

---

<div class="post-metadata">

**Author:** ![robert\_sydes](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@robert\_sydes](https://forum.arduino.cc/u/robert_sydes)\
**Post date:** [July 26, 2023, 6:38pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/8 "2023-07-26T18:38:53Z")

</div>

In this particular instance, it doesn't really matter, as long as I'm getting a different number every time the page refreshes. The purpose of the sketch is for practicing and testing the code for the WiFi functionality of the Arduino.

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [July 26, 2023, 6:51pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/9 "2023-07-26T18:51:07Z")

</div>

Randomness isn't good for this kind of testing. It could send a 666, you receive a 844, and you would never know.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 22, 2024, 6:52pm UTC](https://forum.arduino.cc/t/problems-with-the-uno-r4-wifi/1151714/10 "2024-01-22T18:52:04Z")

</div>

Closed on January 22, 2024, 6:52pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
