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)
#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
#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
/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
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.
#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
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;
^~~~~~~